[CRIU] [PATCH v1 07/17] user_ns: Make host_id() working with any mapping and rename it

Kirill Tkhai ktkhai at virtuozzo.com
Thu Jan 12 09:53:11 PST 2017


Make possible to convert uid and gid from a user_ns to its
representation in its (grand) parent user_ns.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/namespaces.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/criu/namespaces.c b/criu/namespaces.c
index c41e95ae7..0a1fdf0a5 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -743,7 +743,7 @@ static unsigned int userns_id(unsigned int id, UidGidExtent **map, int n)
 	return INVALID_ID;
 }
 
-static unsigned int host_id(unsigned int id, UidGidExtent **map, int n)
+static unsigned int parent_userns_id(unsigned int id, UidGidExtent **map, int n)
 {
 	int i;
 
@@ -759,16 +759,14 @@ static unsigned int host_id(unsigned int id, UidGidExtent **map, int n)
 	return INVALID_ID;
 }
 
-static uid_t host_uid(uid_t uid)
+static uid_t parent_userns_uid(UsernsEntry *e, uid_t uid)
 {
-	UsernsEntry *e = userns_entry;
-	return host_id(uid, e->uid_map, e->n_uid_map);
+	return parent_userns_id(uid, e->uid_map, e->n_uid_map);
 }
 
-static gid_t host_gid(gid_t gid)
+static gid_t parent_userns_gid(UsernsEntry *e, gid_t gid)
 {
-	UsernsEntry *e = userns_entry;
-	return host_id(gid, e->gid_map, e->n_gid_map);
+	return parent_userns_id(gid, e->gid_map, e->n_gid_map);
 }
 
 uid_t userns_uid(uid_t uid)
@@ -892,6 +890,7 @@ int collect_user_namespaces(bool for_dump)
 
 static int check_user_ns(struct ns_id *ns)
 {
+	UsernsEntry *e = ns->user.e;
 	pid_t pid = ns->ns_pid;
 	int status;
 	pid_t chld;
@@ -914,8 +913,8 @@ static int check_user_ns(struct ns_id *ns)
 			return -1;
 		}
 
-		uid = host_uid(0);
-		gid = host_gid(0);
+		uid = parent_userns_uid(e, 0);
+		gid = parent_userns_gid(e, 0);
 		if (uid == INVALID_ID || gid == INVALID_ID) {
 			if (ns->type == NS_ROOT) {
 				pr_err("Unable to convert uid or gid\n");



More information about the CRIU mailing list