[CRIU] [PATCH 09/17] userns: save uid-s from a target userns (v2)
Andrey Vagin
avagin at openvz.org
Fri Oct 31 02:14:27 PDT 2014
We are going to support user namespaces and uid-s will be converted
accoding with userns mappings.
v2: conver id-s for sockets too
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
files-reg.c | 4 ++--
include/namespaces.h | 3 +++
namespaces.c | 15 +++++++++++++++
sk-unix.c | 4 ++--
4 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/files-reg.c b/files-reg.c
index 5f338d4..20b50a0 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -324,8 +324,8 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st, dev_t phys_de
if (img < 0)
return -1;
- gfe.uid = st->st_uid;
- gfe.gid = st->st_gid;
+ gfe.uid = userns_uid(st->st_uid);
+ gfe.gid = userns_gid(st->st_gid);
gfe.mode = st->st_mode;
gfe.has_dev = gfe.has_ino = true;
diff --git a/include/namespaces.h b/include/namespaces.h
index 79327f5..612e815 100644
--- a/include/namespaces.h
+++ b/include/namespaces.h
@@ -63,4 +63,7 @@ extern struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *n
extern int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd);
extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);
+extern int userns_uid(int uid);
+extern int userns_gid(int gid);
+
#endif /* __CR_NS_H__ */
diff --git a/namespaces.c b/namespaces.c
index a125d98..00dcd5a 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -477,6 +477,21 @@ int dump_task_ns_ids(struct pstree_item *item)
return 0;
}
+static int userns_id(int id)
+{
+ return id;
+}
+
+int userns_uid(int uid)
+{
+ return userns_id(uid);
+}
+
+int userns_gid(int gid)
+{
+ return userns_id(gid);
+}
+
static int dump_user_ns(pid_t pid, int ns_id)
{
pr_err("User namesapces are not supported yet\n");
diff --git a/sk-unix.c b/sk-unix.c
index f31e43b..205df7c 100644
--- a/sk-unix.c
+++ b/sk-unix.c
@@ -209,8 +209,8 @@ static int dump_one_unix_fd(int lfd, u32 id, const struct fd_parms *p)
ue->file_perms = perms;
perms->mode = sk->mode;
- perms->uid = sk->uid;
- perms->gid = sk->gid;
+ perms->uid = userns_uid(sk->uid);
+ perms->gid = userns_gid(sk->gid);
}
sk_encode_shutdown(ue, sk->shutdown);
--
1.9.3
More information about the CRIU
mailing list