diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2006-12-08 05:39:56 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-08 11:29:03 -0500 |
commit | 9bc9a6bd3cf559bffe962c51efb062e8b5270ca9 (patch) | |
tree | ccfbf817ab501622ef4651d0393de43b085da7ca /kernel/sysctl.c | |
parent | c4b8b769fa9051838d2772886ecd0ee2a926ddc3 (diff) |
[PATCH] sysctl: simplify ipc ns specific sysctls
Refactor the ipc sysctl support so that it is simpler, more readable, and
prepares for fixing the bug with the wrong values being returned in the
sys_sysctl interface.
The function proc_do_ipc_string() was misnamed as it never handled strings.
It's magic of when to work with strings and when to work with longs belonged
in the sysctl table. I couldn't tell if the code would work if you disabled
the ipc namespace but it certainly looked like it would have problems.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/sysctl.c')
-rw-r--r-- | kernel/sysctl.c | 106 |
1 files changed, 49 insertions, 57 deletions
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 77ea4fc386ef..10474a63a111 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -92,7 +92,9 @@ extern char modprobe_path[]; | |||
92 | extern int sg_big_buff; | 92 | extern int sg_big_buff; |
93 | #endif | 93 | #endif |
94 | #ifdef CONFIG_SYSVIPC | 94 | #ifdef CONFIG_SYSVIPC |
95 | static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp, | 95 | static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp, |
96 | void __user *buffer, size_t *lenp, loff_t *ppos); | ||
97 | static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, struct file *filp, | ||
96 | void __user *buffer, size_t *lenp, loff_t *ppos); | 98 | void __user *buffer, size_t *lenp, loff_t *ppos); |
97 | #endif | 99 | #endif |
98 | 100 | ||
@@ -189,6 +191,18 @@ static void put_uts(ctl_table *table, int write, void *which) | |||
189 | up_write(&uts_sem); | 191 | up_write(&uts_sem); |
190 | } | 192 | } |
191 | 193 | ||
194 | #ifdef CONFIG_SYSVIPC | ||
195 | static void *get_ipc(ctl_table *table, int write) | ||
196 | { | ||
197 | char *which = table->data; | ||
198 | struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns; | ||
199 | which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns; | ||
200 | return which; | ||
201 | } | ||
202 | #else | ||
203 | #define get_ipc(T,W) ((T)->data) | ||
204 | #endif | ||
205 | |||
192 | /* /proc declarations: */ | 206 | /* /proc declarations: */ |
193 | 207 | ||
194 | #ifdef CONFIG_PROC_SYSCTL | 208 | #ifdef CONFIG_PROC_SYSCTL |
@@ -458,58 +472,58 @@ static ctl_table kern_table[] = { | |||
458 | { | 472 | { |
459 | .ctl_name = KERN_SHMMAX, | 473 | .ctl_name = KERN_SHMMAX, |
460 | .procname = "shmmax", | 474 | .procname = "shmmax", |
461 | .data = NULL, | 475 | .data = &init_ipc_ns.shm_ctlmax, |
462 | .maxlen = sizeof (size_t), | 476 | .maxlen = sizeof (init_ipc_ns.shm_ctlmax), |
463 | .mode = 0644, | 477 | .mode = 0644, |
464 | .proc_handler = &proc_do_ipc_string, | 478 | .proc_handler = &proc_ipc_doulongvec_minmax, |
465 | }, | 479 | }, |
466 | { | 480 | { |
467 | .ctl_name = KERN_SHMALL, | 481 | .ctl_name = KERN_SHMALL, |
468 | .procname = "shmall", | 482 | .procname = "shmall", |
469 | .data = NULL, | 483 | .data = &init_ipc_ns.shm_ctlall, |
470 | .maxlen = sizeof (size_t), | 484 | .maxlen = sizeof (init_ipc_ns.shm_ctlall), |
471 | .mode = 0644, | 485 | .mode = 0644, |
472 | .proc_handler = &proc_do_ipc_string, | 486 | .proc_handler = &proc_ipc_doulongvec_minmax, |
473 | }, | 487 | }, |
474 | { | 488 | { |
475 | .ctl_name = KERN_SHMMNI, | 489 | .ctl_name = KERN_SHMMNI, |
476 | .procname = "shmmni", | 490 | .procname = "shmmni", |
477 | .data = NULL, | 491 | .data = &init_ipc_ns.shm_ctlmni, |
478 | .maxlen = sizeof (int), | 492 | .maxlen = sizeof (init_ipc_ns.shm_ctlmni), |
479 | .mode = 0644, | 493 | .mode = 0644, |
480 | .proc_handler = &proc_do_ipc_string, | 494 | .proc_handler = &proc_ipc_dointvec, |
481 | }, | 495 | }, |
482 | { | 496 | { |
483 | .ctl_name = KERN_MSGMAX, | 497 | .ctl_name = KERN_MSGMAX, |
484 | .procname = "msgmax", | 498 | .procname = "msgmax", |
485 | .data = NULL, | 499 | .data = &init_ipc_ns.msg_ctlmax, |
486 | .maxlen = sizeof (int), | 500 | .maxlen = sizeof (init_ipc_ns.msg_ctlmax), |
487 | .mode = 0644, | 501 | .mode = 0644, |
488 | .proc_handler = &proc_do_ipc_string, | 502 | .proc_handler = &proc_ipc_dointvec, |
489 | }, | 503 | }, |
490 | { | 504 | { |
491 | .ctl_name = KERN_MSGMNI, | 505 | .ctl_name = KERN_MSGMNI, |
492 | .procname = "msgmni", | 506 | .procname = "msgmni", |
493 | .data = NULL, | 507 | .data = &init_ipc_ns.msg_ctlmni, |
494 | .maxlen = sizeof (int), | 508 | .maxlen = sizeof (init_ipc_ns.msg_ctlmni), |
495 | .mode = 0644, | 509 | .mode = 0644, |
496 | .proc_handler = &proc_do_ipc_string, | 510 | .proc_handler = &proc_ipc_dointvec, |
497 | }, | 511 | }, |
498 | { | 512 | { |
499 | .ctl_name = KERN_MSGMNB, | 513 | .ctl_name = KERN_MSGMNB, |
500 | .procname = "msgmnb", | 514 | .procname = "msgmnb", |
501 | .data = NULL, | 515 | .data = &init_ipc_ns.msg_ctlmnb, |
502 | .maxlen = sizeof (int), | 516 | .maxlen = sizeof (init_ipc_ns.msg_ctlmnb), |
503 | .mode = 0644, | 517 | .mode = 0644, |
504 | .proc_handler = &proc_do_ipc_string, | 518 | .proc_handler = &proc_ipc_dointvec, |
505 | }, | 519 | }, |
506 | { | 520 | { |
507 | .ctl_name = KERN_SEM, | 521 | .ctl_name = KERN_SEM, |
508 | .procname = "sem", | 522 | .procname = "sem", |
509 | .data = NULL, | 523 | .data = &init_ipc_ns.sem_ctls, |
510 | .maxlen = 4*sizeof (int), | 524 | .maxlen = 4*sizeof (int), |
511 | .mode = 0644, | 525 | .mode = 0644, |
512 | .proc_handler = &proc_do_ipc_string, | 526 | .proc_handler = &proc_ipc_dointvec, |
513 | }, | 527 | }, |
514 | #endif | 528 | #endif |
515 | #ifdef CONFIG_MAGIC_SYSRQ | 529 | #ifdef CONFIG_MAGIC_SYSRQ |
@@ -2319,46 +2333,24 @@ int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp, | |||
2319 | } | 2333 | } |
2320 | 2334 | ||
2321 | #ifdef CONFIG_SYSVIPC | 2335 | #ifdef CONFIG_SYSVIPC |
2322 | static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp, | 2336 | static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp, |
2323 | void __user *buffer, size_t *lenp, loff_t *ppos) | 2337 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2324 | { | 2338 | { |
2325 | void *data; | 2339 | void *which; |
2326 | struct ipc_namespace *ns; | 2340 | which = get_ipc(table, write); |
2327 | 2341 | return __do_proc_dointvec(which, table, write, filp, buffer, | |
2328 | ns = current->nsproxy->ipc_ns; | ||
2329 | |||
2330 | switch (table->ctl_name) { | ||
2331 | case KERN_SHMMAX: | ||
2332 | data = &ns->shm_ctlmax; | ||
2333 | goto proc_minmax; | ||
2334 | case KERN_SHMALL: | ||
2335 | data = &ns->shm_ctlall; | ||
2336 | goto proc_minmax; | ||
2337 | case KERN_SHMMNI: | ||
2338 | data = &ns->shm_ctlmni; | ||
2339 | break; | ||
2340 | case KERN_MSGMAX: | ||
2341 | data = &ns->msg_ctlmax; | ||
2342 | break; | ||
2343 | case KERN_MSGMNI: | ||
2344 | data = &ns->msg_ctlmni; | ||
2345 | break; | ||
2346 | case KERN_MSGMNB: | ||
2347 | data = &ns->msg_ctlmnb; | ||
2348 | break; | ||
2349 | case KERN_SEM: | ||
2350 | data = &ns->sem_ctls; | ||
2351 | break; | ||
2352 | default: | ||
2353 | return -EINVAL; | ||
2354 | } | ||
2355 | |||
2356 | return __do_proc_dointvec(data, table, write, filp, buffer, | ||
2357 | lenp, ppos, NULL, NULL); | 2342 | lenp, ppos, NULL, NULL); |
2358 | proc_minmax: | 2343 | } |
2359 | return __do_proc_doulongvec_minmax(data, table, write, filp, buffer, | 2344 | |
2345 | static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, | ||
2346 | struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos) | ||
2347 | { | ||
2348 | void *which; | ||
2349 | which = get_ipc(table, write); | ||
2350 | return __do_proc_doulongvec_minmax(which, table, write, filp, buffer, | ||
2360 | lenp, ppos, 1l, 1l); | 2351 | lenp, ppos, 1l, 1l); |
2361 | } | 2352 | } |
2353 | |||
2362 | #endif | 2354 | #endif |
2363 | 2355 | ||
2364 | static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp, | 2356 | static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp, |