Thomas Gleixner | b886d83c | 2019-06-01 10:08:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 |
| 4 | * |
| 5 | * Author: Eric Biederman <ebiederm@xmision.com> |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/ipc.h> |
| 10 | #include <linux/nsproxy.h> |
| 11 | #include <linux/sysctl.h> |
| 12 | #include <linux/uaccess.h> |
Michal Clapinski | 5563cab | 2021-11-08 18:35:59 -0800 | [diff] [blame] | 13 | #include <linux/capability.h> |
Pavel Emelyanov | ae5e1b2 | 2008-02-08 04:18:22 -0800 | [diff] [blame] | 14 | #include <linux/ipc_namespace.h> |
Nadia Derbey | 6546bc4 | 2008-04-29 01:00:45 -0700 | [diff] [blame] | 15 | #include <linux/msg.h> |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 16 | #include <linux/slab.h> |
Nadia Derbey | 6546bc4 | 2008-04-29 01:00:45 -0700 | [diff] [blame] | 17 | #include "util.h" |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 18 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 19 | static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write, |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 20 | void *buffer, size_t *lenp, loff_t *ppos) |
Vasiliy Kulikov | b34a6b1 | 2011-07-26 16:08:48 -0700 | [diff] [blame] | 21 | { |
Alexey Gladkov | dd141a4 | 2022-05-03 15:39:55 +0200 | [diff] [blame] | 22 | struct ipc_namespace *ns = |
| 23 | container_of(table->data, struct ipc_namespace, shm_rmid_forced); |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 24 | int err; |
| 25 | |
Alexey Gladkov | dd141a4 | 2022-05-03 15:39:55 +0200 | [diff] [blame] | 26 | err = proc_dointvec_minmax(table, write, buffer, lenp, ppos); |
Vasiliy Kulikov | b34a6b1 | 2011-07-26 16:08:48 -0700 | [diff] [blame] | 27 | |
| 28 | if (err < 0) |
| 29 | return err; |
| 30 | if (ns->shm_rmid_forced) |
| 31 | shm_destroy_orphaned(ns); |
| 32 | return err; |
| 33 | } |
| 34 | |
Manfred Spraul | 0050ee0 | 2014-12-12 16:58:17 -0800 | [diff] [blame] | 35 | static int proc_ipc_auto_msgmni(struct ctl_table *table, int write, |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 36 | void *buffer, size_t *lenp, loff_t *ppos) |
Nadia Derbey | 9eefe52 | 2008-07-25 01:48:08 -0700 | [diff] [blame] | 37 | { |
| 38 | struct ctl_table ipc_table; |
Manfred Spraul | 0050ee0 | 2014-12-12 16:58:17 -0800 | [diff] [blame] | 39 | int dummy = 0; |
Nadia Derbey | 9eefe52 | 2008-07-25 01:48:08 -0700 | [diff] [blame] | 40 | |
| 41 | memcpy(&ipc_table, table, sizeof(ipc_table)); |
Manfred Spraul | 0050ee0 | 2014-12-12 16:58:17 -0800 | [diff] [blame] | 42 | ipc_table.data = &dummy; |
Nadia Derbey | 9eefe52 | 2008-07-25 01:48:08 -0700 | [diff] [blame] | 43 | |
Manfred Spraul | 0050ee0 | 2014-12-12 16:58:17 -0800 | [diff] [blame] | 44 | if (write) |
| 45 | pr_info_once("writing to auto_msgmni has no effect"); |
Nadia Derbey | 9eefe52 | 2008-07-25 01:48:08 -0700 | [diff] [blame] | 46 | |
Manfred Spraul | 0050ee0 | 2014-12-12 16:58:17 -0800 | [diff] [blame] | 47 | return proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos); |
Nadia Derbey | 9eefe52 | 2008-07-25 01:48:08 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Waiman Long | 8c81ddd | 2018-10-30 15:07:24 -0700 | [diff] [blame] | 50 | static int proc_ipc_sem_dointvec(struct ctl_table *table, int write, |
Tobias Klauser | fff1662 | 2020-09-04 16:35:46 -0700 | [diff] [blame] | 51 | void *buffer, size_t *lenp, loff_t *ppos) |
Waiman Long | 8c81ddd | 2018-10-30 15:07:24 -0700 | [diff] [blame] | 52 | { |
Alexey Gladkov | dd141a4 | 2022-05-03 15:39:55 +0200 | [diff] [blame] | 53 | struct ipc_namespace *ns = |
| 54 | container_of(table->data, struct ipc_namespace, sem_ctls); |
Waiman Long | 8c81ddd | 2018-10-30 15:07:24 -0700 | [diff] [blame] | 55 | int ret, semmni; |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 56 | |
Waiman Long | 8c81ddd | 2018-10-30 15:07:24 -0700 | [diff] [blame] | 57 | semmni = ns->sem_ctls[3]; |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 58 | ret = proc_dointvec(table, write, buffer, lenp, ppos); |
Waiman Long | 8c81ddd | 2018-10-30 15:07:24 -0700 | [diff] [blame] | 59 | |
| 60 | if (!ret) |
Alexey Gladkov | def7343 | 2022-05-03 15:39:54 +0200 | [diff] [blame] | 61 | ret = sem_check_semmni(ns); |
Waiman Long | 8c81ddd | 2018-10-30 15:07:24 -0700 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | * Reset the semmni value if an error happens. |
| 65 | */ |
| 66 | if (ret) |
| 67 | ns->sem_ctls[3] = semmni; |
| 68 | return ret; |
| 69 | } |
| 70 | |
Waiman Long | 5ac893b | 2019-05-14 15:46:29 -0700 | [diff] [blame] | 71 | int ipc_mni = IPCMNI; |
| 72 | int ipc_mni_shift = IPCMNI_SHIFT; |
Manfred Spraul | 99db46e | 2019-05-14 15:46:36 -0700 | [diff] [blame] | 73 | int ipc_min_cycle = RADIX_TREE_MAP_SIZE; |
Nadia Derbey | 9eefe52 | 2008-07-25 01:48:08 -0700 | [diff] [blame] | 74 | |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 75 | static struct ctl_table ipc_sysctls[] = { |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 76 | { |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 77 | .procname = "shmmax", |
| 78 | .data = &init_ipc_ns.shm_ctlmax, |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 79 | .maxlen = sizeof(init_ipc_ns.shm_ctlmax), |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 80 | .mode = 0644, |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 81 | .proc_handler = proc_doulongvec_minmax, |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 82 | }, |
| 83 | { |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 84 | .procname = "shmall", |
| 85 | .data = &init_ipc_ns.shm_ctlall, |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 86 | .maxlen = sizeof(init_ipc_ns.shm_ctlall), |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 87 | .mode = 0644, |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 88 | .proc_handler = proc_doulongvec_minmax, |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 89 | }, |
| 90 | { |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 91 | .procname = "shmmni", |
| 92 | .data = &init_ipc_ns.shm_ctlmni, |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 93 | .maxlen = sizeof(init_ipc_ns.shm_ctlmni), |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 94 | .mode = 0644, |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 95 | .proc_handler = proc_dointvec_minmax, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 96 | .extra1 = SYSCTL_ZERO, |
Waiman Long | 6730e65 | 2018-10-30 15:07:20 -0700 | [diff] [blame] | 97 | .extra2 = &ipc_mni, |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 98 | }, |
| 99 | { |
Vasiliy Kulikov | b34a6b1 | 2011-07-26 16:08:48 -0700 | [diff] [blame] | 100 | .procname = "shm_rmid_forced", |
| 101 | .data = &init_ipc_ns.shm_rmid_forced, |
| 102 | .maxlen = sizeof(init_ipc_ns.shm_rmid_forced), |
| 103 | .mode = 0644, |
| 104 | .proc_handler = proc_ipc_dointvec_minmax_orphans, |
Alexey Gladkov | dd141a4 | 2022-05-03 15:39:55 +0200 | [diff] [blame] | 105 | .extra1 = SYSCTL_ZERO, |
| 106 | .extra2 = SYSCTL_ONE, |
Vasiliy Kulikov | b34a6b1 | 2011-07-26 16:08:48 -0700 | [diff] [blame] | 107 | }, |
| 108 | { |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 109 | .procname = "msgmax", |
| 110 | .data = &init_ipc_ns.msg_ctlmax, |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 111 | .maxlen = sizeof(init_ipc_ns.msg_ctlmax), |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 112 | .mode = 0644, |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 113 | .proc_handler = proc_dointvec_minmax, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 114 | .extra1 = SYSCTL_ZERO, |
| 115 | .extra2 = SYSCTL_INT_MAX, |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 116 | }, |
| 117 | { |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 118 | .procname = "msgmni", |
| 119 | .data = &init_ipc_ns.msg_ctlmni, |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 120 | .maxlen = sizeof(init_ipc_ns.msg_ctlmni), |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 121 | .mode = 0644, |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 122 | .proc_handler = proc_dointvec_minmax, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 123 | .extra1 = SYSCTL_ZERO, |
Waiman Long | 6730e65 | 2018-10-30 15:07:20 -0700 | [diff] [blame] | 124 | .extra2 = &ipc_mni, |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 125 | }, |
| 126 | { |
Manfred Spraul | 0050ee0 | 2014-12-12 16:58:17 -0800 | [diff] [blame] | 127 | .procname = "auto_msgmni", |
| 128 | .data = NULL, |
| 129 | .maxlen = sizeof(int), |
| 130 | .mode = 0644, |
| 131 | .proc_handler = proc_ipc_auto_msgmni, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 132 | .extra1 = SYSCTL_ZERO, |
| 133 | .extra2 = SYSCTL_ONE, |
Manfred Spraul | 0050ee0 | 2014-12-12 16:58:17 -0800 | [diff] [blame] | 134 | }, |
| 135 | { |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 136 | .procname = "msgmnb", |
| 137 | .data = &init_ipc_ns.msg_ctlmnb, |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 138 | .maxlen = sizeof(init_ipc_ns.msg_ctlmnb), |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 139 | .mode = 0644, |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 140 | .proc_handler = proc_dointvec_minmax, |
Matteo Croce | eec4844 | 2019-07-18 15:58:50 -0700 | [diff] [blame] | 141 | .extra1 = SYSCTL_ZERO, |
| 142 | .extra2 = SYSCTL_INT_MAX, |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 143 | }, |
| 144 | { |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 145 | .procname = "sem", |
| 146 | .data = &init_ipc_ns.sem_ctls, |
Manfred Spraul | 239521f | 2014-01-27 17:07:04 -0800 | [diff] [blame] | 147 | .maxlen = 4*sizeof(int), |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 148 | .mode = 0644, |
Waiman Long | 8c81ddd | 2018-10-30 15:07:24 -0700 | [diff] [blame] | 149 | .proc_handler = proc_ipc_sem_dointvec, |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 150 | }, |
Stanislav Kinsbursky | 03f5956 | 2013-01-04 15:34:50 -0800 | [diff] [blame] | 151 | #ifdef CONFIG_CHECKPOINT_RESTORE |
| 152 | { |
| 153 | .procname = "sem_next_id", |
| 154 | .data = &init_ipc_ns.ids[IPC_SEM_IDS].next_id, |
| 155 | .maxlen = sizeof(init_ipc_ns.ids[IPC_SEM_IDS].next_id), |
Alexey Gladkov | 0889f44 | 2022-05-03 15:39:56 +0200 | [diff] [blame] | 156 | .mode = 0444, |
| 157 | .proc_handler = proc_dointvec_minmax, |
| 158 | .extra1 = SYSCTL_ZERO, |
| 159 | .extra2 = SYSCTL_INT_MAX, |
Stanislav Kinsbursky | 03f5956 | 2013-01-04 15:34:50 -0800 | [diff] [blame] | 160 | }, |
| 161 | { |
| 162 | .procname = "msg_next_id", |
| 163 | .data = &init_ipc_ns.ids[IPC_MSG_IDS].next_id, |
| 164 | .maxlen = sizeof(init_ipc_ns.ids[IPC_MSG_IDS].next_id), |
Alexey Gladkov | 0889f44 | 2022-05-03 15:39:56 +0200 | [diff] [blame] | 165 | .mode = 0444, |
| 166 | .proc_handler = proc_dointvec_minmax, |
| 167 | .extra1 = SYSCTL_ZERO, |
| 168 | .extra2 = SYSCTL_INT_MAX, |
Stanislav Kinsbursky | 03f5956 | 2013-01-04 15:34:50 -0800 | [diff] [blame] | 169 | }, |
| 170 | { |
| 171 | .procname = "shm_next_id", |
| 172 | .data = &init_ipc_ns.ids[IPC_SHM_IDS].next_id, |
| 173 | .maxlen = sizeof(init_ipc_ns.ids[IPC_SHM_IDS].next_id), |
Alexey Gladkov | 0889f44 | 2022-05-03 15:39:56 +0200 | [diff] [blame] | 174 | .mode = 0444, |
| 175 | .proc_handler = proc_dointvec_minmax, |
| 176 | .extra1 = SYSCTL_ZERO, |
| 177 | .extra2 = SYSCTL_INT_MAX, |
Stanislav Kinsbursky | 03f5956 | 2013-01-04 15:34:50 -0800 | [diff] [blame] | 178 | }, |
| 179 | #endif |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 180 | {} |
| 181 | }; |
| 182 | |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 183 | static struct ctl_table_set *set_lookup(struct ctl_table_root *root) |
| 184 | { |
| 185 | return ¤t->nsproxy->ipc_ns->ipc_set; |
| 186 | } |
| 187 | |
| 188 | static int set_is_seen(struct ctl_table_set *set) |
| 189 | { |
| 190 | return ¤t->nsproxy->ipc_ns->ipc_set == set; |
| 191 | } |
| 192 | |
Alexey Gladkov | 0889f44 | 2022-05-03 15:39:56 +0200 | [diff] [blame] | 193 | static int ipc_permissions(struct ctl_table_header *head, struct ctl_table *table) |
| 194 | { |
| 195 | int mode = table->mode; |
| 196 | |
| 197 | #ifdef CONFIG_CHECKPOINT_RESTORE |
| 198 | struct ipc_namespace *ns = current->nsproxy->ipc_ns; |
| 199 | |
| 200 | if (((table->data == &ns->ids[IPC_SEM_IDS].next_id) || |
| 201 | (table->data == &ns->ids[IPC_MSG_IDS].next_id) || |
| 202 | (table->data == &ns->ids[IPC_SHM_IDS].next_id)) && |
| 203 | checkpoint_restore_ns_capable(ns->user_ns)) |
| 204 | mode = 0666; |
| 205 | #endif |
| 206 | return mode; |
| 207 | } |
| 208 | |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 209 | static struct ctl_table_root set_root = { |
| 210 | .lookup = set_lookup, |
Alexey Gladkov | 0889f44 | 2022-05-03 15:39:56 +0200 | [diff] [blame] | 211 | .permissions = ipc_permissions, |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 212 | }; |
| 213 | |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 214 | bool setup_ipc_sysctls(struct ipc_namespace *ns) |
| 215 | { |
| 216 | struct ctl_table *tbl; |
| 217 | |
| 218 | setup_sysctl_set(&ns->ipc_set, &set_root, set_is_seen); |
| 219 | |
| 220 | tbl = kmemdup(ipc_sysctls, sizeof(ipc_sysctls), GFP_KERNEL); |
| 221 | if (tbl) { |
| 222 | int i; |
| 223 | |
| 224 | for (i = 0; i < ARRAY_SIZE(ipc_sysctls); i++) { |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 225 | if (tbl[i].data == &init_ipc_ns.shm_ctlmax) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 226 | tbl[i].data = &ns->shm_ctlmax; |
| 227 | |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 228 | else if (tbl[i].data == &init_ipc_ns.shm_ctlall) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 229 | tbl[i].data = &ns->shm_ctlall; |
| 230 | |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 231 | else if (tbl[i].data == &init_ipc_ns.shm_ctlmni) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 232 | tbl[i].data = &ns->shm_ctlmni; |
| 233 | |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 234 | else if (tbl[i].data == &init_ipc_ns.shm_rmid_forced) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 235 | tbl[i].data = &ns->shm_rmid_forced; |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 236 | |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 237 | else if (tbl[i].data == &init_ipc_ns.msg_ctlmax) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 238 | tbl[i].data = &ns->msg_ctlmax; |
| 239 | |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 240 | else if (tbl[i].data == &init_ipc_ns.msg_ctlmni) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 241 | tbl[i].data = &ns->msg_ctlmni; |
| 242 | |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 243 | else if (tbl[i].data == &init_ipc_ns.msg_ctlmnb) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 244 | tbl[i].data = &ns->msg_ctlmnb; |
| 245 | |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 246 | else if (tbl[i].data == &init_ipc_ns.sem_ctls) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 247 | tbl[i].data = &ns->sem_ctls; |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 248 | #ifdef CONFIG_CHECKPOINT_RESTORE |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 249 | else if (tbl[i].data == &init_ipc_ns.ids[IPC_SEM_IDS].next_id) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 250 | tbl[i].data = &ns->ids[IPC_SEM_IDS].next_id; |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 251 | |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 252 | else if (tbl[i].data == &init_ipc_ns.ids[IPC_MSG_IDS].next_id) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 253 | tbl[i].data = &ns->ids[IPC_MSG_IDS].next_id; |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 254 | |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 255 | else if (tbl[i].data == &init_ipc_ns.ids[IPC_SHM_IDS].next_id) |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 256 | tbl[i].data = &ns->ids[IPC_SHM_IDS].next_id; |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 257 | #endif |
Alexey Gladkov | 38cd5b1 | 2022-05-03 15:39:57 +0200 | [diff] [blame] | 258 | else |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 259 | tbl[i].data = NULL; |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | ns->ipc_sysctls = __register_sysctl_table(&ns->ipc_set, "kernel", tbl); |
| 263 | } |
| 264 | if (!ns->ipc_sysctls) { |
| 265 | kfree(tbl); |
| 266 | retire_sysctl_set(&ns->ipc_set); |
| 267 | return false; |
| 268 | } |
| 269 | |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | void retire_ipc_sysctls(struct ipc_namespace *ns) |
| 274 | { |
| 275 | struct ctl_table *tbl; |
| 276 | |
| 277 | tbl = ns->ipc_sysctls->ctl_table_arg; |
| 278 | unregister_sysctl_table(ns->ipc_sysctls); |
| 279 | retire_sysctl_set(&ns->ipc_set); |
| 280 | kfree(tbl); |
| 281 | } |
| 282 | |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 283 | static int __init ipc_sysctl_init(void) |
| 284 | { |
Alexey Gladkov | 1f5c135 | 2022-02-14 19:18:15 +0100 | [diff] [blame] | 285 | if (!setup_ipc_sysctls(&init_ipc_ns)) { |
| 286 | pr_warn("ipc sysctl registration failed\n"); |
| 287 | return -ENOMEM; |
| 288 | } |
Eric W. Biederman | a5494dc | 2007-02-14 00:34:06 -0800 | [diff] [blame] | 289 | return 0; |
| 290 | } |
| 291 | |
Davidlohr Bueso | 6d08a25 | 2014-04-07 15:39:18 -0700 | [diff] [blame] | 292 | device_initcall(ipc_sysctl_init); |
Waiman Long | 5ac893b | 2019-05-14 15:46:29 -0700 | [diff] [blame] | 293 | |
| 294 | static int __init ipc_mni_extend(char *str) |
| 295 | { |
| 296 | ipc_mni = IPCMNI_EXTEND; |
| 297 | ipc_mni_shift = IPCMNI_EXTEND_SHIFT; |
Manfred Spraul | 99db46e | 2019-05-14 15:46:36 -0700 | [diff] [blame] | 298 | ipc_min_cycle = IPCMNI_EXTEND_MIN_CYCLE; |
Waiman Long | 5ac893b | 2019-05-14 15:46:29 -0700 | [diff] [blame] | 299 | pr_info("IPCMNI extended to %d.\n", ipc_mni); |
| 300 | return 0; |
| 301 | } |
| 302 | early_param("ipcmni_extend", ipc_mni_extend); |