aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2012-02-09 12:10:30 -0500
committerEric W. Biederman <ebiederm@xmission.com>2012-05-15 17:08:35 -0400
commita7c1938e22c02b008655524c766d185ae99d9d53 (patch)
treef6b862a5d187908007614e5537f4cd1e31a40df4
parent52137abe1820196d956bfd51edebc571b3427deb (diff)
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>
-rw-r--r--arch/arm/kernel/sys_oabi-compat.c4
-rw-r--r--arch/parisc/hpux/fs.c4
-rw-r--r--arch/s390/kernel/compat_linux.c4
-rw-r--r--arch/sparc/kernel/sys_sparc32.c4
-rw-r--r--arch/x86/ia32/sys_ia32.c4
-rw-r--r--fs/compat.c4
-rw-r--r--fs/stat.c12
-rw-r--r--include/linux/stat.h5
8 files changed, 21 insertions, 20 deletions
diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c
index af0aaebf4de6..3e94811690ce 100644
--- a/arch/arm/kernel/sys_oabi-compat.c
+++ b/arch/arm/kernel/sys_oabi-compat.c
@@ -124,8 +124,8 @@ static long cp_oldabi_stat64(struct kstat *stat,
124 tmp.__st_ino = stat->ino; 124 tmp.__st_ino = stat->ino;
125 tmp.st_mode = stat->mode; 125 tmp.st_mode = stat->mode;
126 tmp.st_nlink = stat->nlink; 126 tmp.st_nlink = stat->nlink;
127 tmp.st_uid = stat->uid; 127 tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
128 tmp.st_gid = stat->gid; 128 tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
129 tmp.st_rdev = huge_encode_dev(stat->rdev); 129 tmp.st_rdev = huge_encode_dev(stat->rdev);
130 tmp.st_size = stat->size; 130 tmp.st_size = stat->size;
131 tmp.st_blocks = stat->blocks; 131 tmp.st_blocks = stat->blocks;
diff --git a/arch/parisc/hpux/fs.c b/arch/parisc/hpux/fs.c
index 0dc8543acb4f..c71eb6c79897 100644
--- a/arch/parisc/hpux/fs.c
+++ b/arch/parisc/hpux/fs.c
@@ -159,8 +159,8 @@ static int cp_hpux_stat(struct kstat *stat, struct hpux_stat64 __user *statbuf)
159 tmp.st_ino = stat->ino; 159 tmp.st_ino = stat->ino;
160 tmp.st_mode = stat->mode; 160 tmp.st_mode = stat->mode;
161 tmp.st_nlink = stat->nlink; 161 tmp.st_nlink = stat->nlink;
162 tmp.st_uid = stat->uid; 162 tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
163 tmp.st_gid = stat->gid; 163 tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
164 tmp.st_rdev = new_encode_dev(stat->rdev); 164 tmp.st_rdev = new_encode_dev(stat->rdev);
165 tmp.st_size = stat->size; 165 tmp.st_size = stat->size;
166 tmp.st_atime = stat->atime.tv_sec; 166 tmp.st_atime = stat->atime.tv_sec;
diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c
index f0273ed760ef..65426525d9f2 100644
--- a/arch/s390/kernel/compat_linux.c
+++ b/arch/s390/kernel/compat_linux.c
@@ -547,8 +547,8 @@ static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
547 tmp.__st_ino = (u32)stat->ino; 547 tmp.__st_ino = (u32)stat->ino;
548 tmp.st_mode = stat->mode; 548 tmp.st_mode = stat->mode;
549 tmp.st_nlink = (unsigned int)stat->nlink; 549 tmp.st_nlink = (unsigned int)stat->nlink;
550 tmp.st_uid = stat->uid; 550 tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
551 tmp.st_gid = stat->gid; 551 tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
552 tmp.st_rdev = huge_encode_dev(stat->rdev); 552 tmp.st_rdev = huge_encode_dev(stat->rdev);
553 tmp.st_size = stat->size; 553 tmp.st_size = stat->size;
554 tmp.st_blksize = (u32)stat->blksize; 554 tmp.st_blksize = (u32)stat->blksize;
diff --git a/arch/sparc/kernel/sys_sparc32.c b/arch/sparc/kernel/sys_sparc32.c
index 29c478ffed91..f7392336961f 100644
--- a/arch/sparc/kernel/sys_sparc32.c
+++ b/arch/sparc/kernel/sys_sparc32.c
@@ -139,8 +139,8 @@ static int cp_compat_stat64(struct kstat *stat,
139 err |= put_user(stat->ino, &statbuf->st_ino); 139 err |= put_user(stat->ino, &statbuf->st_ino);
140 err |= put_user(stat->mode, &statbuf->st_mode); 140 err |= put_user(stat->mode, &statbuf->st_mode);
141 err |= put_user(stat->nlink, &statbuf->st_nlink); 141 err |= put_user(stat->nlink, &statbuf->st_nlink);
142 err |= put_user(stat->uid, &statbuf->st_uid); 142 err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
143 err |= put_user(stat->gid, &statbuf->st_gid); 143 err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
144 err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev); 144 err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
145 err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]); 145 err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
146 err |= put_user(stat->size, &statbuf->st_size); 146 err |= put_user(stat->size, &statbuf->st_size);
diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
index aec2202a596c..d5c820a54590 100644
--- a/arch/x86/ia32/sys_ia32.c
+++ b/arch/x86/ia32/sys_ia32.c
@@ -71,8 +71,8 @@ static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
71{ 71{
72 typeof(ubuf->st_uid) uid = 0; 72 typeof(ubuf->st_uid) uid = 0;
73 typeof(ubuf->st_gid) gid = 0; 73 typeof(ubuf->st_gid) gid = 0;
74 SET_UID(uid, stat->uid); 74 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
75 SET_GID(gid, stat->gid); 75 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
76 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) || 76 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
77 __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) || 77 __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
78 __put_user(stat->ino, &ubuf->__st_ino) || 78 __put_user(stat->ino, &ubuf->__st_ino) ||
diff --git a/fs/compat.c b/fs/compat.c
index f2944ace7a7b..0781e619a62a 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -144,8 +144,8 @@ static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
144 tmp.st_nlink = stat->nlink; 144 tmp.st_nlink = stat->nlink;
145 if (tmp.st_nlink != stat->nlink) 145 if (tmp.st_nlink != stat->nlink)
146 return -EOVERFLOW; 146 return -EOVERFLOW;
147 SET_UID(tmp.st_uid, stat->uid); 147 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
148 SET_GID(tmp.st_gid, stat->gid); 148 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
149 tmp.st_rdev = old_encode_dev(stat->rdev); 149 tmp.st_rdev = old_encode_dev(stat->rdev);
150 if ((u64) stat->size > MAX_NON_LFS) 150 if ((u64) stat->size > MAX_NON_LFS)
151 return -EOVERFLOW; 151 return -EOVERFLOW;
diff --git a/fs/stat.c b/fs/stat.c
index c733dc5753ae..31acca5f5a0c 100644
--- 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
137 tmp.st_nlink = stat->nlink; 137 tmp.st_nlink = stat->nlink;
138 if (tmp.st_nlink != stat->nlink) 138 if (tmp.st_nlink != stat->nlink)
139 return -EOVERFLOW; 139 return -EOVERFLOW;
140 SET_UID(tmp.st_uid, stat->uid); 140 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
141 SET_GID(tmp.st_gid, stat->gid); 141 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
142 tmp.st_rdev = old_encode_dev(stat->rdev); 142 tmp.st_rdev = old_encode_dev(stat->rdev);
143#if BITS_PER_LONG == 32 143#if BITS_PER_LONG == 32
144 if (stat->size > MAX_NON_LFS) 144 if (stat->size > MAX_NON_LFS)
@@ -215,8 +215,8 @@ static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf)
215 tmp.st_nlink = stat->nlink; 215 tmp.st_nlink = stat->nlink;
216 if (tmp.st_nlink != stat->nlink) 216 if (tmp.st_nlink != stat->nlink)
217 return -EOVERFLOW; 217 return -EOVERFLOW;
218 SET_UID(tmp.st_uid, stat->uid); 218 SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
219 SET_GID(tmp.st_gid, stat->gid); 219 SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
220#if BITS_PER_LONG == 32 220#if BITS_PER_LONG == 32
221 tmp.st_rdev = old_encode_dev(stat->rdev); 221 tmp.st_rdev = old_encode_dev(stat->rdev);
222#else 222#else
@@ -350,8 +350,8 @@ static long cp_new_stat64(struct kstat *stat, struct stat64 __user *statbuf)
350#endif 350#endif
351 tmp.st_mode = stat->mode; 351 tmp.st_mode = stat->mode;
352 tmp.st_nlink = stat->nlink; 352 tmp.st_nlink = stat->nlink;
353 tmp.st_uid = stat->uid; 353 tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
354 tmp.st_gid = stat->gid; 354 tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
355 tmp.st_atime = stat->atime.tv_sec; 355 tmp.st_atime = stat->atime.tv_sec;
356 tmp.st_atime_nsec = stat->atime.tv_nsec; 356 tmp.st_atime_nsec = stat->atime.tv_nsec;
357 tmp.st_mtime = stat->mtime.tv_sec; 357 tmp.st_mtime = stat->mtime.tv_sec;
diff --git a/include/linux/stat.h b/include/linux/stat.h
index 611c398dab72..46132409a3f7 100644
--- a/include/linux/stat.h
+++ b/include/linux/stat.h
@@ -58,14 +58,15 @@
58 58
59#include <linux/types.h> 59#include <linux/types.h>
60#include <linux/time.h> 60#include <linux/time.h>
61#include <linux/uidgid.h>
61 62
62struct kstat { 63struct kstat {
63 u64 ino; 64 u64 ino;
64 dev_t dev; 65 dev_t dev;
65 umode_t mode; 66 umode_t mode;
66 unsigned int nlink; 67 unsigned int nlink;
67 uid_t uid; 68 kuid_t uid;
68 gid_t gid; 69 kgid_t gid;
69 dev_t rdev; 70 dev_t rdev;
70 loff_t size; 71 loff_t size;
71 struct timespec atime; 72 struct timespec atime;