userns: Convert stat to return values mapped from kuids and kgids
authorEric W. Biederman <ebiederm@xmission.com>
Thu, 9 Feb 2012 17:10:30 +0000 (09:10 -0800)
committerEric W. Biederman <ebiederm@xmission.com>
Tue, 15 May 2012 21:08:35 +0000 (14:08 -0700)
- 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>
arch/arm/kernel/sys_oabi-compat.c
arch/parisc/hpux/fs.c
arch/s390/kernel/compat_linux.c
arch/sparc/kernel/sys_sparc32.c
arch/x86/ia32/sys_ia32.c
fs/compat.c
fs/stat.c
include/linux/stat.h

index af0aaebf4de62e16e70fcfcad8ccafece2879217..3e94811690ce1c510beb49e2bf15edea9e0a4fa7 100644 (file)
@@ -124,8 +124,8 @@ static long cp_oldabi_stat64(struct kstat *stat,
        tmp.__st_ino = stat->ino;
        tmp.st_mode = stat->mode;
        tmp.st_nlink = stat->nlink;
-       tmp.st_uid = stat->uid;
-       tmp.st_gid = stat->gid;
+       tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
+       tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
        tmp.st_rdev = huge_encode_dev(stat->rdev);
        tmp.st_size = stat->size;
        tmp.st_blocks = stat->blocks;
index 0dc8543acb4fc31e9e13c3ba0c124096b6471648..c71eb6c7989707d0fbbc609a8e27ec5261204b25 100644 (file)
@@ -159,8 +159,8 @@ static int cp_hpux_stat(struct kstat *stat, struct hpux_stat64 __user *statbuf)
        tmp.st_ino = stat->ino;
        tmp.st_mode = stat->mode;
        tmp.st_nlink = stat->nlink;
-       tmp.st_uid = stat->uid;
-       tmp.st_gid = stat->gid;
+       tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
+       tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
        tmp.st_rdev = new_encode_dev(stat->rdev);
        tmp.st_size = stat->size;
        tmp.st_atime = stat->atime.tv_sec;
index f0273ed760efe6d23b93ab6b98ff32030ce2dbc1..65426525d9f22f576788e88804bb893ff817cca5 100644 (file)
@@ -547,8 +547,8 @@ static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
        tmp.__st_ino = (u32)stat->ino;
        tmp.st_mode = stat->mode;
        tmp.st_nlink = (unsigned int)stat->nlink;
-       tmp.st_uid = stat->uid;
-       tmp.st_gid = stat->gid;
+       tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
+       tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
        tmp.st_rdev = huge_encode_dev(stat->rdev);
        tmp.st_size = stat->size;
        tmp.st_blksize = (u32)stat->blksize;
index 29c478ffed9154f3e4207e8cbb9d325803025a5d..f7392336961f84a956d3d693c72df3a8674b5d97 100644 (file)
@@ -139,8 +139,8 @@ static int cp_compat_stat64(struct kstat *stat,
        err |= put_user(stat->ino, &statbuf->st_ino);
        err |= put_user(stat->mode, &statbuf->st_mode);
        err |= put_user(stat->nlink, &statbuf->st_nlink);
-       err |= put_user(stat->uid, &statbuf->st_uid);
-       err |= put_user(stat->gid, &statbuf->st_gid);
+       err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
+       err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
        err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
        err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
        err |= put_user(stat->size, &statbuf->st_size);
index aec2202a596cb0348aa6e5c1b397cff09d3a3386..d5c820a5459016b128f232a5d5fb4c33f40f8421 100644 (file)
@@ -71,8 +71,8 @@ static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
 {
        typeof(ubuf->st_uid) uid = 0;
        typeof(ubuf->st_gid) gid = 0;
-       SET_UID(uid, stat->uid);
-       SET_GID(gid, stat->gid);
+       SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
+       SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
        if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
            __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
            __put_user(stat->ino, &ubuf->__st_ino) ||
index f2944ace7a7b4a06a29880ed8c55cdd2cccb1ada..0781e619a62a48babf8969fa5453994d784ba13c 100644 (file)
@@ -144,8 +144,8 @@ static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
        tmp.st_nlink = stat->nlink;
        if (tmp.st_nlink != stat->nlink)
                return -EOVERFLOW;
-       SET_UID(tmp.st_uid, stat->uid);
-       SET_GID(tmp.st_gid, stat->gid);
+       SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
+       SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
        tmp.st_rdev = old_encode_dev(stat->rdev);
        if ((u64) stat->size > MAX_NON_LFS)
                return -EOVERFLOW;
index c733dc5753aea129a1e5deb76bf48d0cb640d6e3..31acca5f5a0cd55152acae75f381f9337d8a9afa 100644 (file)
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -137,8 +137,8 @@ static int cp_old_stat(struct kstat *stat, struct __old_kernel_stat __user * sta
        tmp.st_nlink = stat->nlink;
        if (tmp.st_nlink != stat->nlink)
                return -EOVERFLOW;
-       SET_UID(tmp.st_uid, stat->uid);
-       SET_GID(tmp.st_gid, stat->gid);
+       SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
+       SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
        tmp.st_rdev = old_encode_dev(stat->rdev);
 #if BITS_PER_LONG == 32
        if (stat->size > MAX_NON_LFS)
@@ -215,8 +215,8 @@ static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf)
        tmp.st_nlink = stat->nlink;
        if (tmp.st_nlink != stat->nlink)
                return -EOVERFLOW;
-       SET_UID(tmp.st_uid, stat->uid);
-       SET_GID(tmp.st_gid, stat->gid);
+       SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
+       SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
 #if BITS_PER_LONG == 32
        tmp.st_rdev = old_encode_dev(stat->rdev);
 #else
@@ -350,8 +350,8 @@ static long cp_new_stat64(struct kstat *stat, struct stat64 __user *statbuf)
 #endif
        tmp.st_mode = stat->mode;
        tmp.st_nlink = stat->nlink;
-       tmp.st_uid = stat->uid;
-       tmp.st_gid = stat->gid;
+       tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
+       tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
        tmp.st_atime = stat->atime.tv_sec;
        tmp.st_atime_nsec = stat->atime.tv_nsec;
        tmp.st_mtime = stat->mtime.tv_sec;
index 611c398dab72bd52e47c3945e81935b25956d818..46132409a3f73b3d57c2c150fec9b46039150b96 100644 (file)
 
 #include <linux/types.h>
 #include <linux/time.h>
+#include <linux/uidgid.h>
 
 struct kstat {
        u64             ino;
        dev_t           dev;
        umode_t         mode;
        unsigned int    nlink;
-       uid_t           uid;
-       gid_t           gid;
+       kuid_t          uid;
+       kgid_t          gid;
        dev_t           rdev;
        loff_t          size;
        struct timespec  atime;