In commit e94591d0d90c "proc: Convert proc_mount to use mount_ns" the parsing of mount parameters for the proc filesystem was broken. The SB_KERNMOUNT for procfs happens via: start_kernel() rest_init() kernel_thread() _do_fork() copy_process() alloc_pid() pid_ns_prepare_proc() kern_mount_data() proc_mount() mount_ns() In mount_ns(), the kernel calls proc_fill_super() only if the superblock has not previously been set up (i.e. the first mount reference), regardless of SB_KERNMOUNT. Because the call to proc_parse_options() had been moved inside here, and the SB_KERNMOUNT uses no mount options, the option parser became a no-op. When userspace later mounted procfs with e.g. hidepid=2, the options would be ignored. This change backs out a part of the original cleanup and parses the procfs mount options at every mount call. Because the options currently only update the pid_ns for the mount, they are applied for all mounts of proc by that pid or childen of that pid, instantaneously. This is the same behavior as the original code. Fixes: e94591d0d90c ("proc: Convert proc_mount to use mount_ns") Signed-off-by: Alistair Strachan <astrachan@xxxxxxxxxx> Cc: Seth Forshee <seth.forshee@xxxxxxxxxxxxx> Cc: Djalal Harouni <tixxdz@xxxxxxxxx> Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx> Cc: kernel-team@xxxxxxxxxxx Cc: linux-kernel@xxxxxxxxxxxxxxx --- fs/proc/inode.c | 4 ---- fs/proc/internal.h | 1 - fs/proc/root.c | 5 ++++- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 2cf3b74391ca..bbbbf348be0a 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -492,13 +492,9 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de) int proc_fill_super(struct super_block *s, void *data, int silent) { - struct pid_namespace *ns = get_pid_ns(s->s_fs_info); struct inode *root_inode; int ret; - if (!proc_parse_options(data, ns)) - return -EINVAL; - /* User space would break if executables or devices appear on proc */ s->s_iflags |= SB_I_USERNS_VISIBLE | SB_I_NOEXEC | SB_I_NODEV; s->s_flags |= SB_NODIRATIME | SB_NOSUID | SB_NOEXEC; diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 50cb22a08c2f..89b7e845b000 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -264,7 +264,6 @@ static inline void proc_tty_init(void) {} * root.c */ extern struct proc_dir_entry proc_root; -extern int proc_parse_options(char *options, struct pid_namespace *pid); extern void proc_self_init(void); extern int proc_remount(struct super_block *, int *, char *); diff --git a/fs/proc/root.c b/fs/proc/root.c index 61b7340b357a..d40676a5dd6c 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -36,7 +36,7 @@ static const match_table_t tokens = { {Opt_err, NULL}, }; -int proc_parse_options(char *options, struct pid_namespace *pid) +static int proc_parse_options(char *options, struct pid_namespace *pid) { char *p; substring_t args[MAX_OPT_ARGS]; @@ -98,6 +98,9 @@ static struct dentry *proc_mount(struct file_system_type *fs_type, ns = task_active_pid_ns(current); } + if (!proc_parse_options(data, ns)) + return ERR_PTR(-EINVAL); + return mount_ns(fs_type, flags, data, ns, ns->user_ns, proc_fill_super); } -- 2.18.0.rc1.242.g61856ae69a-goog