1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2007 IBM Corporation
5 * Author: Cedric Le Goater <clg@fr.ibm.com>
8 #include <linux/nsproxy.h>
9 #include <linux/ipc_namespace.h>
10 #include <linux/sysctl.h>
12 #include <linux/stat.h>
13 #include <linux/capability.h>
14 #include <linux/slab.h>
16 static int msg_max_limit_min = MIN_MSGMAX;
17 static int msg_max_limit_max = HARD_MSGMAX;
19 static int msg_maxsize_limit_min = MIN_MSGSIZEMAX;
20 static int msg_maxsize_limit_max = HARD_MSGSIZEMAX;
22 static struct ctl_table mq_sysctls[] = {
24 .procname = "queues_max",
25 .data = &init_ipc_ns.mq_queues_max,
26 .maxlen = sizeof(int),
28 .proc_handler = proc_dointvec,
31 .procname = "msg_max",
32 .data = &init_ipc_ns.mq_msg_max,
33 .maxlen = sizeof(int),
35 .proc_handler = proc_dointvec_minmax,
36 .extra1 = &msg_max_limit_min,
37 .extra2 = &msg_max_limit_max,
40 .procname = "msgsize_max",
41 .data = &init_ipc_ns.mq_msgsize_max,
42 .maxlen = sizeof(int),
44 .proc_handler = proc_dointvec_minmax,
45 .extra1 = &msg_maxsize_limit_min,
46 .extra2 = &msg_maxsize_limit_max,
49 .procname = "msg_default",
50 .data = &init_ipc_ns.mq_msg_default,
51 .maxlen = sizeof(int),
53 .proc_handler = proc_dointvec_minmax,
54 .extra1 = &msg_max_limit_min,
55 .extra2 = &msg_max_limit_max,
58 .procname = "msgsize_default",
59 .data = &init_ipc_ns.mq_msgsize_default,
60 .maxlen = sizeof(int),
62 .proc_handler = proc_dointvec_minmax,
63 .extra1 = &msg_maxsize_limit_min,
64 .extra2 = &msg_maxsize_limit_max,
69 static struct ctl_table_set *set_lookup(struct ctl_table_root *root)
71 return ¤t->nsproxy->ipc_ns->mq_set;
74 static int set_is_seen(struct ctl_table_set *set)
76 return ¤t->nsproxy->ipc_ns->mq_set == set;
79 static struct ctl_table_root set_root = {
83 bool setup_mq_sysctls(struct ipc_namespace *ns)
85 struct ctl_table *tbl;
87 setup_sysctl_set(&ns->mq_set, &set_root, set_is_seen);
89 tbl = kmemdup(mq_sysctls, sizeof(mq_sysctls), GFP_KERNEL);
93 for (i = 0; i < ARRAY_SIZE(mq_sysctls); i++) {
94 if (tbl[i].data == &init_ipc_ns.mq_queues_max)
95 tbl[i].data = &ns->mq_queues_max;
97 else if (tbl[i].data == &init_ipc_ns.mq_msg_max)
98 tbl[i].data = &ns->mq_msg_max;
100 else if (tbl[i].data == &init_ipc_ns.mq_msgsize_max)
101 tbl[i].data = &ns->mq_msgsize_max;
103 else if (tbl[i].data == &init_ipc_ns.mq_msg_default)
104 tbl[i].data = &ns->mq_msg_default;
106 else if (tbl[i].data == &init_ipc_ns.mq_msgsize_default)
107 tbl[i].data = &ns->mq_msgsize_default;
112 ns->mq_sysctls = __register_sysctl_table(&ns->mq_set, "fs/mqueue", tbl);
114 if (!ns->mq_sysctls) {
116 retire_sysctl_set(&ns->mq_set);
123 void retire_mq_sysctls(struct ipc_namespace *ns)
125 struct ctl_table *tbl;
127 tbl = ns->mq_sysctls->ctl_table_arg;
128 unregister_sysctl_table(ns->mq_sysctls);
129 retire_sysctl_set(&ns->mq_set);