forked from Minki/linux
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>
This commit is contained in:
parent
52137abe18
commit
a7c1938e22
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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) ||
|
||||
|
@ -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;
|
||||
|
12
fs/stat.c
12
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;
|
||||
|
@ -58,14 +58,15 @@
|
||||
|
||||
#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;
|
||||
|
Loading…
Reference in New Issue
Block a user