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