Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 IBM Corporation |
| 3 | * |
| 4 | * Author: Cedric Le Goater <clg@fr.ibm.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation, version 2 of the |
| 9 | * License. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/nsproxy.h> |
| 13 | #include <linux/ipc_namespace.h> |
| 14 | #include <linux/sysctl.h> |
| 15 | |
Geert Uytterhoeven | f26ec5b | 2009-04-13 14:39:48 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_PROC_SYSCTL |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 17 | static void *get_mq(struct ctl_table *table) |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 18 | { |
| 19 | char *which = table->data; |
| 20 | struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns; |
| 21 | which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns; |
| 22 | return which; |
| 23 | } |
| 24 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 25 | static int proc_mq_dointvec(struct ctl_table *table, int write, |
Davidlohr Bueso | f3713fd | 2014-02-25 15:01:45 -0800 | [diff] [blame] | 26 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 27 | { |
| 28 | struct ctl_table mq_table; |
| 29 | memcpy(&mq_table, table, sizeof(mq_table)); |
| 30 | mq_table.data = get_mq(table); |
| 31 | |
| 32 | return proc_dointvec(&mq_table, write, buffer, lenp, ppos); |
| 33 | } |
| 34 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 35 | static int proc_mq_dointvec_minmax(struct ctl_table *table, int write, |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 36 | void __user *buffer, size_t *lenp, loff_t *ppos) |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 37 | { |
| 38 | struct ctl_table mq_table; |
| 39 | memcpy(&mq_table, table, sizeof(mq_table)); |
| 40 | mq_table.data = get_mq(table); |
| 41 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 42 | return proc_dointvec_minmax(&mq_table, write, buffer, |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 43 | lenp, ppos); |
| 44 | } |
| 45 | #else |
Davidlohr Bueso | f3713fd | 2014-02-25 15:01:45 -0800 | [diff] [blame] | 46 | #define proc_mq_dointvec NULL |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 47 | #define proc_mq_dointvec_minmax NULL |
| 48 | #endif |
| 49 | |
| 50 | static int msg_max_limit_min = MIN_MSGMAX; |
Doug Ledford | 93e6f11 | 2012-05-31 16:26:28 -0700 | [diff] [blame] | 51 | static int msg_max_limit_max = HARD_MSGMAX; |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 52 | |
| 53 | static int msg_maxsize_limit_min = MIN_MSGSIZEMAX; |
Doug Ledford | 93e6f11 | 2012-05-31 16:26:28 -0700 | [diff] [blame] | 54 | static int msg_maxsize_limit_max = HARD_MSGSIZEMAX; |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 55 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 56 | static struct ctl_table mq_sysctls[] = { |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 57 | { |
| 58 | .procname = "queues_max", |
| 59 | .data = &init_ipc_ns.mq_queues_max, |
| 60 | .maxlen = sizeof(int), |
| 61 | .mode = 0644, |
Davidlohr Bueso | f3713fd | 2014-02-25 15:01:45 -0800 | [diff] [blame] | 62 | .proc_handler = proc_mq_dointvec, |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 63 | }, |
| 64 | { |
| 65 | .procname = "msg_max", |
| 66 | .data = &init_ipc_ns.mq_msg_max, |
| 67 | .maxlen = sizeof(int), |
| 68 | .mode = 0644, |
| 69 | .proc_handler = proc_mq_dointvec_minmax, |
| 70 | .extra1 = &msg_max_limit_min, |
| 71 | .extra2 = &msg_max_limit_max, |
| 72 | }, |
| 73 | { |
| 74 | .procname = "msgsize_max", |
| 75 | .data = &init_ipc_ns.mq_msgsize_max, |
| 76 | .maxlen = sizeof(int), |
| 77 | .mode = 0644, |
| 78 | .proc_handler = proc_mq_dointvec_minmax, |
| 79 | .extra1 = &msg_maxsize_limit_min, |
| 80 | .extra2 = &msg_maxsize_limit_max, |
| 81 | }, |
KOSAKI Motohiro | cef0184 | 2012-05-31 16:26:33 -0700 | [diff] [blame] | 82 | { |
| 83 | .procname = "msg_default", |
| 84 | .data = &init_ipc_ns.mq_msg_default, |
| 85 | .maxlen = sizeof(int), |
| 86 | .mode = 0644, |
| 87 | .proc_handler = proc_mq_dointvec_minmax, |
| 88 | .extra1 = &msg_max_limit_min, |
| 89 | .extra2 = &msg_max_limit_max, |
| 90 | }, |
| 91 | { |
| 92 | .procname = "msgsize_default", |
| 93 | .data = &init_ipc_ns.mq_msgsize_default, |
| 94 | .maxlen = sizeof(int), |
| 95 | .mode = 0644, |
| 96 | .proc_handler = proc_mq_dointvec_minmax, |
| 97 | .extra1 = &msg_maxsize_limit_min, |
| 98 | .extra2 = &msg_maxsize_limit_max, |
| 99 | }, |
Eric W. Biederman | 2bc4657 | 2009-04-03 02:51:10 -0700 | [diff] [blame] | 100 | {} |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 103 | static struct ctl_table mq_sysctl_dir[] = { |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 104 | { |
| 105 | .procname = "mqueue", |
| 106 | .mode = 0555, |
| 107 | .child = mq_sysctls, |
| 108 | }, |
Eric W. Biederman | 2bc4657 | 2009-04-03 02:51:10 -0700 | [diff] [blame] | 109 | {} |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 112 | static struct ctl_table mq_sysctl_root[] = { |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 113 | { |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 114 | .procname = "fs", |
| 115 | .mode = 0555, |
| 116 | .child = mq_sysctl_dir, |
| 117 | }, |
Eric W. Biederman | 2bc4657 | 2009-04-03 02:51:10 -0700 | [diff] [blame] | 118 | {} |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | struct ctl_table_header *mq_register_sysctl_table(void) |
| 122 | { |
| 123 | return register_sysctl_table(mq_sysctl_root); |
| 124 | } |