mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 17:25:38 +00:00
vfs-6.11-rc1.fixes.3
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCZqSoSAAKCRCRxhvAZXjc omGDAP9g7+3hDDFvDfYm3cjSw5CcbYodaS0cjzSZV9FQ8jSLUgEAv9741X4c5og1 u8hjOnkYXVJPKn+DzfwBza0wV8qtVQM= =YIoY -----END PGP SIGNATURE----- Merge tag 'vfs-6.11-rc1.fixes.3' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs Pull vfs fixes from Christian Brauner: "This contains two fixes for this merge window: VFS: - I noticed that it is possible for a privileged user to mount most filesystems with a non-initial user namespace in sb->s_user_ns. When fsopen() is called in a non-init namespace the caller's namespace is recorded in fs_context->user_ns. If the returned file descriptor is then passed to a process privileged in init_user_ns, that process can call fsconfig(fd_fs, FSCONFIG_CMD_CREATE*), creating a new superblock with sb->s_user_ns set to the namespace of the process which called fsopen(). This is problematic as only filesystems that raise FS_USERNS_MOUNT are known to be able to support a non-initial s_user_ns. Others may suffer security issues, on-disk corruption or outright crash the kernel. Prevent that by restricting such delegation to filesystems that allow FS_USERNS_MOUNT. Note, that this delegation requires a privileged process to actually create the superblock so either the privileged process is cooperaing or someone must have tricked a privileged process into operating on a fscontext file descriptor whose origin it doesn't know (a stupid idea). The bug dates back to about 5 years afaict. Misc: - Fix hostfs parsing when the mount request comes in via the legacy mount api. In the legacy mount api hostfs allows to specify the host directory mount without any key. Restore that behavior" * tag 'vfs-6.11-rc1.fixes.3' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: hostfs: fix the host directory parse when mounting. fs: don't allow non-init s_user_ns for filesystems without FS_USERNS_MOUNT
This commit is contained in:
commit
bc4eee85ca
@ -17,6 +17,7 @@
|
||||
#include <linux/writeback.h>
|
||||
#include <linux/mount.h>
|
||||
#include <linux/fs_context.h>
|
||||
#include <linux/fs_parser.h>
|
||||
#include <linux/namei.h>
|
||||
#include "hostfs.h"
|
||||
#include <init.h>
|
||||
@ -929,7 +930,6 @@ static const struct inode_operations hostfs_link_iops = {
|
||||
static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc)
|
||||
{
|
||||
struct hostfs_fs_info *fsi = sb->s_fs_info;
|
||||
const char *host_root = fc->source;
|
||||
struct inode *root_inode;
|
||||
int err;
|
||||
|
||||
@ -943,15 +943,6 @@ static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc)
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* NULL is printed as '(null)' by printf(): avoid that. */
|
||||
if (fc->source == NULL)
|
||||
host_root = "";
|
||||
|
||||
fsi->host_root_path =
|
||||
kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root);
|
||||
if (fsi->host_root_path == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
root_inode = hostfs_iget(sb, fsi->host_root_path);
|
||||
if (IS_ERR(root_inode))
|
||||
return PTR_ERR(root_inode);
|
||||
@ -977,6 +968,58 @@ static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum hostfs_parma {
|
||||
Opt_hostfs,
|
||||
};
|
||||
|
||||
static const struct fs_parameter_spec hostfs_param_specs[] = {
|
||||
fsparam_string_empty("hostfs", Opt_hostfs),
|
||||
{}
|
||||
};
|
||||
|
||||
static int hostfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
|
||||
{
|
||||
struct hostfs_fs_info *fsi = fc->s_fs_info;
|
||||
struct fs_parse_result result;
|
||||
char *host_root;
|
||||
int opt;
|
||||
|
||||
opt = fs_parse(fc, hostfs_param_specs, param, &result);
|
||||
if (opt < 0)
|
||||
return opt;
|
||||
|
||||
switch (opt) {
|
||||
case Opt_hostfs:
|
||||
host_root = param->string;
|
||||
if (!*host_root)
|
||||
host_root = "";
|
||||
fsi->host_root_path =
|
||||
kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root);
|
||||
if (fsi->host_root_path == NULL)
|
||||
return -ENOMEM;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hostfs_parse_monolithic(struct fs_context *fc, void *data)
|
||||
{
|
||||
struct hostfs_fs_info *fsi = fc->s_fs_info;
|
||||
char *host_root = (char *)data;
|
||||
|
||||
/* NULL is printed as '(null)' by printf(): avoid that. */
|
||||
if (host_root == NULL)
|
||||
host_root = "";
|
||||
|
||||
fsi->host_root_path =
|
||||
kasprintf(GFP_KERNEL, "%s/%s", root_ino, host_root);
|
||||
if (fsi->host_root_path == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hostfs_fc_get_tree(struct fs_context *fc)
|
||||
{
|
||||
return get_tree_nodev(fc, hostfs_fill_super);
|
||||
@ -994,6 +1037,8 @@ static void hostfs_fc_free(struct fs_context *fc)
|
||||
}
|
||||
|
||||
static const struct fs_context_operations hostfs_context_ops = {
|
||||
.parse_monolithic = hostfs_parse_monolithic,
|
||||
.parse_param = hostfs_parse_param,
|
||||
.get_tree = hostfs_fc_get_tree,
|
||||
.free = hostfs_fc_free,
|
||||
};
|
||||
|
11
fs/super.c
11
fs/super.c
@ -736,6 +736,17 @@ struct super_block *sget_fc(struct fs_context *fc,
|
||||
struct user_namespace *user_ns = fc->global ? &init_user_ns : fc->user_ns;
|
||||
int err;
|
||||
|
||||
/*
|
||||
* Never allow s_user_ns != &init_user_ns when FS_USERNS_MOUNT is
|
||||
* not set, as the filesystem is likely unprepared to handle it.
|
||||
* This can happen when fsconfig() is called from init_user_ns with
|
||||
* an fs_fd opened in another user namespace.
|
||||
*/
|
||||
if (user_ns != &init_user_ns && !(fc->fs_type->fs_flags & FS_USERNS_MOUNT)) {
|
||||
errorfc(fc, "VFS: Mounting from non-initial user namespace is not allowed");
|
||||
return ERR_PTR(-EPERM);
|
||||
}
|
||||
|
||||
retry:
|
||||
spin_lock(&sb_lock);
|
||||
if (test) {
|
||||
|
Loading…
Reference in New Issue
Block a user