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

Kirill Tkhai ktkhai at virtuozzo.com
Wed Feb 22 03:31:30 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 e2b0c6e7e..34903d1fd 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -770,7 +770,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;
 
@@ -786,16 +786,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)
@@ -935,6 +933,7 @@ static int collect_ns_hierarhy(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;
@@ -952,8 +951,8 @@ static int check_user_ns(struct ns_id *ns)
 		gid_t gid;
 		int i;
 
-		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) {
 			pr_err("Unable to convert uid or gid\n");
 			return -1;



More information about the CRIU mailing list