mq_sysctl.c 2.7 KB

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