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>
19 static void *get_ipc(ctl_table
*table
)
21 char *which
= table
->data
;
22 struct ipc_namespace
*ipc_ns
= current
->nsproxy
->ipc_ns
;
23 which
= (which
- (char *)&init_ipc_ns
) + (char *)ipc_ns
;
27 #define get_ipc(T) ((T)->data)
31 static int proc_ipc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
32 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
34 struct ctl_table ipc_table
;
35 memcpy(&ipc_table
, table
, sizeof(ipc_table
));
36 ipc_table
.data
= get_ipc(table
);
38 return proc_dointvec(&ipc_table
, write
, filp
, buffer
, lenp
, ppos
);
41 static int proc_ipc_doulongvec_minmax(ctl_table
*table
, int write
,
42 struct file
*filp
, void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
44 struct ctl_table ipc_table
;
45 memcpy(&ipc_table
, table
, sizeof(ipc_table
));
46 ipc_table
.data
= get_ipc(table
);
48 return proc_doulongvec_minmax(&ipc_table
, write
, filp
, buffer
,
53 #define proc_ipc_doulongvec_minmax NULL
54 #define proc_ipc_dointvec NULL
57 #ifdef CONFIG_SYSCTL_SYSCALL
58 /* The generic sysctl ipc data routine. */
59 static int sysctl_ipc_data(ctl_table
*table
, int __user
*name
, int nlen
,
60 void __user
*oldval
, size_t __user
*oldlenp
,
61 void __user
*newval
, size_t newlen
)
66 /* Get out of I don't have a variable */
67 if (!table
->data
|| !table
->maxlen
)
70 data
= get_ipc(table
);
74 if (oldval
&& oldlenp
) {
75 if (get_user(len
, oldlenp
))
78 if (len
> table
->maxlen
)
80 if (copy_to_user(oldval
, data
, len
))
82 if (put_user(len
, oldlenp
))
87 if (newval
&& newlen
) {
88 if (newlen
> table
->maxlen
)
89 newlen
= table
->maxlen
;
91 if (copy_from_user(data
, newval
, newlen
))
97 #define sysctl_ipc_data NULL
100 static struct ctl_table ipc_kern_table
[] = {
102 .ctl_name
= KERN_SHMMAX
,
103 .procname
= "shmmax",
104 .data
= &init_ipc_ns
.shm_ctlmax
,
105 .maxlen
= sizeof (init_ipc_ns
.shm_ctlmax
),
107 .proc_handler
= proc_ipc_doulongvec_minmax
,
108 .strategy
= sysctl_ipc_data
,
111 .ctl_name
= KERN_SHMALL
,
112 .procname
= "shmall",
113 .data
= &init_ipc_ns
.shm_ctlall
,
114 .maxlen
= sizeof (init_ipc_ns
.shm_ctlall
),
116 .proc_handler
= proc_ipc_doulongvec_minmax
,
117 .strategy
= sysctl_ipc_data
,
120 .ctl_name
= KERN_SHMMNI
,
121 .procname
= "shmmni",
122 .data
= &init_ipc_ns
.shm_ctlmni
,
123 .maxlen
= sizeof (init_ipc_ns
.shm_ctlmni
),
125 .proc_handler
= proc_ipc_dointvec
,
126 .strategy
= sysctl_ipc_data
,
129 .ctl_name
= KERN_MSGMAX
,
130 .procname
= "msgmax",
131 .data
= &init_ipc_ns
.msg_ctlmax
,
132 .maxlen
= sizeof (init_ipc_ns
.msg_ctlmax
),
134 .proc_handler
= proc_ipc_dointvec
,
135 .strategy
= sysctl_ipc_data
,
138 .ctl_name
= KERN_MSGMNI
,
139 .procname
= "msgmni",
140 .data
= &init_ipc_ns
.msg_ctlmni
,
141 .maxlen
= sizeof (init_ipc_ns
.msg_ctlmni
),
143 .proc_handler
= proc_ipc_dointvec
,
144 .strategy
= sysctl_ipc_data
,
147 .ctl_name
= KERN_MSGMNB
,
148 .procname
= "msgmnb",
149 .data
= &init_ipc_ns
.msg_ctlmnb
,
150 .maxlen
= sizeof (init_ipc_ns
.msg_ctlmnb
),
152 .proc_handler
= proc_ipc_dointvec
,
153 .strategy
= sysctl_ipc_data
,
156 .ctl_name
= KERN_SEM
,
158 .data
= &init_ipc_ns
.sem_ctls
,
159 .maxlen
= 4*sizeof (int),
161 .proc_handler
= proc_ipc_dointvec
,
162 .strategy
= sysctl_ipc_data
,
167 static struct ctl_table ipc_root_table
[] = {
169 .ctl_name
= CTL_KERN
,
170 .procname
= "kernel",
172 .child
= ipc_kern_table
,
177 static int __init
ipc_sysctl_init(void)
179 register_sysctl_table(ipc_root_table
);
183 __initcall(ipc_sysctl_init
);