ipc_sysctl.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (C) 2007
  3. *
  4. * Author: Eric Biederman <ebiederm@xmision.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. #include <linux/module.h>
  12. #include <linux/ipc.h>
  13. #include <linux/nsproxy.h>
  14. #include <linux/sysctl.h>
  15. #include <linux/uaccess.h>
  16. #include <linux/ipc_namespace.h>
  17. #include <linux/msg.h>
  18. #include "util.h"
  19. static void *get_ipc(struct ctl_table *table)
  20. {
  21. char *which = table->data;
  22. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  23. which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
  24. return which;
  25. }
  26. #ifdef CONFIG_PROC_SYSCTL
  27. static int proc_ipc_dointvec(struct ctl_table *table, int write,
  28. void __user *buffer, size_t *lenp, loff_t *ppos)
  29. {
  30. struct ctl_table ipc_table;
  31. memcpy(&ipc_table, table, sizeof(ipc_table));
  32. ipc_table.data = get_ipc(table);
  33. return proc_dointvec(&ipc_table, write, buffer, lenp, ppos);
  34. }
  35. static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
  36. void __user *buffer, size_t *lenp, loff_t *ppos)
  37. {
  38. struct ctl_table ipc_table;
  39. memcpy(&ipc_table, table, sizeof(ipc_table));
  40. ipc_table.data = get_ipc(table);
  41. return proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
  42. }
  43. static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
  44. void __user *buffer, size_t *lenp, loff_t *ppos)
  45. {
  46. struct ipc_namespace *ns = current->nsproxy->ipc_ns;
  47. int err = proc_ipc_dointvec_minmax(table, write, buffer, lenp, ppos);
  48. if (err < 0)
  49. return err;
  50. if (ns->shm_rmid_forced)
  51. shm_destroy_orphaned(ns);
  52. return err;
  53. }
  54. static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
  55. void __user *buffer, size_t *lenp, loff_t *ppos)
  56. {
  57. struct ctl_table ipc_table;
  58. memcpy(&ipc_table, table, sizeof(ipc_table));
  59. ipc_table.data = get_ipc(table);
  60. return proc_doulongvec_minmax(&ipc_table, write, buffer,
  61. lenp, ppos);
  62. }
  63. static int proc_ipc_auto_msgmni(struct ctl_table *table, int write,
  64. void __user *buffer, size_t *lenp, loff_t *ppos)
  65. {
  66. struct ctl_table ipc_table;
  67. int dummy = 0;
  68. memcpy(&ipc_table, table, sizeof(ipc_table));
  69. ipc_table.data = &dummy;
  70. if (write)
  71. pr_info_once("writing to auto_msgmni has no effect");
  72. return proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
  73. }
  74. #else
  75. #define proc_ipc_doulongvec_minmax NULL
  76. #define proc_ipc_dointvec NULL
  77. #define proc_ipc_dointvec_minmax NULL
  78. #define proc_ipc_dointvec_minmax_orphans NULL
  79. #define proc_ipc_auto_msgmni NULL
  80. #endif
  81. static int zero;
  82. static int one = 1;
  83. static int int_max = INT_MAX;
  84. static struct ctl_table ipc_kern_table[] = {
  85. {
  86. .procname = "shmmax",
  87. .data = &init_ipc_ns.shm_ctlmax,
  88. .maxlen = sizeof(init_ipc_ns.shm_ctlmax),
  89. .mode = 0644,
  90. .proc_handler = proc_ipc_doulongvec_minmax,
  91. },
  92. {
  93. .procname = "shmall",
  94. .data = &init_ipc_ns.shm_ctlall,
  95. .maxlen = sizeof(init_ipc_ns.shm_ctlall),
  96. .mode = 0644,
  97. .proc_handler = proc_ipc_doulongvec_minmax,
  98. },
  99. {
  100. .procname = "shmmni",
  101. .data = &init_ipc_ns.shm_ctlmni,
  102. .maxlen = sizeof(init_ipc_ns.shm_ctlmni),
  103. .mode = 0644,
  104. .proc_handler = proc_ipc_dointvec,
  105. },
  106. {
  107. .procname = "shm_rmid_forced",
  108. .data = &init_ipc_ns.shm_rmid_forced,
  109. .maxlen = sizeof(init_ipc_ns.shm_rmid_forced),
  110. .mode = 0644,
  111. .proc_handler = proc_ipc_dointvec_minmax_orphans,
  112. .extra1 = &zero,
  113. .extra2 = &one,
  114. },
  115. {
  116. .procname = "msgmax",
  117. .data = &init_ipc_ns.msg_ctlmax,
  118. .maxlen = sizeof(init_ipc_ns.msg_ctlmax),
  119. .mode = 0644,
  120. .proc_handler = proc_ipc_dointvec_minmax,
  121. .extra1 = &zero,
  122. .extra2 = &int_max,
  123. },
  124. {
  125. .procname = "msgmni",
  126. .data = &init_ipc_ns.msg_ctlmni,
  127. .maxlen = sizeof(init_ipc_ns.msg_ctlmni),
  128. .mode = 0644,
  129. .proc_handler = proc_ipc_dointvec_minmax,
  130. .extra1 = &zero,
  131. .extra2 = &int_max,
  132. },
  133. {
  134. .procname = "auto_msgmni",
  135. .data = NULL,
  136. .maxlen = sizeof(int),
  137. .mode = 0644,
  138. .proc_handler = proc_ipc_auto_msgmni,
  139. .extra1 = &zero,
  140. .extra2 = &one,
  141. },
  142. {
  143. .procname = "msgmnb",
  144. .data = &init_ipc_ns.msg_ctlmnb,
  145. .maxlen = sizeof(init_ipc_ns.msg_ctlmnb),
  146. .mode = 0644,
  147. .proc_handler = proc_ipc_dointvec_minmax,
  148. .extra1 = &zero,
  149. .extra2 = &int_max,
  150. },
  151. {
  152. .procname = "sem",
  153. .data = &init_ipc_ns.sem_ctls,
  154. .maxlen = 4*sizeof(int),
  155. .mode = 0644,
  156. .proc_handler = proc_ipc_dointvec,
  157. },
  158. #ifdef CONFIG_CHECKPOINT_RESTORE
  159. {
  160. .procname = "sem_next_id",
  161. .data = &init_ipc_ns.ids[IPC_SEM_IDS].next_id,
  162. .maxlen = sizeof(init_ipc_ns.ids[IPC_SEM_IDS].next_id),
  163. .mode = 0644,
  164. .proc_handler = proc_ipc_dointvec_minmax,
  165. .extra1 = &zero,
  166. .extra2 = &int_max,
  167. },
  168. {
  169. .procname = "msg_next_id",
  170. .data = &init_ipc_ns.ids[IPC_MSG_IDS].next_id,
  171. .maxlen = sizeof(init_ipc_ns.ids[IPC_MSG_IDS].next_id),
  172. .mode = 0644,
  173. .proc_handler = proc_ipc_dointvec_minmax,
  174. .extra1 = &zero,
  175. .extra2 = &int_max,
  176. },
  177. {
  178. .procname = "shm_next_id",
  179. .data = &init_ipc_ns.ids[IPC_SHM_IDS].next_id,
  180. .maxlen = sizeof(init_ipc_ns.ids[IPC_SHM_IDS].next_id),
  181. .mode = 0644,
  182. .proc_handler = proc_ipc_dointvec_minmax,
  183. .extra1 = &zero,
  184. .extra2 = &int_max,
  185. },
  186. #endif
  187. {}
  188. };
  189. static struct ctl_table ipc_root_table[] = {
  190. {
  191. .procname = "kernel",
  192. .mode = 0555,
  193. .child = ipc_kern_table,
  194. },
  195. {}
  196. };
  197. static int __init ipc_sysctl_init(void)
  198. {
  199. register_sysctl_table(ipc_root_table);
  200. return 0;
  201. }
  202. device_initcall(ipc_sysctl_init);