Skip to content

Commit d83f590

Browse files
committed
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: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 9fd973e commit d83f590

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

‎fs/coda/coda_linux.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ void coda_vattr_to_iattr(struct inode *inode, struct coda_vattr *attr)
100100
if (attr->va_mode != (u_short) -1)
101101
inode->i_mode = attr->va_mode | inode_type;
102102
if (attr->va_uid != -1)
103-
inode->i_uid = (uid_t) attr->va_uid;
103+
inode->i_uid = make_kuid(&init_user_ns, (uid_t) attr->va_uid);
104104
if (attr->va_gid != -1)
105-
inode->i_gid = (gid_t) attr->va_gid;
105+
inode->i_gid = make_kgid(&init_user_ns, (gid_t) attr->va_gid);
106106
if (attr->va_nlink != -1)
107107
set_nlink(inode, attr->va_nlink);
108108
if (attr->va_size != -1)
@@ -171,10 +171,10 @@ void coda_iattr_to_vattr(struct iattr *iattr, struct coda_vattr *vattr)
171171
vattr->va_mode = iattr->ia_mode;
172172
}
173173
if ( valid & ATTR_UID ) {
174-
vattr->va_uid = (vuid_t) iattr->ia_uid;
174+
vattr->va_uid = (vuid_t) from_kuid(&init_user_ns, iattr->ia_uid);
175175
}
176176
if ( valid & ATTR_GID ) {
177-
vattr->va_gid = (vgid_t) iattr->ia_gid;
177+
vattr->va_gid = (vgid_t) from_kgid(&init_user_ns, iattr->ia_gid);
178178
}
179179
if ( valid & ATTR_SIZE ) {
180180
vattr->va_size = iattr->ia_size;

‎fs/coda/psdev.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ static int coda_psdev_open(struct inode * inode, struct file * file)
270270
if (task_active_pid_ns(current) != &init_pid_ns)
271271
return -EINVAL;
272272

273+
if (current_user_ns() != &init_user_ns)
274+
return -EINVAL;
275+
273276
idx = iminor(inode);
274277
if (idx < 0 || idx >= MAX_CODADEVS)
275278
return -ENODEV;

‎fs/coda/upcall.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void *alloc_upcall(int opcode, int size)
5252
inp->ih.opcode = opcode;
5353
inp->ih.pid = task_pid_nr_ns(current, &init_pid_ns);
5454
inp->ih.pgid = task_pgrp_nr_ns(current, &init_pid_ns);
55-
inp->ih.uid = current_fsuid();
55+
inp->ih.uid = from_kuid(&init_user_ns, current_fsuid());
5656

5757
return (void*)inp;
5858
}
@@ -157,7 +157,7 @@ int venus_lookup(struct super_block *sb, struct CodaFid *fid,
157157
}
158158

159159
int venus_close(struct super_block *sb, struct CodaFid *fid, int flags,
160-
vuid_t uid)
160+
kuid_t uid)
161161
{
162162
union inputArgs *inp;
163163
union outputArgs *outp;
@@ -166,7 +166,7 @@ int venus_close(struct super_block *sb, struct CodaFid *fid, int flags,
166166
insize = SIZE(release);
167167
UPARG(CODA_CLOSE);
168168

169-
inp->ih.uid = uid;
169+
inp->ih.uid = from_kuid(&init_user_ns, uid);
170170
inp->coda_close.VFid = *fid;
171171
inp->coda_close.flags = flags;
172172

‎include/linux/coda_psdev.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int venus_lookup(struct super_block *sb, struct CodaFid *fid,
3434
const char *name, int length, int *type,
3535
struct CodaFid *resfid);
3636
int venus_close(struct super_block *sb, struct CodaFid *fid, int flags,
37-
vuid_t uid);
37+
kuid_t uid);
3838
int venus_open(struct super_block *sb, struct CodaFid *fid, int flags,
3939
struct file **f);
4040
int venus_mkdir(struct super_block *sb, struct CodaFid *dirfid,

0 commit comments

Comments
 (0)