Blame view

ipc/ipc_sysctl.c 5.37 KB
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  /*
   *  Copyright (C) 2007
   *
   *  Author: Eric Biederman <ebiederm@xmision.com>
   *
   *  This program is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU General Public License as
   *  published by the Free Software Foundation, version 2 of the
   *  License.
   */
  
  #include <linux/module.h>
  #include <linux/ipc.h>
  #include <linux/nsproxy.h>
  #include <linux/sysctl.h>
  #include <linux/uaccess.h>
ae5e1b22f   Pavel Emelyanov   namespaces: move ...
17
  #include <linux/ipc_namespace.h>
6546bc427   Nadia Derbey   ipc: re-enable ms...
18
19
  #include <linux/msg.h>
  #include "util.h"
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
20

a5c5928b7   Joe Perches   ipc: convert use ...
21
  static void *get_ipc(struct ctl_table *table)
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
22
23
24
25
26
27
  {
  	char *which = table->data;
  	struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  	which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
  	return which;
  }
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
28

11dea1900   Serge E. Hallyn   proc_sysctl: use ...
29
  #ifdef CONFIG_PROC_SYSCTL
a5c5928b7   Joe Perches   ipc: convert use ...
30
  static int proc_ipc_dointvec(struct ctl_table *table, int write,
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
31
32
33
  	void __user *buffer, size_t *lenp, loff_t *ppos)
  {
  	struct ctl_table ipc_table;
b34a6b1da   Vasiliy Kulikov   ipc: introduce sh...
34

a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
35
36
  	memcpy(&ipc_table, table, sizeof(ipc_table));
  	ipc_table.data = get_ipc(table);
8d65af789   Alexey Dobriyan   sysctl: remove "s...
37
  	return proc_dointvec(&ipc_table, write, buffer, lenp, ppos);
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
38
  }
a5c5928b7   Joe Perches   ipc: convert use ...
39
  static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
b34a6b1da   Vasiliy Kulikov   ipc: introduce sh...
40
41
42
43
44
45
46
47
48
  	void __user *buffer, size_t *lenp, loff_t *ppos)
  {
  	struct ctl_table ipc_table;
  
  	memcpy(&ipc_table, table, sizeof(ipc_table));
  	ipc_table.data = get_ipc(table);
  
  	return proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
  }
a5c5928b7   Joe Perches   ipc: convert use ...
49
  static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
b34a6b1da   Vasiliy Kulikov   ipc: introduce sh...
50
51
52
53
54
55
56
57
58
59
60
  	void __user *buffer, size_t *lenp, loff_t *ppos)
  {
  	struct ipc_namespace *ns = current->nsproxy->ipc_ns;
  	int err = proc_ipc_dointvec_minmax(table, write, buffer, lenp, ppos);
  
  	if (err < 0)
  		return err;
  	if (ns->shm_rmid_forced)
  		shm_destroy_orphaned(ns);
  	return err;
  }
a5c5928b7   Joe Perches   ipc: convert use ...
61
  static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
8d65af789   Alexey Dobriyan   sysctl: remove "s...
62
  	void __user *buffer, size_t *lenp, loff_t *ppos)
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
63
64
65
66
  {
  	struct ctl_table ipc_table;
  	memcpy(&ipc_table, table, sizeof(ipc_table));
  	ipc_table.data = get_ipc(table);
8d65af789   Alexey Dobriyan   sysctl: remove "s...
67
  	return proc_doulongvec_minmax(&ipc_table, write, buffer,
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
68
69
  					lenp, ppos);
  }
0050ee059   Manfred Spraul   ipc/msg: increase...
70
  static int proc_ipc_auto_msgmni(struct ctl_table *table, int write,
8d65af789   Alexey Dobriyan   sysctl: remove "s...
71
  	void __user *buffer, size_t *lenp, loff_t *ppos)
