1 #include <linux/stat.h>
2 #include <linux/sysctl.h>
3 #include "../fs/xfs/linux-2.6/xfs_sysctl.h"
4 #include <linux/sunrpc/debug.h>
5 #include <linux/string.h>
9 static int sysctl_depth(struct ctl_table
*table
)
11 struct ctl_table
*tmp
;
15 for (tmp
= table
; tmp
->parent
; tmp
= tmp
->parent
)
21 static struct ctl_table
*sysctl_parent(struct ctl_table
*table
, int n
)
25 for (i
= 0; table
&& i
< n
; i
++)
26 table
= table
->parent
;
32 static void sysctl_print_path(struct ctl_table
*table
)
34 struct ctl_table
*tmp
;
36 depth
= sysctl_depth(table
);
37 if (table
->procname
) {
38 for (i
= depth
; i
>= 0; i
--) {
39 tmp
= sysctl_parent(table
, i
);
40 printk("/%s", tmp
->procname
?tmp
->procname
:"");
46 static struct ctl_table
*sysctl_check_lookup(struct nsproxy
*namespaces
,
47 struct ctl_table
*table
)
49 struct ctl_table_header
*head
;
50 struct ctl_table
*ref
, *test
;
53 depth
= sysctl_depth(table
);
55 for (head
= __sysctl_head_next(namespaces
, NULL
); head
;
56 head
= __sysctl_head_next(namespaces
, head
)) {
58 ref
= head
->ctl_table
;
60 test
= sysctl_parent(table
, cur_depth
);
61 for (; ref
->procname
; ref
++) {
63 if (cur_depth
&& !ref
->child
)
66 if (test
->procname
&& ref
->procname
&&
67 (strcmp(test
->procname
, ref
->procname
) == 0))
82 sysctl_head_finish(head
);
86 static void set_fail(const char **fail
, struct ctl_table
*table
, const char *str
)
89 printk(KERN_ERR
"sysctl table check failed: ");
90 sysctl_print_path(table
);
91 printk(" %s\n", *fail
);
97 static void sysctl_check_leaf(struct nsproxy
*namespaces
,
98 struct ctl_table
*table
, const char **fail
)
100 struct ctl_table
*ref
;
102 ref
= sysctl_check_lookup(namespaces
, table
);
103 if (ref
&& (ref
!= table
))
104 set_fail(fail
, table
, "Sysctl already exists");
107 int sysctl_check_table(struct nsproxy
*namespaces
, struct ctl_table
*table
)
110 for (; table
->procname
; table
++) {
111 const char *fail
= NULL
;
114 if (table
->procname
&& !table
->parent
->procname
)
115 set_fail(&fail
, table
, "Parent without procname");
117 if (!table
->procname
)
118 set_fail(&fail
, table
, "No procname");
121 set_fail(&fail
, table
, "Directory with data?");
123 set_fail(&fail
, table
, "Directory with maxlen?");
124 if ((table
->mode
& (S_IRUGO
|S_IXUGO
)) != table
->mode
)
125 set_fail(&fail
, table
, "Writable sysctl directory");
126 if (table
->proc_handler
)
127 set_fail(&fail
, table
, "Directory with proc_handler");
129 set_fail(&fail
, table
, "Directory with extra1");
131 set_fail(&fail
, table
, "Directory with extra2");
133 if ((table
->proc_handler
== proc_dostring
) ||
134 (table
->proc_handler
== proc_dointvec
) ||
135 (table
->proc_handler
== proc_dointvec_minmax
) ||
136 (table
->proc_handler
== proc_dointvec_jiffies
) ||
137 (table
->proc_handler
== proc_dointvec_userhz_jiffies
) ||
138 (table
->proc_handler
== proc_dointvec_ms_jiffies
) ||
139 (table
->proc_handler
== proc_doulongvec_minmax
) ||
140 (table
->proc_handler
== proc_doulongvec_ms_jiffies_minmax
)) {
142 set_fail(&fail
, table
, "No data");
144 set_fail(&fail
, table
, "No maxlen");
146 if ((table
->proc_handler
== proc_doulongvec_minmax
) ||
147 (table
->proc_handler
== proc_doulongvec_ms_jiffies_minmax
)) {
148 if (table
->maxlen
> sizeof (unsigned long)) {
150 set_fail(&fail
, table
, "No min");
152 set_fail(&fail
, table
, "No max");
155 #ifdef CONFIG_PROC_SYSCTL
156 if (table
->procname
&& !table
->proc_handler
)
157 set_fail(&fail
, table
, "No proc_handler");
160 if (!table
->procname
&& table
->proc_handler
)
161 set_fail(&fail
, table
, "proc_handler without procname");
163 sysctl_check_leaf(namespaces
, table
, &fail
);
165 if (table
->mode
> 0777)
166 set_fail(&fail
, table
, "bogus .mode");
168 set_fail(&fail
, table
, NULL
);
172 error
|= sysctl_check_table(namespaces
, table
->child
);