Skip to content

Commit 9741295

Browse files
segoontorvalds
authored andcommitted
procfs: parse mount options
Add support for procfs mount options. Actual mount options are coming in the next patches. Signed-off-by: Vasiliy Kulikov <segoon@openwall.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Randy Dunlap <rdunlap@xenotime.net> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Greg KH <greg@kroah.com> Cc: Theodore Tso <tytso@MIT.EDU> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: James Morris <jmorris@namei.org> Cc: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 640708a commit 9741295

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

fs/proc/inode.c

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/time.h>
88
#include <linux/proc_fs.h>
99
#include <linux/kernel.h>
10+
#include <linux/pid_namespace.h>
1011
#include <linux/mm.h>
1112
#include <linux/string.h>
1213
#include <linux/stat.h>
@@ -17,7 +18,9 @@
1718
#include <linux/init.h>
1819
#include <linux/module.h>
1920
#include <linux/sysctl.h>
21+
#include <linux/seq_file.h>
2022
#include <linux/slab.h>
23+
#include <linux/mount.h>
2124

2225
#include <asm/system.h>
2326
#include <asm/uaccess.h>
@@ -101,12 +104,19 @@ void __init proc_init_inodecache(void)
101104
init_once);
102105
}
103106

107+
static int proc_show_options(struct seq_file *seq, struct dentry *root)
108+
{
109+
return 0;
110+
}
111+
104112
static const struct super_operations proc_sops = {
105113
.alloc_inode = proc_alloc_inode,
106114
.destroy_inode = proc_destroy_inode,
107115
.drop_inode = generic_delete_inode,
108116
.evict_inode = proc_evict_inode,
109117
.statfs = simple_statfs,
118+
.remount_fs = proc_remount,
119+
.show_options = proc_show_options,
110120
};
111121

112122
static void __pde_users_dec(struct proc_dir_entry *pde)

fs/proc/internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void pde_put(struct proc_dir_entry *pde);
117117

118118
int proc_fill_super(struct super_block *);
119119
struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
120+
int proc_remount(struct super_block *sb, int *flags, char *data);
120121

121122
/*
122123
* These are generic /proc routines that use the internal

fs/proc/root.c

+53-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/bitops.h>
1919
#include <linux/mount.h>
2020
#include <linux/pid_namespace.h>
21+
#include <linux/parser.h>
2122

2223
#include "internal.h"
2324

@@ -36,25 +37,75 @@ static int proc_set_super(struct super_block *sb, void *data)
3637
return err;
3738
}
3839

40+
enum {
41+
Opt_err,
42+
};
43+
44+
static const match_table_t tokens = {
45+
{Opt_err, NULL},
46+
};
47+
48+
static int proc_parse_options(char *options, struct pid_namespace *pid)
49+
{
50+
char *p;
51+
substring_t args[MAX_OPT_ARGS];
52+
53+
pr_debug("proc: options = %s\n", options);
54+
55+
if (!options)
56+
return 1;
57+
58+
while ((p = strsep(&options, ",")) != NULL) {
59+
int token;
60+
if (!*p)
61+
continue;
62+
63+
args[0].to = args[0].from = 0;
64+
token = match_token(p, tokens, args);
65+
switch (token) {
66+
default:
67+
pr_err("proc: unrecognized mount option \"%s\" "
68+
"or missing value\n", p);
69+
return 0;
70+
}
71+
}
72+
73+
return 1;
74+
}
75+
76+
int proc_remount(struct super_block *sb, int *flags, char *data)
77+
{
78+
struct pid_namespace *pid = sb->s_fs_info;
79+
return !proc_parse_options(data, pid);
80+
}
81+
3982
static struct dentry *proc_mount(struct file_system_type *fs_type,
4083
int flags, const char *dev_name, void *data)
4184
{
4285
int err;
4386
struct super_block *sb;
4487
struct pid_namespace *ns;
4588
struct proc_inode *ei;
89+
char *options;
4690

47-
if (flags & MS_KERNMOUNT)
91+
if (flags & MS_KERNMOUNT) {
4892
ns = (struct pid_namespace *)data;
49-
else
93+
options = NULL;
94+
} else {
5095
ns = current->nsproxy->pid_ns;
96+
options = data;
97+
}
5198

5299
sb = sget(fs_type, proc_test_super, proc_set_super, ns);
53100
if (IS_ERR(sb))
54101
return ERR_CAST(sb);
55102

56103
if (!sb->s_root) {
57104
sb->s_flags = flags;
105+
if (!proc_parse_options(options, ns)) {
106+
deactivate_locked_super(sb);
107+
return ERR_PTR(-EINVAL);
108+
}
58109
err = proc_fill_super(sb);
59110
if (err) {
60111
deactivate_locked_super(sb);

0 commit comments

Comments
 (0)