4 * Author: Eric Biederman <ebiederm@xmision.com>
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
12 #include <linux/module.h>
13 #include <linux/ipc.h>
14 #include <linux/nsproxy.h>
15 #include <linux/sysctl.h>
16 #include <linux/uaccess.h>
17 #include <linux/ipc_namespace.h>
18 #include <linux/msg.h>
21 static void *get_ipc(ctl_table
*table
)
23 char *which
= table
->data
;
24 struct ipc_namespace
*ipc_ns
= current
->nsproxy
->ipc_ns
;
25 which
= (which
- (char *)&init_ipc_ns
) + (char *)ipc_ns
;
29 #ifdef CONFIG_PROC_SYSCTL
30 static int proc_ipc_dointvec(ctl_table
*table
, int write
,
31 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
33 struct ctl_table ipc_table
;
34 memcpy(&ipc_table
, table
, sizeof(ipc_table
));
35 ipc_table
.data
= get_ipc(table
);
37 return proc_dointvec(&ipc_table
, write
, buffer
, lenp
, ppos
);
40 static int proc_ipc_callback_dointvec(ctl_table
*table
, int write
,
41 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
43 struct ctl_table ipc_table
;
44 size_t lenp_bef
= *lenp
;
47 memcpy(&ipc_table
, table
, sizeof(ipc_table
));
48 ipc_table
.data
= get_ipc(table
);
50 rc
= proc_dointvec(&ipc_table
, write
, buffer
, lenp
, ppos
);
52 if (write
&& !rc
&& lenp_bef
== *lenp
)
54 * Tunable has successfully been changed by hand. Disable its
55 * automatic adjustment. This simply requires unregistering
56 * the notifiers that trigger recalculation.
58 unregister_ipcns_notifier(current
->nsproxy
->ipc_ns
);
63 static int proc_ipc_doulongvec_minmax(ctl_table
*table
, int write
,
64 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
66 struct ctl_table ipc_table
;
67 memcpy(&ipc_table
, table
, sizeof(ipc_table
));
68 ipc_table
.data
= get_ipc(table
);
70 return proc_doulongvec_minmax(&ipc_table
, write
, buffer
,
75 * Routine that is called when the file "auto_msgmni" has successfully been
77 * Two values are allowed:
78 * 0: unregister msgmni's callback routine from the ipc namespace notifier
79 * chain. This means that msgmni won't be recomputed anymore upon memory
80 * add/remove or ipc namespace creation/removal.
81 * 1: register back the callback routine.
83 static void ipc_auto_callback(int val
)
86 unregister_ipcns_notifier(current
->nsproxy
->ipc_ns
);
89 * Re-enable automatic recomputing only if not already
92 recompute_msgmni(current
->nsproxy
->ipc_ns
);
93 cond_register_ipcns_notifier(current
->nsproxy
->ipc_ns
);
97 static int proc_ipcauto_dointvec_minmax(ctl_table
*table
, int write
,
98 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
100 struct ctl_table ipc_table
;
101 size_t lenp_bef
= *lenp
;
105 memcpy(&ipc_table
, table
, sizeof(ipc_table
));
106 ipc_table
.data
= get_ipc(table
);
107 oldval
= *((int *)(ipc_table
.data
));
109 rc
= proc_dointvec_minmax(&ipc_table
, write
, buffer
, lenp
, ppos
);
111 if (write
&& !rc
&& lenp_bef
== *lenp
) {
112 int newval
= *((int *)(ipc_table
.data
));
114 * The file "auto_msgmni" has correctly been set.
115 * React by (un)registering the corresponding tunable, if the
118 if (newval
!= oldval
)
119 ipc_auto_callback(newval
);
126 #define proc_ipc_doulongvec_minmax NULL
127 #define proc_ipc_dointvec NULL
128 #define proc_ipc_callback_dointvec NULL
129 #define proc_ipcauto_dointvec_minmax NULL
135 static struct ctl_table ipc_kern_table
[] = {
137 .procname
= "shmmax",
138 .data
= &init_ipc_ns
.shm_ctlmax
,
139 .maxlen
= sizeof (init_ipc_ns
.shm_ctlmax
),
141 .proc_handler
= proc_ipc_doulongvec_minmax
,
144 .procname
= "shmall",
145 .data
= &init_ipc_ns
.shm_ctlall
,
146 .maxlen
= sizeof (init_ipc_ns
.shm_ctlall
),
148 .proc_handler
= proc_ipc_doulongvec_minmax
,
151 .procname
= "shmmni",
152 .data
= &init_ipc_ns
.shm_ctlmni
,
153 .maxlen
= sizeof (init_ipc_ns
.shm_ctlmni
),
155 .proc_handler
= proc_ipc_dointvec
,
158 .procname
= "msgmax",
159 .data
= &init_ipc_ns
.msg_ctlmax
,
160 .maxlen
= sizeof (init_ipc_ns
.msg_ctlmax
),
162 .proc_handler
= proc_ipc_dointvec
,
165 .procname
= "msgmni",
166 .data
= &init_ipc_ns
.msg_ctlmni
,
167 .maxlen
= sizeof (init_ipc_ns
.msg_ctlmni
),
169 .proc_handler
= proc_ipc_callback_dointvec
,
172 .procname
= "msgmnb",
173 .data
= &init_ipc_ns
.msg_ctlmnb
,
174 .maxlen
= sizeof (init_ipc_ns
.msg_ctlmnb
),
176 .proc_handler
= proc_ipc_dointvec
,
180 .data
= &init_ipc_ns
.sem_ctls
,
181 .maxlen
= 4*sizeof (int),
183 .proc_handler
= proc_ipc_dointvec
,
186 .procname
= "auto_msgmni",
187 .data
= &init_ipc_ns
.auto_msgmni
,
188 .maxlen
= sizeof(int),
190 .proc_handler
= proc_ipcauto_dointvec_minmax
,
197 static struct ctl_table ipc_root_table
[] = {
199 .procname
= "kernel",
201 .child
= ipc_kern_table
,
206 static int __init
ipc_sysctl_init(void)
208 register_sysctl_table(ipc_root_table
);
212 __initcall(ipc_sysctl_init
);