提交 d83f5901 编写于 作者: E Eric W. Biederman

coda: Restrict coda messages to the initial user namespace

Remove the slight chance that uids and gids in coda messages will be
interpreted in the wrong user namespace.

- Only allow processes in the initial user namespace to open the coda
  character device to communicate with coda filesystems.
- Explicitly convert the uids in the coda header into the initial user
  namespace.
- In coda_vattr_to_attr make kuids and kgids from the initial user
  namespace uids and gids in struct coda_vattr that just came from
  userspace.
- In coda_iattr_to_vattr convert kuids and kgids into uids and gids
  in the intial user namespace and store them in struct coda_vattr for
  sending to coda userspace programs.

Nothing needs to be changed with mounts as coda does not support
being mounted in anything other than the initial user namespace.

Cc: Jan Harkes <jaharkes@cs.cmu.edu>
Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
上级 9fd973e0
...@@ -100,9 +100,9 @@ void coda_vattr_to_iattr(struct inode *inode, struct coda_vattr *attr) ...@@ -100,9 +100,9 @@ void coda_vattr_to_iattr(struct inode *inode, struct coda_vattr *attr)
if (attr->va_mode != (u_short) -1) if (attr->va_mode != (u_short) -1)
inode->i_mode = attr->va_mode | inode_type; inode->i_mode = attr->va_mode | inode_type;
if (attr->va_uid != -1) if (attr->va_uid != -1)
inode->i_uid = (uid_t) attr->va_uid; inode->i_uid = make_kuid(&init_user_ns, (uid_t) attr->va_uid);
if (attr->va_gid != -1) if (attr->va_gid != -1)
inode->i_gid = (gid_t) attr->va_gid; inode->i_gid = make_kgid(&init_user_ns, (gid_t) attr->va_gid);
if (attr->va_nlink != -1) if (attr->va_nlink != -1)
set_nlink(inode, attr->va_nlink); set_nlink(inode, attr->va_nlink);
if (attr->va_size != -1) if (attr->va_size != -1)
...@@ -171,10 +171,10 @@ void coda_iattr_to_vattr(struct iattr *iattr, struct coda_vattr *vattr) ...@@ -171,10 +171,10 @@ void coda_iattr_to_vattr(struct iattr *iattr, struct coda_vattr *vattr)
vattr->va_mode = iattr->ia_mode; vattr->va_mode = iattr->ia_mode;
} }
if ( valid & ATTR_UID ) { if ( valid & ATTR_UID ) {
vattr->va_uid = (vuid_t) iattr->ia_uid; vattr->va_uid = (vuid_t) from_kuid(&init_user_ns, iattr->ia_uid);
} }
if ( valid & ATTR_GID ) { if ( valid & ATTR_GID ) {
vattr->va_gid = (vgid_t) iattr->ia_gid; vattr->va_gid = (vgid_t) from_kgid(&init_user_ns, iattr->ia_gid);
} }
if ( valid & ATTR_SIZE ) { if ( valid & ATTR_SIZE ) {
vattr->va_size = iattr->ia_size; vattr->va_size = iattr->ia_size;
......
...@@ -270,6 +270,9 @@ static int coda_psdev_open(struct inode * inode, struct file * file) ...@@ -270,6 +270,9 @@ static int coda_psdev_open(struct inode * inode, struct file * file)
if (task_active_pid_ns(current) != &init_pid_ns) if (task_active_pid_ns(current) != &init_pid_ns)
return -EINVAL; return -EINVAL;
if (current_user_ns() != &init_user_ns)
return -EINVAL;
idx = iminor(inode); idx = iminor(inode);
if (idx < 0 || idx >= MAX_CODADEVS) if (idx < 0 || idx >= MAX_CODADEVS)
return -ENODEV; return -ENODEV;
......
...@@ -52,7 +52,7 @@ static void *alloc_upcall(int opcode, int size) ...@@ -52,7 +52,7 @@ static void *alloc_upcall(int opcode, int size)
inp->ih.opcode = opcode; inp->ih.opcode = opcode;
inp->ih.pid = task_pid_nr_ns(current, &init_pid_ns); inp->ih.pid = task_pid_nr_ns(current, &init_pid_ns);
inp->ih.pgid = task_pgrp_nr_ns(current, &init_pid_ns); inp->ih.pgid = task_pgrp_nr_ns(current, &init_pid_ns);
inp->ih.uid = current_fsuid(); inp->ih.uid = from_kuid(&init_user_ns, current_fsuid());
return (void*)inp; return (void*)inp;
} }
...@@ -157,7 +157,7 @@ int venus_lookup(struct super_block *sb, struct CodaFid *fid, ...@@ -157,7 +157,7 @@ int venus_lookup(struct super_block *sb, struct CodaFid *fid,
} }
int venus_close(struct super_block *sb, struct CodaFid *fid, int flags, int venus_close(struct super_block *sb, struct CodaFid *fid, int flags,
vuid_t uid) kuid_t uid)
{ {
union inputArgs *inp; union inputArgs *inp;
union outputArgs *outp; union outputArgs *outp;
...@@ -166,7 +166,7 @@ int venus_close(struct super_block *sb, struct CodaFid *fid, int flags, ...@@ -166,7 +166,7 @@ int venus_close(struct super_block *sb, struct CodaFid *fid, int flags,
insize = SIZE(release); insize = SIZE(release);
UPARG(CODA_CLOSE); UPARG(CODA_CLOSE);
inp->ih.uid = uid; inp->ih.uid = from_kuid(&init_user_ns, uid);
inp->coda_close.VFid = *fid; inp->coda_close.VFid = *fid;
inp->coda_close.flags = flags; inp->coda_close.flags = flags;
......
...@@ -34,7 +34,7 @@ int venus_lookup(struct super_block *sb, struct CodaFid *fid, ...@@ -34,7 +34,7 @@ int venus_lookup(struct super_block *sb, struct CodaFid *fid,
const char *name, int length, int *type, const char *name, int length, int *type,
struct CodaFid *resfid); struct CodaFid *resfid);
int venus_close(struct super_block *sb, struct CodaFid *fid, int flags, int venus_close(struct super_block *sb, struct CodaFid *fid, int flags,
vuid_t uid); kuid_t uid);
int venus_open(struct super_block *sb, struct CodaFid *fid, int flags, int venus_open(struct super_block *sb, struct CodaFid *fid, int flags,
struct file **f); struct file **f);
int venus_mkdir(struct super_block *sb, struct CodaFid *dirfid, int venus_mkdir(struct super_block *sb, struct CodaFid *dirfid,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册