Blame view
ipc/ipc_sysctl.c
6.11 KB
b886d83c5 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
a5494dcd8 [PATCH] sysctl: m... |
2 3 4 5 |
/* * Copyright (C) 2007 * * Author: Eric Biederman <ebiederm@xmision.com> |
a5494dcd8 [PATCH] sysctl: m... |
6 7 8 9 10 11 12 |
*/ #include <linux/module.h> #include <linux/ipc.h> #include <linux/nsproxy.h> #include <linux/sysctl.h> #include <linux/uaccess.h> |
ae5e1b22f namespaces: move ... |
13 |
#include <linux/ipc_namespace.h> |
6546bc427 ipc: re-enable ms... |
14 15 |
#include <linux/msg.h> #include "util.h" |
a5494dcd8 [PATCH] sysctl: m... |
16 |
|
a5c5928b7 ipc: convert use ... |
17 |
static void *get_ipc(struct ctl_table *table) |
a5494dcd8 [PATCH] sysctl: m... |
18 19 20 21 22 23 |
{ 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 [PATCH] sysctl: m... |
24 |
|
11dea1900 proc_sysctl: use ... |
25 |
#ifdef CONFIG_PROC_SYSCTL |
a5c5928b7 ipc: convert use ... |
26 |
static int proc_ipc_dointvec(struct ctl_table *table, int write, |
a5494dcd8 [PATCH] sysctl: m... |
27 28 29 |
void __user *buffer, size_t *lenp, loff_t *ppos) { struct ctl_table ipc_table; |
b34a6b1da ipc: introduce sh... |
30 |
|
a5494dcd8 [PATCH] sysctl: m... |
31 32 |
memcpy(&ipc_table, table, sizeof(ipc_table)); ipc_table.data = get_ipc(table); |
8d65af789 sysctl: remove "s... |
33 |
return proc_dointvec(&ipc_table, write, buffer, lenp, ppos); |
a5494dcd8 [PATCH] sysctl: m... |
34 |
} |
a5c5928b7 ipc: convert use ... |
35 |
static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write, |
b34a6b1da ipc: introduce sh... |
36 37 38 39 40 41 42 43 44 |
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 ipc: convert use ... |
45 |
static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write, |
b34a6b1da ipc: introduce sh... |
46 47 48 49 50 51 52 53 54 55 56 |
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 ipc: convert use ... |
57 |
static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write, |
8d65af789 sysctl: remove "s... |
58 |
void __user *buffer, size_t *lenp, loff_t *ppos) |
a5494dcd8 [PATCH] sysctl: m... |
59 60 61 62 |
{ struct ctl_table ipc_table; memcpy(&ipc_table, table, sizeof(ipc_table)); ipc_table.data = get_ipc(table); |
8d65af789 sysctl: remove "s... |
63 |
return proc_doulongvec_minmax(&ipc_table, write, buffer, |
a5494dcd8 [PATCH] sysctl: m... |
64 65 |
lenp, ppos); } |
0050ee059 ipc/msg: increase... |
66 |
static int proc_ipc_auto_msgmni(struct ctl_table *table, int write, |
8d65af789 sysctl: remove "s... |
67 |
void __user *buffer, size_t *lenp, loff_t *ppos) |
9eefe520c ipc: do not use a... |
68 69 |
{ struct ctl_table ipc_table; |
0050ee059 ipc/msg: increase... |
70 |
int dummy = 0; |
9eefe520c ipc: do not use a... |
71 72 |
memcpy(&ipc_table, table, sizeof(ipc_table)); |
0050ee059 ipc/msg: increase... |
73 74 75 76 77 78 |
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 ipc: do not use a... |
79 |
} |
8c81ddd2a ipc: IPCMNI limit... |
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
static int proc_ipc_sem_dointvec(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { int ret, semmni; struct ipc_namespace *ns = current->nsproxy->ipc_ns; semmni = ns->sem_ctls[3]; ret = proc_ipc_dointvec(table, write, buffer, lenp, ppos); if (!ret) ret = sem_check_semmni(current->nsproxy->ipc_ns); /* * Reset the semmni value if an error happens. */ if (ret) ns->sem_ctls[3] = semmni; return ret; } |
a5494dcd8 [PATCH] sysctl: m... |
99 100 101 |
#else #define proc_ipc_doulongvec_minmax NULL #define proc_ipc_dointvec NULL |
b34a6b1da ipc: introduce sh... |
102 103 |
#define proc_ipc_dointvec_minmax NULL #define proc_ipc_dointvec_minmax_orphans NULL |
0050ee059 ipc/msg: increase... |
104 |
#define proc_ipc_auto_msgmni NULL |
8c81ddd2a ipc: IPCMNI limit... |
105 |
#define proc_ipc_sem_dointvec NULL |
a5494dcd8 [PATCH] sysctl: m... |
106 |
#endif |
5ac893b8c ipc: allow boot t... |
107 108 |
int ipc_mni = IPCMNI; int ipc_mni_shift = IPCMNI_SHIFT; |
99db46ea2 ipc: do cyclic id... |
109 |
int ipc_min_cycle = RADIX_TREE_MAP_SIZE; |
9eefe520c ipc: do not use a... |
110 |
|
a5494dcd8 [PATCH] sysctl: m... |
111 112 |
static struct ctl_table ipc_kern_table[] = { { |
a5494dcd8 [PATCH] sysctl: m... |
113 114 |
.procname = "shmmax", .data = &init_ipc_ns.shm_ctlmax, |
239521f31 ipc: whitespace c... |
115 |
.maxlen = sizeof(init_ipc_ns.shm_ctlmax), |
a5494dcd8 [PATCH] sysctl: m... |
116 117 |
.mode = 0644, .proc_handler = proc_ipc_doulongvec_minmax, |
a5494dcd8 [PATCH] sysctl: m... |
118 119 |
}, { |
a5494dcd8 [PATCH] sysctl: m... |
120 121 |
.procname = "shmall", .data = &init_ipc_ns.shm_ctlall, |
239521f31 ipc: whitespace c... |
122 |
.maxlen = sizeof(init_ipc_ns.shm_ctlall), |
a5494dcd8 [PATCH] sysctl: m... |
123 124 |
.mode = 0644, .proc_handler = proc_ipc_doulongvec_minmax, |
a5494dcd8 [PATCH] sysctl: m... |
125 126 |
}, { |
a5494dcd8 [PATCH] sysctl: m... |
127 128 |
.procname = "shmmni", .data = &init_ipc_ns.shm_ctlmni, |
239521f31 ipc: whitespace c... |
129 |
.maxlen = sizeof(init_ipc_ns.shm_ctlmni), |
a5494dcd8 [PATCH] sysctl: m... |
130 |
.mode = 0644, |
6730e6580 ipc: IPCMNI limit... |
131 |
.proc_handler = proc_ipc_dointvec_minmax, |
eec4844fa proc/sysctl: add ... |
132 |
.extra1 = SYSCTL_ZERO, |
6730e6580 ipc: IPCMNI limit... |
133 |
.extra2 = &ipc_mni, |
a5494dcd8 [PATCH] sysctl: m... |
134 135 |
}, { |
b34a6b1da ipc: introduce sh... |
136 137 138 139 140 |
.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, |
eec4844fa proc/sysctl: add ... |
141 142 |
.extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, |
b34a6b1da ipc: introduce sh... |
143 144 |
}, { |
a5494dcd8 [PATCH] sysctl: m... |
145 146 |
.procname = "msgmax", .data = &init_ipc_ns.msg_ctlmax, |
239521f31 ipc: whitespace c... |
147 |
.maxlen = sizeof(init_ipc_ns.msg_ctlmax), |
a5494dcd8 [PATCH] sysctl: m... |
148 |
.mode = 0644, |
9bf76ca32 ipc, msg: forbid ... |
149 |
.proc_handler = proc_ipc_dointvec_minmax, |
eec4844fa proc/sysctl: add ... |
150 151 |
.extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_INT_MAX, |
a5494dcd8 [PATCH] sysctl: m... |
152 153 |
}, { |
a5494dcd8 [PATCH] sysctl: m... |
154 155 |
.procname = "msgmni", .data = &init_ipc_ns.msg_ctlmni, |
239521f31 ipc: whitespace c... |
156 |
.maxlen = sizeof(init_ipc_ns.msg_ctlmni), |
a5494dcd8 [PATCH] sysctl: m... |
157 |
.mode = 0644, |
0050ee059 ipc/msg: increase... |
158 |
.proc_handler = proc_ipc_dointvec_minmax, |
eec4844fa proc/sysctl: add ... |
159 |
.extra1 = SYSCTL_ZERO, |
6730e6580 ipc: IPCMNI limit... |
160 |
.extra2 = &ipc_mni, |
a5494dcd8 [PATCH] sysctl: m... |
161 162 |
}, { |
0050ee059 ipc/msg: increase... |
163 164 165 166 167 |
.procname = "auto_msgmni", .data = NULL, .maxlen = sizeof(int), .mode = 0644, .proc_handler = proc_ipc_auto_msgmni, |
eec4844fa proc/sysctl: add ... |
168 169 |
.extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, |
0050ee059 ipc/msg: increase... |
170 171 |
}, { |
a5494dcd8 [PATCH] sysctl: m... |
172 173 |
.procname = "msgmnb", .data = &init_ipc_ns.msg_ctlmnb, |
239521f31 ipc: whitespace c... |
174 |
.maxlen = sizeof(init_ipc_ns.msg_ctlmnb), |
a5494dcd8 [PATCH] sysctl: m... |
175 |
.mode = 0644, |
9bf76ca32 ipc, msg: forbid ... |
176 |
.proc_handler = proc_ipc_dointvec_minmax, |
eec4844fa proc/sysctl: add ... |
177 178 |
.extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_INT_MAX, |
a5494dcd8 [PATCH] sysctl: m... |
179 180 |
}, { |
a5494dcd8 [PATCH] sysctl: m... |
181 182 |
.procname = "sem", .data = &init_ipc_ns.sem_ctls, |
239521f31 ipc: whitespace c... |
183 |
.maxlen = 4*sizeof(int), |
a5494dcd8 [PATCH] sysctl: m... |
184 |
.mode = 0644, |
8c81ddd2a ipc: IPCMNI limit... |
185 |
.proc_handler = proc_ipc_sem_dointvec, |
a5494dcd8 [PATCH] sysctl: m... |
186 |
}, |
03f595668 ipc: add sysctl t... |
187 188 189 190 191 192 193 |
#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, |
eec4844fa proc/sysctl: add ... |
194 195 |
.extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_INT_MAX, |
03f595668 ipc: add sysctl t... |
196 197 198 199 200 201 202 |
}, { .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, |
eec4844fa proc/sysctl: add ... |
203 204 |
.extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_INT_MAX, |
03f595668 ipc: add sysctl t... |
205 206 207 208 209 210 211 |
}, { .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, |
eec4844fa proc/sysctl: add ... |
212 213 |
.extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_INT_MAX, |
03f595668 ipc: add sysctl t... |
214 215 |
}, #endif |
a5494dcd8 [PATCH] sysctl: m... |
216 217 218 219 220 |
{} }; static struct ctl_table ipc_root_table[] = { { |
a5494dcd8 [PATCH] sysctl: m... |
221 222 223 224 225 226 227 228 229 |
.procname = "kernel", .mode = 0555, .child = ipc_kern_table, }, {} }; static int __init ipc_sysctl_init(void) { |
0b4d41471 [PATCH] sysctl: r... |
230 |
register_sysctl_table(ipc_root_table); |
a5494dcd8 [PATCH] sysctl: m... |
231 232 |
return 0; } |
6d08a2567 ipc: use device_i... |
233 |
device_initcall(ipc_sysctl_init); |
5ac893b8c ipc: allow boot t... |
234 235 236 237 238 |
static int __init ipc_mni_extend(char *str) { ipc_mni = IPCMNI_EXTEND; ipc_mni_shift = IPCMNI_EXTEND_SHIFT; |
99db46ea2 ipc: do cyclic id... |
239 |
ipc_min_cycle = IPCMNI_EXTEND_MIN_CYCLE; |
5ac893b8c ipc: allow boot t... |
240 241 242 243 244 |
pr_info("IPCMNI extended to %d. ", ipc_mni); return 0; } early_param("ipcmni_extend", ipc_mni_extend); |