Commit a7c1938e22c02b008655524c766d185ae99d9d53

Authored by Eric W. Biederman
1 parent 52137abe18

userns: Convert stat to return values mapped from kuids and kgids

- Store uids and gids with kuid_t and kgid_t in struct kstat
- Convert uid and gids to userspace usable values with
  from_kuid and from_kgid

Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>

Showing 8 changed files with 21 additions and 20 deletions Side-by-side Diff

arch/arm/kernel/sys_oabi-compat.c
... ... @@ -124,8 +124,8 @@
124 124 tmp.__st_ino = stat->ino;
125 125 tmp.st_mode = stat->mode;
126 126 tmp.st_nlink = stat->nlink;
127   - tmp.st_uid = stat->uid;
128   - tmp.st_gid = stat->gid;
  127 + tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
  128 + tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
129 129 tmp.st_rdev = huge_encode_dev(stat->rdev);
130 130 tmp.st_size = stat->size;
131 131 tmp.st_blocks = stat->blocks;
arch/parisc/hpux/fs.c
... ... @@ -159,8 +159,8 @@
159 159 tmp.st_ino = stat->ino;
160 160 tmp.st_mode = stat->mode;
161 161 tmp.st_nlink = stat->nlink;
162   - tmp.st_uid = stat->uid;
163   - tmp.st_gid = stat->gid;
  162 + tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
  163 + tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
164 164 tmp.st_rdev = new_encode_dev(stat->rdev);
165 165 tmp.st_size = stat->size;
166 166 tmp.st_atime = stat->atime.tv_sec;
arch/s390/kernel/compat_linux.c
... ... @@ -547,8 +547,8 @@
547 547 tmp.__st_ino = (u32)stat->ino;
548 548 tmp.st_mode = stat->mode;
549 549 tmp.st_nlink = (unsigned int)stat->nlink;
550   - tmp.st_uid = stat->uid;
551   - tmp.st_gid = stat->gid;
  550 + tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
  551 + tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
552 552 tmp.st_rdev = huge_encode_dev(stat->rdev);
553 553 tmp.st_size = stat->size;
554 554 tmp.st_blksize = (u32)stat->blksize;
arch/sparc/kernel/sys_sparc32.c
... ... @@ -139,8 +139,8 @@
139 139 err |= put_user(stat->ino, &statbuf->st_ino);
140 140 err |= put_user(stat->mode, &statbuf->st_mode);
141 141 err |= put_user(stat->nlink, &statbuf->st_nlink);
142   - err |= put_user(stat->uid, &statbuf->st_uid);
143   - err |= put_user(stat->gid, &statbuf->st_gid);
  142 + err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
  143 + err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
144 144 err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
145 145 err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
146 146 err |= put_user(stat->size, &statbuf->st_size);
arch/x86/ia32/sys_ia32.c
... ... @@ -71,8 +71,8 @@
71 71 {
72 72 typeof(ubuf->st_uid) uid = 0;
73 73 typeof(ubuf->st_gid) gid = 0;
74   - SET_UID(uid, stat->uid);
75   - SET_GID(gid, stat->gid);
  74 + SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
  75 + SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
76 76 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
77 77 __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
78 78 __put_user(stat->ino, &ubuf->__st_ino) ||
... ... @@ -144,8 +144,8 @@
144 144 tmp.st_nlink = stat->nlink;
145 145 if (tmp.st_nlink != stat->nlink)
146 146 return -EOVERFLOW;
147   - SET_UID(tmp.st_uid, stat->uid);
148   - SET_GID(tmp.st_gid, stat->gid);
  147 + SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
  148 + SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
149 149 tmp.st_rdev = old_encode_dev(stat->rdev);
150 150 if ((u64) stat->size > MAX_NON_LFS)
151 151 return -EOVERFLOW;
... ... @@ -137,8 +137,8 @@
137 137 tmp.st_nlink = stat->nlink;
138 138 if (tmp.st_nlink != stat->nlink)
139 139 return -EOVERFLOW;
140   - SET_UID(tmp.st_uid, stat->uid);
141   - SET_GID(tmp.st_gid, stat->gid);
  140 + SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
  141 + SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
142 142 tmp.st_rdev = old_encode_dev(stat->rdev);
143 143 #if BITS_PER_LONG == 32
144 144 if (stat->size > MAX_NON_LFS)
... ... @@ -215,8 +215,8 @@
215 215 tmp.st_nlink = stat->nlink;
216 216 if (tmp.st_nlink != stat->nlink)
217 217 return -EOVERFLOW;
218   - SET_UID(tmp.st_uid, stat->uid);
219   - SET_GID(tmp.st_gid, stat->gid);
  218 + SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
  219 + SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
220 220 #if BITS_PER_LONG == 32
221 221 tmp.st_rdev = old_encode_dev(stat->rdev);
222 222 #else
... ... @@ -350,8 +350,8 @@
350 350 #endif
351 351 tmp.st_mode = stat->mode;
352 352 tmp.st_nlink = stat->nlink;
353   - tmp.st_uid = stat->uid;
354   - tmp.st_gid = stat->gid;
  353 + tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
  354 + tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
355 355 tmp.st_atime = stat->atime.tv_sec;
356 356 tmp.st_atime_nsec = stat->atime.tv_nsec;
357 357 tmp.st_mtime = stat->mtime.tv_sec;
include/linux/stat.h
... ... @@ -58,14 +58,15 @@
58 58  
59 59 #include <linux/types.h>
60 60 #include <linux/time.h>
  61 +#include <linux/uidgid.h>
61 62  
62 63 struct kstat {
63 64 u64 ino;
64 65 dev_t dev;
65 66 umode_t mode;
66 67 unsigned int nlink;
67   - uid_t uid;
68   - gid_t gid;
  68 + kuid_t uid;
  69 + kgid_t gid;
69 70 dev_t rdev;
70 71 loff_t size;
71 72 struct timespec atime;