1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2007 IBM Corporation
4 *
5 * Author: Cedric Le Goater <clg@fr.ibm.com>
6 */
7
8 #include <linux/nsproxy.h>
9 #include <linux/ipc_namespace.h>
10 #include <linux/sysctl.h>
11
12 #ifdef CONFIG_PROC_SYSCTL
get_mq(struct ctl_table * table)13 static void *get_mq(struct ctl_table *table)
14 {
15 char *which = table->data;
16 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
17 which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
18 return which;
19 }
20
proc_mq_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)21 static int proc_mq_dointvec(struct ctl_table *table, int write,
22 void *buffer, size_t *lenp, loff_t *ppos)
23 {
24 struct ctl_table mq_table;
25 memcpy(&mq_table, table, sizeof(mq_table));
26 mq_table.data = get_mq(table);
27
28 return proc_dointvec(&mq_table, write, buffer, lenp, ppos);
29 }
30
proc_mq_dointvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)31 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
32 void *buffer, size_t *lenp, loff_t *ppos)
33 {
34 struct ctl_table mq_table;
35 memcpy(&mq_table, table, sizeof(mq_table));
36 mq_table.data = get_mq(table);
37
38 return proc_dointvec_minmax(&mq_table, write, buffer,
39 lenp, ppos);
40 }
41 #else
42 #define proc_mq_dointvec NULL
43 #define proc_mq_dointvec_minmax NULL
44 #endif
45
46 static int msg_max_limit_min = MIN_MSGMAX;
47 static int msg_max_limit_max = HARD_MSGMAX;
48
49 static int msg_maxsize_limit_min = MIN_MSGSIZEMAX;
50 static int msg_maxsize_limit_max = HARD_MSGSIZEMAX;
51
52 static struct ctl_table mq_sysctls[] = {
53 {
54 .procname = "queues_max",
55 .data = &init_ipc_ns.mq_queues_max,
56 .maxlen = sizeof(int),
57 .mode = 0644,
58 .proc_handler = proc_mq_dointvec,
59 },
60 {
61 .procname = "msg_max",
62 .data = &init_ipc_ns.mq_msg_max,
63 .maxlen = sizeof(int),
64 .mode = 0644,
65 .proc_handler = proc_mq_dointvec_minmax,
66 .extra1 = &msg_max_limit_min,
67 .extra2 = &msg_max_limit_max,
68 },
69 {
70 .procname = "msgsize_max",
71 .data = &init_ipc_ns.mq_msgsize_max,
72 .maxlen = sizeof(int),
73 .mode = 0644,
74 .proc_handler = proc_mq_dointvec_minmax,
75 .extra1 = &msg_maxsize_limit_min,
76 .extra2 = &msg_maxsize_limit_max,
77 },
78 {
79 .procname = "msg_default",
80 .data = &init_ipc_ns.mq_msg_default,
81 .maxlen = sizeof(int),
82 .mode = 0644,
83 .proc_handler = proc_mq_dointvec_minmax,
84 .extra1 = &msg_max_limit_min,
85 .extra2 = &msg_max_limit_max,
86 },
87 {
88 .procname = "msgsize_default",
89 .data = &init_ipc_ns.mq_msgsize_default,
90 .maxlen = sizeof(int),
91 .mode = 0644,
92 .proc_handler = proc_mq_dointvec_minmax,
93 .extra1 = &msg_maxsize_limit_min,
94 .extra2 = &msg_maxsize_limit_max,
95 },
96 {}
97 };
98
99 static struct ctl_table mq_sysctl_dir[] = {
100 {
101 .procname = "mqueue",
102 .mode = 0555,
103 .child = mq_sysctls,
104 },
105 {}
106 };
107
108 static struct ctl_table mq_sysctl_root[] = {
109 {
110 .procname = "fs",
111 .mode = 0555,
112 .child = mq_sysctl_dir,
113 },
114 {}
115 };
116
mq_register_sysctl_table(void)117 struct ctl_table_header *mq_register_sysctl_table(void)
118 {
119 return register_sysctl_table(mq_sysctl_root);
120 }
121