init: handle idmapped mounts
Enable the init helpers to handle idmapped mounts by passing down the mount's user namespace. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before. Link: https://lore.kernel.org/r/20210121131959.646623-21-christian.brauner@ubuntu.com Cc: Christoph Hellwig <hch@lst.de> Cc: David Howells <dhowells@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Родитель
9eccd12ce7
Коммит
b816dd5dde
20
fs/init.c
20
fs/init.c
|
@ -157,8 +157,8 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev)
|
||||||
mode &= ~current_umask();
|
mode &= ~current_umask();
|
||||||
error = security_path_mknod(&path, dentry, mode, dev);
|
error = security_path_mknod(&path, dentry, mode, dev);
|
||||||
if (!error)
|
if (!error)
|
||||||
error = vfs_mknod(&init_user_ns, path.dentry->d_inode, dentry,
|
error = vfs_mknod(mnt_user_ns(path.mnt), path.dentry->d_inode,
|
||||||
mode, new_decode_dev(dev));
|
dentry, mode, new_decode_dev(dev));
|
||||||
done_path_create(&path, dentry);
|
done_path_create(&path, dentry);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,7 @@ int __init init_link(const char *oldname, const char *newname)
|
||||||
{
|
{
|
||||||
struct dentry *new_dentry;
|
struct dentry *new_dentry;
|
||||||
struct path old_path, new_path;
|
struct path old_path, new_path;
|
||||||
|
struct user_namespace *mnt_userns;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = kern_path(oldname, 0, &old_path);
|
error = kern_path(oldname, 0, &old_path);
|
||||||
|
@ -181,14 +182,15 @@ int __init init_link(const char *oldname, const char *newname)
|
||||||
error = -EXDEV;
|
error = -EXDEV;
|
||||||
if (old_path.mnt != new_path.mnt)
|
if (old_path.mnt != new_path.mnt)
|
||||||
goto out_dput;
|
goto out_dput;
|
||||||
error = may_linkat(&init_user_ns, &old_path);
|
mnt_userns = mnt_user_ns(new_path.mnt);
|
||||||
|
error = may_linkat(mnt_userns, &old_path);
|
||||||
if (unlikely(error))
|
if (unlikely(error))
|
||||||
goto out_dput;
|
goto out_dput;
|
||||||
error = security_path_link(old_path.dentry, &new_path, new_dentry);
|
error = security_path_link(old_path.dentry, &new_path, new_dentry);
|
||||||
if (error)
|
if (error)
|
||||||
goto out_dput;
|
goto out_dput;
|
||||||
error = vfs_link(old_path.dentry, &init_user_ns,
|
error = vfs_link(old_path.dentry, mnt_userns, new_path.dentry->d_inode,
|
||||||
new_path.dentry->d_inode, new_dentry, NULL);
|
new_dentry, NULL);
|
||||||
out_dput:
|
out_dput:
|
||||||
done_path_create(&new_path, new_dentry);
|
done_path_create(&new_path, new_dentry);
|
||||||
out:
|
out:
|
||||||
|
@ -207,8 +209,8 @@ int __init init_symlink(const char *oldname, const char *newname)
|
||||||
return PTR_ERR(dentry);
|
return PTR_ERR(dentry);
|
||||||
error = security_path_symlink(&path, dentry, oldname);
|
error = security_path_symlink(&path, dentry, oldname);
|
||||||
if (!error)
|
if (!error)
|
||||||
error = vfs_symlink(&init_user_ns, path.dentry->d_inode, dentry,
|
error = vfs_symlink(mnt_user_ns(path.mnt), path.dentry->d_inode,
|
||||||
oldname);
|
dentry, oldname);
|
||||||
done_path_create(&path, dentry);
|
done_path_create(&path, dentry);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -231,8 +233,8 @@ int __init init_mkdir(const char *pathname, umode_t mode)
|
||||||
mode &= ~current_umask();
|
mode &= ~current_umask();
|
||||||
error = security_path_mkdir(&path, dentry, mode);
|
error = security_path_mkdir(&path, dentry, mode);
|
||||||
if (!error)
|
if (!error)
|
||||||
error = vfs_mkdir(&init_user_ns, path.dentry->d_inode, dentry,
|
error = vfs_mkdir(mnt_user_ns(path.mnt), path.dentry->d_inode,
|
||||||
mode);
|
dentry, mode);
|
||||||
done_path_create(&path, dentry);
|
done_path_create(&path, dentry);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче