Skip to content

Commit aeaa4a7

Browse files
committed
fs: Call d_automount with the filesystems creds
Seth Forshee reported a mount regression in nfs autmounts with "fs: Add user namespace member to struct super_block". It turns out that the assumption that current->cred is something reasonable during mount while necessary to improve support of unprivileged mounts is wrong in the automount path. To fix the existing filesystems override current->cred with the init_cred before calling d_automount and restore current->cred after d_automount completes. To support unprivileged mounts would require a more nuanced cred selection, so fail on unprivileged mounts for the time being. As none of the filesystems that currently set FS_USERNS_MOUNT implement d_automount this check is only good for preventing future problems. Fixes: 6e4eab5 ("fs: Add user namespace member to struct super_block") Tested-by: Seth Forshee <seth.forshee@canonical.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 8175435 commit aeaa4a7

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎fs/namei.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/posix_acl.h>
3737
#include <linux/hash.h>
3838
#include <linux/bitops.h>
39+
#include <linux/init_task.h>
3940
#include <asm/uaccess.h>
4041

4142
#include "internal.h"
@@ -1099,6 +1100,7 @@ static int follow_automount(struct path *path, struct nameidata *nd,
10991100
bool *need_mntput)
11001101
{
11011102
struct vfsmount *mnt;
1103+
const struct cred *old_cred;
11021104
int err;
11031105

11041106
if (!path->dentry->d_op || !path->dentry->d_op->d_automount)
@@ -1120,11 +1122,16 @@ static int follow_automount(struct path *path, struct nameidata *nd,
11201122
path->dentry->d_inode)
11211123
return -EISDIR;
11221124

1125+
if (path->dentry->d_sb->s_user_ns != &init_user_ns)
1126+
return -EACCES;
1127+
11231128
nd->total_link_count++;
11241129
if (nd->total_link_count >= 40)
11251130
return -ELOOP;
11261131

1132+
old_cred = override_creds(&init_cred);
11271133
mnt = path->dentry->d_op->d_automount(path);
1134+
revert_creds(old_cred);
11281135
if (IS_ERR(mnt)) {
11291136
/*
11301137
* The filesystem is allowed to return -EISDIR here to indicate

0 commit comments

Comments
 (0)