Skip to content

Commit 3e914fe

Browse files
dhowellsbrauner
authored andcommitted
afs: Add rootcell checks
Add some checks for the validity of the cell name. It's may get put into a symlink, so preclude it containing any slashes or "..". Also disallow starting/ending with a dot. This makes /afs/@cell/ as a symlink less of a security risk. Also disallow multiple setting of /proc/net/afs/rootcell for any given network namespace. Once set, the value may not be changed. This makes it easier to only create /afs/@cell and /afs/.@cell if there's a rootcell. Signed-off-by: David Howells <[email protected]> Link: https://lore.kernel.org/r/[email protected] cc: Marc Dionne <[email protected]> cc: [email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 92f08e9 commit 3e914fe

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

fs/afs/cell.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ int afs_cell_init(struct afs_net *net, const char *rootcell)
367367
len = cp - rootcell;
368368
}
369369

370+
if (len == 0 || !rootcell[0] || rootcell[0] == '.' || rootcell[len - 1] == '.')
371+
return -EINVAL;
372+
if (memchr(rootcell, '/', len))
373+
return -EINVAL;
374+
cp = strstr(rootcell, "..");
375+
if (cp && cp < rootcell + len)
376+
return -EINVAL;
377+
370378
/* allocate a cell record for the root cell */
371379
new_root = afs_lookup_cell(net, rootcell, len, vllist, false);
372380
if (IS_ERR(new_root)) {

fs/afs/proc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,13 @@ static int afs_proc_rootcell_write(struct file *file, char *buf, size_t size)
240240
/* determine command to perform */
241241
_debug("rootcell=%s", buf);
242242

243-
ret = afs_cell_init(net, buf);
243+
ret = -EEXIST;
244+
inode_lock(file_inode(file));
245+
if (!net->ws_cell)
246+
ret = afs_cell_init(net, buf);
247+
else
248+
printk("busy\n");
249+
inode_unlock(file_inode(file));
244250

245251
out:
246252
_leave(" = %d", ret);

0 commit comments

Comments
 (0)