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