blob: 72a92a08c848e1e66f3b8f7c2b7566873f42552a [file] [log] [blame]
Thomas Gleixnerb886d83c2019-06-01 10:08:55 +02001// SPDX-License-Identifier: GPL-2.0-only
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -07002/*
3 * Copyright (C) 2007 IBM Corporation
4 *
5 * Author: Cedric Le Goater <clg@fr.ibm.com>
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -07006 */
7
8#include <linux/nsproxy.h>
9#include <linux/ipc_namespace.h>
10#include <linux/sysctl.h>
11
Geert Uytterhoevenf26ec5b2009-04-13 14:39:48 -070012#ifdef CONFIG_PROC_SYSCTL
Joe Perchesa5c59282014-06-06 14:38:07 -070013static void *get_mq(struct ctl_table *table)
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -070014{
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
Joe Perchesa5c59282014-06-06 14:38:07 -070021static int proc_mq_dointvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +020022 void *buffer, size_t *lenp, loff_t *ppos)
Davidlohr Buesof3713fd2014-02-25 15:01:45 -080023{
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
Joe Perchesa5c59282014-06-06 14:38:07 -070031static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +020032 void *buffer, size_t *lenp, loff_t *ppos)
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -070033{
34 struct ctl_table mq_table;
35 memcpy(&mq_table, table, sizeof(mq_table));
36 mq_table.data = get_mq(table);
37
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070038 return proc_dointvec_minmax(&mq_table, write, buffer,
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -070039 lenp, ppos);
40}
41#else
Davidlohr Buesof3713fd2014-02-25 15:01:45 -080042#define proc_mq_dointvec NULL
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -070043#define proc_mq_dointvec_minmax NULL
44#endif
45
46static int msg_max_limit_min = MIN_MSGMAX;
Doug Ledford93e6f112012-05-31 16:26:28 -070047static int msg_max_limit_max = HARD_MSGMAX;
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -070048
49static int msg_maxsize_limit_min = MIN_MSGSIZEMAX;
Doug Ledford93e6f112012-05-31 16:26:28 -070050static int msg_maxsize_limit_max = HARD_MSGSIZEMAX;
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -070051
Joe Perchesa5c59282014-06-06 14:38:07 -070052static struct ctl_table mq_sysctls[] = {
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -070053 {
54 .procname = "queues_max",
55 .data = &init_ipc_ns.mq_queues_max,
56 .maxlen = sizeof(int),
57 .mode = 0644,
Davidlohr Buesof3713fd2014-02-25 15:01:45 -080058 .proc_handler = proc_mq_dointvec,
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -070059 },
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 },
KOSAKI Motohirocef01842012-05-31 16:26:33 -070078 {
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 },
Eric W. Biederman2bc46572009-04-03 02:51:10 -070096 {}
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -070097};
98
Joe Perchesa5c59282014-06-06 14:38:07 -070099static struct ctl_table mq_sysctl_dir[] = {
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -0700100 {
101 .procname = "mqueue",
102 .mode = 0555,
103 .child = mq_sysctls,
104 },
Eric W. Biederman2bc46572009-04-03 02:51:10 -0700105 {}
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -0700106};
107
Joe Perchesa5c59282014-06-06 14:38:07 -0700108static struct ctl_table mq_sysctl_root[] = {
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -0700109 {
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -0700110 .procname = "fs",
111 .mode = 0555,
112 .child = mq_sysctl_dir,
113 },
Eric W. Biederman2bc46572009-04-03 02:51:10 -0700114 {}
Serge E. Hallynbdc8e5f2009-04-06 19:01:11 -0700115};
116
117struct ctl_table_header *mq_register_sysctl_table(void)
118{
119 return register_sysctl_table(mq_sysctl_root);
120}