Thomas Gleixner | b886d83c | 2019-06-01 10:08:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 IBM Corporation |
| 4 | * |
| 5 | * Author: Cedric Le Goater <clg@fr.ibm.com> |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/nsproxy.h> |
| 9 | #include <linux/ipc_namespace.h> |
| 10 | #include <linux/sysctl.h> |
| 11 | |
Geert Uytterhoeven | f26ec5b | 2009-04-13 14:39:48 -0700 | [diff] [blame] | 12 | #ifdef CONFIG_PROC_SYSCTL |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 13 | static void *get_mq(struct ctl_table *table) |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 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 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 21 | static int proc_mq_dointvec(struct ctl_table *table, int write, |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 22 | void *buffer, size_t *lenp, loff_t *ppos) |
Davidlohr Bueso | f3713fd | 2014-02-25 15:01:45 -0800 | [diff] [blame] | 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 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 31 | static int proc_mq_dointvec_minmax(struct ctl_table *table, int write, |
Christoph Hellwig | 3292739 | 2020-04-24 08:43:38 +0200 | [diff] [blame] | 32 | void *buffer, size_t *lenp, loff_t *ppos) |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 33 | { |
| 34 | struct ctl_table mq_table; |
| 35 | memcpy(&mq_table, table, sizeof(mq_table)); |
| 36 | mq_table.data = get_mq(table); |
| 37 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 38 | return proc_dointvec_minmax(&mq_table, write, buffer, |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 39 | lenp, ppos); |
| 40 | } |
| 41 | #else |
Davidlohr Bueso | f3713fd | 2014-02-25 15:01:45 -0800 | [diff] [blame] | 42 | #define proc_mq_dointvec NULL |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 43 | #define proc_mq_dointvec_minmax NULL |
| 44 | #endif |
| 45 | |
| 46 | static int msg_max_limit_min = MIN_MSGMAX; |
Doug Ledford | 93e6f11 | 2012-05-31 16:26:28 -0700 | [diff] [blame] | 47 | static int msg_max_limit_max = HARD_MSGMAX; |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 48 | |
| 49 | static int msg_maxsize_limit_min = MIN_MSGSIZEMAX; |
Doug Ledford | 93e6f11 | 2012-05-31 16:26:28 -0700 | [diff] [blame] | 50 | static int msg_maxsize_limit_max = HARD_MSGSIZEMAX; |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 51 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 52 | static struct ctl_table mq_sysctls[] = { |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 53 | { |
| 54 | .procname = "queues_max", |
| 55 | .data = &init_ipc_ns.mq_queues_max, |
| 56 | .maxlen = sizeof(int), |
| 57 | .mode = 0644, |
Davidlohr Bueso | f3713fd | 2014-02-25 15:01:45 -0800 | [diff] [blame] | 58 | .proc_handler = proc_mq_dointvec, |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 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 | }, |
KOSAKI Motohiro | cef0184 | 2012-05-31 16:26:33 -0700 | [diff] [blame] | 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 | }, |
Eric W. Biederman | 2bc4657 | 2009-04-03 02:51:10 -0700 | [diff] [blame] | 96 | {} |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 99 | static struct ctl_table mq_sysctl_dir[] = { |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 100 | { |
| 101 | .procname = "mqueue", |
| 102 | .mode = 0555, |
| 103 | .child = mq_sysctls, |
| 104 | }, |
Eric W. Biederman | 2bc4657 | 2009-04-03 02:51:10 -0700 | [diff] [blame] | 105 | {} |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Joe Perches | a5c5928 | 2014-06-06 14:38:07 -0700 | [diff] [blame] | 108 | static struct ctl_table mq_sysctl_root[] = { |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 109 | { |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 110 | .procname = "fs", |
| 111 | .mode = 0555, |
| 112 | .child = mq_sysctl_dir, |
| 113 | }, |
Eric W. Biederman | 2bc4657 | 2009-04-03 02:51:10 -0700 | [diff] [blame] | 114 | {} |
Serge E. Hallyn | bdc8e5f | 2009-04-06 19:01:11 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | struct ctl_table_header *mq_register_sysctl_table(void) |
| 118 | { |
| 119 | return register_sysctl_table(mq_sysctl_root); |
| 120 | } |