9eefe520c   Nadia Derbey   ipc: do not use a...
72
73
  {
  	struct ctl_table ipc_table;
0050ee059   Manfred Spraul   ipc/msg: increase...
74
  	int dummy = 0;
9eefe520c   Nadia Derbey   ipc: do not use a...
75
76
  
  	memcpy(&ipc_table, table, sizeof(ipc_table));
0050ee059   Manfred Spraul   ipc/msg: increase...
77
78
79
80
81
82
  	ipc_table.data = &dummy;
  
  	if (write)
  		pr_info_once("writing to auto_msgmni has no effect");
  
  	return proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
9eefe520c   Nadia Derbey   ipc: do not use a...
83
  }
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
84
85
86
  #else
  #define proc_ipc_doulongvec_minmax NULL
  #define proc_ipc_dointvec	   NULL
b34a6b1da   Vasiliy Kulikov   ipc: introduce sh...
87
88
  #define proc_ipc_dointvec_minmax   NULL
  #define proc_ipc_dointvec_minmax_orphans   NULL
0050ee059   Manfred Spraul   ipc/msg: increase...
89
  #define proc_ipc_auto_msgmni	   NULL
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
90
  #endif
9eefe520c   Nadia Derbey   ipc: do not use a...
91
92
  static int zero;
  static int one = 1;
03f595668   Stanislav Kinsbursky   ipc: add sysctl t...
93
  static int int_max = INT_MAX;
9eefe520c   Nadia Derbey   ipc: do not use a...
94

