OSDN Git Service

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 af0aaeb..3e94811 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 0dc8543..c71eb6c 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 f0273ed..6542652 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 29c478f..f739233 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 aec2202..d5c820a 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 f2944ac..0781e61 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 c733dc5..31acca5 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 611c398..4613240 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;