[CRIU] [PATCH 1/4] mount: convert uid and gid properties according with userns

Andrey Vagin avagin at openvz.org
Mon Jul 20 02:34:14 PDT 2015


uid and gid are shown in the init userns. We are going to restore mounts
in a target userns, so we need to set these options in the target
userns.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 proc_parse.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/proc_parse.c b/proc_parse.c
index 8a03fea..ed78d70 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -28,6 +28,8 @@
 #include "cr_options.h"
 #include "sysfs_parse.h"
 #include "seccomp.h"
+#include "namespaces.h"
+
 #include "protobuf.h"
 #include "protobuf/fdinfo.pb-c.h"
 #include "protobuf/mnt.pb-c.h"
@@ -879,6 +881,8 @@ static int do_opt2flag(char *opt, unsigned *flags,
 	size_t uoff = 0;
 
 	while (1) {
+		unsigned int id;
+
 		end = strchr(opt, ',');
 		if (end)
 			*end = '\0';
@@ -889,7 +893,15 @@ static int do_opt2flag(char *opt, unsigned *flags,
 				break;
 			}
 
-		if (opts[i].opt == NULL) {
+		if (sscanf(opt, "gid=%d", &id) == 1) {
+			uoff += sprintf(unknown + uoff, "gid=%d", userns_gid(id));
+			unknown[uoff] = ',';
+			uoff++;
+		} else if (sscanf(opt, "uid=%d", &id) == 1) {
+			uoff += sprintf(unknown + uoff, "uid=%d", userns_uid(id));
+			unknown[uoff] = ',';
+			uoff++;
+		} else if (opts[i].opt == NULL) {
 			if (!unknown) {
 				pr_err("Unknown option [%s]\n", opt);
 				return -1;
-- 
2.1.0



More information about the CRIU mailing list