a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
95
96
  static struct ctl_table ipc_kern_table[] = {
  	{
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
97
98
  		.procname	= "shmmax",
  		.data		= &init_ipc_ns.shm_ctlmax,
239521f31   Manfred Spraul   ipc: whitespace c...
99
  		.maxlen		= sizeof(init_ipc_ns.shm_ctlmax),
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
100
101
  		.mode		= 0644,
  		.proc_handler	= proc_ipc_doulongvec_minmax,
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
102
103
  	},
  	{
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
104
105
  		.procname	= "shmall",
  		.data		= &init_ipc_ns.shm_ctlall,
239521f31   Manfred Spraul   ipc: whitespace c...
106
  		.maxlen		= sizeof(init_ipc_ns.shm_ctlall),
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
107
108
  		.mode		= 0644,
  		.proc_handler	= proc_ipc_doulongvec_minmax,
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
109
110
  	},
  	{
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
111
112
  		.procname	= "shmmni",
  		.data		= &init_ipc_ns.shm_ctlmni,
239521f31   Manfred Spraul   ipc: whitespace c...
113
  		.maxlen		= sizeof(init_ipc_ns.shm_ctlmni),
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
114
115
  		.mode		= 0644,
  		.proc_handler	= proc_ipc_dointvec,
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
116
117
  	},
  	{
b34a6b1da   Vasiliy Kulikov   ipc: introduce sh...
118
119
120
121
122
123
124
125
126
  		.procname	= "shm_rmid_forced",
  		.data		= &init_ipc_ns.shm_rmid_forced,
  		.maxlen		= sizeof(init_ipc_ns.shm_rmid_forced),
  		.mode		= 0644,
  		.proc_handler	= proc_ipc_dointvec_minmax_orphans,
  		.extra1		= &zero,
  		.extra2		= &one,
  	},
  	{
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
127
128
  		.procname	= "msgmax",
  		.data		= &init_ipc_ns.msg_ctlmax,
239521f31   Manfred Spraul   ipc: whitespace c...
129
  		.maxlen		= sizeof(init_ipc_ns.msg_ctlmax),
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
130
  		.mode		= 0644,
9bf76ca32   Mathias Krause   ipc, msg: forbid ...
131
132
133
  		.proc_handler	= proc_ipc_dointvec_minmax,
  		.extra1		= &zero,
  		.extra2		= &int_max,
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
134
135
  	},
  	{
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
136
137
  		.procname	= "msgmni",
  		.data		= &init_ipc_ns.msg_ctlmni,
239521f31   Manfred Spraul   ipc: whitespace c...
138
  		.maxlen		= sizeof(init_ipc_ns.msg_ctlmni),
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
139
  		.mode		= 0644,
0050ee059   Manfred Spraul   ipc/msg: increase...
140
  		.proc_handler	= proc_ipc_dointvec_minmax,
9bf76ca32   Mathias Krause   ipc, msg: forbid ...
141
142
  		.extra1		= &zero,
  		.extra2		= &int_max,
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
143
144
  	},
  	{
0050ee059   Manfred Spraul   ipc/msg: increase...
145
146
147
148
149
150
151
152
153
  		.procname	= "auto_msgmni",
  		.data		= NULL,
  		.maxlen		= sizeof(int),
  		.mode		= 0644,
  		.proc_handler	= proc_ipc_auto_msgmni,
  		.extra1		= &zero,
  		.extra2		= &one,
  	},
  	{
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
154
155
  		.procname	=  "msgmnb",
  		.data		= &init_ipc_ns.msg_ctlmnb,
239521f31   Manfred Spraul   ipc: whitespace c...
156
  		.maxlen		= sizeof(init_ipc_ns.msg_ctlmnb),
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
157
  		.mode		= 0644,
9bf76ca32   Mathias Krause   ipc, msg: forbid ...
158
159
160
  		.proc_handler	= proc_ipc_dointvec_minmax,
  		.extra1		= &zero,
  		.extra2		= &int_max,
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
161
162
  	},
  	{
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
163
164
  		.procname	= "sem",
  		.data		= &init_ipc_ns.sem_ctls,
239521f31   Manfred Spraul   ipc: whitespace c...
165
  		.maxlen		= 4*sizeof(int),
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
166
167
  		.mode		= 0644,
  		.proc_handler	= proc_ipc_dointvec,
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
168
  	},
03f595668   Stanislav Kinsbursky   ipc: add sysctl t...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
  #ifdef CONFIG_CHECKPOINT_RESTORE
  	{
  		.procname	= "sem_next_id",
  		.data		= &init_ipc_ns.ids[IPC_SEM_IDS].next_id,
  		.maxlen		= sizeof(init_ipc_ns.ids[IPC_SEM_IDS].next_id),
  		.mode		= 0644,
  		.proc_handler	= proc_ipc_dointvec_minmax,
  		.extra1		= &zero,
  		.extra2		= &int_max,
  	},
  	{
  		.procname	= "msg_next_id",
  		.data		= &init_ipc_ns.ids[IPC_MSG_IDS].next_id,
  		.maxlen		= sizeof(init_ipc_ns.ids[IPC_MSG_IDS].next_id),
  		.mode		= 0644,
  		.proc_handler	= proc_ipc_dointvec_minmax,
  		.extra1		= &zero,
  		.extra2		= &int_max,
  	},
  	{
  		.procname	= "shm_next_id",
  		.data		= &init_ipc_ns.ids[IPC_SHM_IDS].next_id,
  		.maxlen		= sizeof(init_ipc_ns.ids[IPC_SHM_IDS].next_id),
  		.mode		= 0644,
  		.proc_handler	= proc_ipc_dointvec_minmax,
  		.extra1		= &zero,
  		.extra2		= &int_max,
  	},
  #endif
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
198
199
200
201
202
  	{}
  };
  
  static struct ctl_table ipc_root_table[] = {
  	{
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
203
204
205
206
207
208
209
210
211
  		.procname	= "kernel",
  		.mode		= 0555,
  		.child		= ipc_kern_table,
  	},
  	{}
  };
  
  static int __init ipc_sysctl_init(void)
  {
0b4d41471   Eric W. Biederman   [PATCH] sysctl: r...
212
  	register_sysctl_table(ipc_root_table);
a5494dcd8   Eric W. Biederman   [PATCH] sysctl: m...
213
214
  	return 0;
  }
6d08a2567   Davidlohr Bueso   ipc: use device_i...
215
  device_initcall(ipc_sysctl_init);