sysctl.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * sysctl.h: General linux system control interface
  4. *
  5. * Begun 24 March 1995, Stephen Tweedie
  6. *
  7. ****************************************************************
  8. ****************************************************************
  9. **
  10. ** WARNING:
  11. ** The values in this file are exported to user space via
  12. ** the sysctl() binary interface. Do *NOT* change the
  13. ** numbering of any existing values here, and do not change
  14. ** any numbers within any one set of values. If you have to
  15. ** redefine an existing interface, use a new number for it.
  16. ** The kernel will then return -ENOTDIR to any application using
  17. ** the old binary interface.
  18. **
  19. ****************************************************************
  20. ****************************************************************
  21. */
  22. #ifndef _LINUX_SYSCTL_H
  23. #define _LINUX_SYSCTL_H
  24. #include <linux/list.h>
  25. #include <linux/rcupdate.h>
  26. #include <linux/wait.h>
  27. #include <linux/rbtree.h>
  28. #include <linux/uidgid.h>
  29. #include <uapi/linux/sysctl.h>
  30. /* For the /proc/sys support */
  31. struct completion;
  32. struct ctl_table;
  33. struct nsproxy;
  34. struct ctl_table_root;
  35. struct ctl_table_header;
  36. struct ctl_dir;
  37. /* Keep the same order as in fs/proc/proc_sysctl.c */
  38. #define SYSCTL_ZERO ((void *)&sysctl_vals[0])
  39. #define SYSCTL_ONE ((void *)&sysctl_vals[1])
  40. #define SYSCTL_TWO ((void *)&sysctl_vals[2])
  41. #define SYSCTL_THREE ((void *)&sysctl_vals[3])
  42. #define SYSCTL_FOUR ((void *)&sysctl_vals[4])
  43. #define SYSCTL_ONE_HUNDRED ((void *)&sysctl_vals[5])
  44. #define SYSCTL_TWO_HUNDRED ((void *)&sysctl_vals[6])
  45. #define SYSCTL_ONE_THOUSAND ((void *)&sysctl_vals[7])
  46. #define SYSCTL_THREE_THOUSAND ((void *)&sysctl_vals[8])
  47. #define SYSCTL_INT_MAX ((void *)&sysctl_vals[9])
  48. /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
  49. #define SYSCTL_MAXOLDUID ((void *)&sysctl_vals[10])
  50. #define SYSCTL_NEG_ONE ((void *)&sysctl_vals[11])
  51. extern const int sysctl_vals[];
  52. #define SYSCTL_LONG_ZERO ((void *)&sysctl_long_vals[0])
  53. #define SYSCTL_LONG_ONE ((void *)&sysctl_long_vals[1])
  54. #define SYSCTL_LONG_MAX ((void *)&sysctl_long_vals[2])
  55. extern const unsigned long sysctl_long_vals[];
  56. typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer,
  57. size_t *lenp, loff_t *ppos);
  58. int proc_dostring(struct ctl_table *, int, void *, size_t *, loff_t *);
  59. int proc_dobool(struct ctl_table *table, int write, void *buffer,
  60. size_t *lenp, loff_t *ppos);
  61. int proc_dointvec(struct ctl_table *, int, void *, size_t *, loff_t *);
  62. int proc_douintvec(struct ctl_table *, int, void *, size_t *, loff_t *);
  63. int proc_dointvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
  64. int proc_douintvec_minmax(struct ctl_table *table, int write, void *buffer,
  65. size_t *lenp, loff_t *ppos);
  66. int proc_dou8vec_minmax(struct ctl_table *table, int write, void *buffer,
  67. size_t *lenp, loff_t *ppos);
  68. int proc_dointvec_jiffies(struct ctl_table *, int, void *, size_t *, loff_t *);
  69. int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  70. void *buffer, size_t *lenp, loff_t *ppos);
  71. int proc_dointvec_userhz_jiffies(struct ctl_table *, int, void *, size_t *,
  72. loff_t *);
  73. int proc_dointvec_ms_jiffies(struct ctl_table *, int, void *, size_t *,
  74. loff_t *);
  75. int proc_doulongvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);
  76. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int, void *,
  77. size_t *, loff_t *);
  78. int proc_do_large_bitmap(struct ctl_table *, int, void *, size_t *, loff_t *);
  79. int proc_do_static_key(struct ctl_table *table, int write, void *buffer,
  80. size_t *lenp, loff_t *ppos);
  81. /*
  82. * Register a set of sysctl names by calling register_sysctl_table
  83. * with an initialised array of struct ctl_table's. An entry with
  84. * NULL procname terminates the table. table->de will be
  85. * set up by the registration and need not be initialised in advance.
  86. *
  87. * sysctl names can be mirrored automatically under /proc/sys. The
  88. * procname supplied controls /proc naming.
  89. *
  90. * The table's mode will be honoured for proc-fs access.
  91. *
  92. * Leaf nodes in the sysctl tree will be represented by a single file
  93. * under /proc; non-leaf nodes will be represented by directories. A
  94. * null procname disables /proc mirroring at this node.
  95. *
  96. * The data and maxlen fields of the ctl_table
  97. * struct enable minimal validation of the values being written to be
  98. * performed, and the mode field allows minimal authentication.
  99. *
  100. * There must be a proc_handler routine for any terminal nodes
  101. * mirrored under /proc/sys (non-terminals are handled by a built-in
  102. * directory handler). Several default handlers are available to
  103. * cover common cases.
  104. */
  105. /* Support for userspace poll() to watch for changes */
  106. struct ctl_table_poll {
  107. atomic_t event;
  108. wait_queue_head_t wait;
  109. };
  110. static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
  111. {
  112. return (void *)(unsigned long)atomic_read(&poll->event);
  113. }
  114. #define __CTL_TABLE_POLL_INITIALIZER(name) { \
  115. .event = ATOMIC_INIT(0), \
  116. .wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait) }
  117. #define DEFINE_CTL_TABLE_POLL(name) \
  118. struct ctl_table_poll name = __CTL_TABLE_POLL_INITIALIZER(name)
  119. /* A sysctl table is an array of struct ctl_table: */
  120. struct ctl_table {
  121. const char *procname; /* Text ID for /proc/sys, or zero */
  122. void *data;
  123. int maxlen;
  124. umode_t mode;
  125. struct ctl_table *child; /* Deprecated */
  126. proc_handler *proc_handler; /* Callback for text formatting */
  127. struct ctl_table_poll *poll;
  128. void *extra1;
  129. void *extra2;
  130. } __randomize_layout;
  131. struct ctl_node {
  132. struct rb_node node;
  133. struct ctl_table_header *header;
  134. };
  135. /* struct ctl_table_header is used to maintain dynamic lists of
  136. struct ctl_table trees. */
  137. struct ctl_table_header {
  138. union {
  139. struct {
  140. struct ctl_table *ctl_table;
  141. int used;
  142. int count;
  143. int nreg;
  144. };
  145. struct rcu_head rcu;
  146. };
  147. struct completion *unregistering;
  148. struct ctl_table *ctl_table_arg;
  149. struct ctl_table_root *root;
  150. struct ctl_table_set *set;
  151. struct ctl_dir *parent;
  152. struct ctl_node *node;
  153. struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */
  154. };
  155. struct ctl_dir {
  156. /* Header must be at the start of ctl_dir */
  157. struct ctl_table_header header;
  158. struct rb_root root;
  159. };
  160. struct ctl_table_set {
  161. int (*is_seen)(struct ctl_table_set *);
  162. struct ctl_dir dir;
  163. };
  164. struct ctl_table_root {
  165. struct ctl_table_set default_set;
  166. struct ctl_table_set *(*lookup)(struct ctl_table_root *root);
  167. void (*set_ownership)(struct ctl_table_header *head,
  168. struct ctl_table *table,
  169. kuid_t *uid, kgid_t *gid);
  170. int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
  171. };
  172. /* struct ctl_path describes where in the hierarchy a table is added */
  173. struct ctl_path {
  174. const char *procname;
  175. };
  176. #ifdef CONFIG_SYSCTL
  177. #define DECLARE_SYSCTL_BASE(_name, _table) \
  178. static struct ctl_table _name##_base_table[] = { \
  179. { \
  180. .procname = #_name, \
  181. .mode = 0555, \
  182. .child = _table, \
  183. }, \
  184. { }, \
  185. }
  186. extern int __register_sysctl_base(struct ctl_table *base_table);
  187. #define register_sysctl_base(_name) __register_sysctl_base(_name##_base_table)
  188. void proc_sys_poll_notify(struct ctl_table_poll *poll);
  189. extern void setup_sysctl_set(struct ctl_table_set *p,
  190. struct ctl_table_root *root,
  191. int (*is_seen)(struct ctl_table_set *));
  192. extern void retire_sysctl_set(struct ctl_table_set *set);
  193. struct ctl_table_header *__register_sysctl_table(
  194. struct ctl_table_set *set,
  195. const char *path, struct ctl_table *table);
  196. struct ctl_table_header *__register_sysctl_paths(
  197. struct ctl_table_set *set,
  198. const struct ctl_path *path, struct ctl_table *table);
  199. struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table);
  200. struct ctl_table_header *register_sysctl_table(struct ctl_table * table);
  201. struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
  202. struct ctl_table *table);
  203. void unregister_sysctl_table(struct ctl_table_header * table);
  204. extern int sysctl_init_bases(void);
  205. extern void __register_sysctl_init(const char *path, struct ctl_table *table,
  206. const char *table_name);
  207. #define register_sysctl_init(path, table) __register_sysctl_init(path, table, #table)
  208. extern struct ctl_table_header *register_sysctl_mount_point(const char *path);
  209. void do_sysctl_args(void);
  210. bool sysctl_is_alias(char *param);
  211. int do_proc_douintvec(struct ctl_table *table, int write,
  212. void *buffer, size_t *lenp, loff_t *ppos,
  213. int (*conv)(unsigned long *lvalp,
  214. unsigned int *valp,
  215. int write, void *data),
  216. void *data);
  217. extern int pwrsw_enabled;
  218. extern int unaligned_enabled;
  219. extern int unaligned_dump_stack;
  220. extern int no_unaligned_warning;
  221. extern struct ctl_table sysctl_mount_point[];
  222. #else /* CONFIG_SYSCTL */
  223. #define DECLARE_SYSCTL_BASE(_name, _table)
  224. static inline int __register_sysctl_base(struct ctl_table *base_table)
  225. {
  226. return 0;
  227. }
  228. #define register_sysctl_base(table) __register_sysctl_base(table)
  229. static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
  230. {
  231. return NULL;
  232. }
  233. static inline void register_sysctl_init(const char *path, struct ctl_table *table)
  234. {
  235. }
  236. static inline struct ctl_table_header *register_sysctl_mount_point(const char *path)
  237. {
  238. return NULL;
  239. }
  240. static inline struct ctl_table_header *register_sysctl_paths(
  241. const struct ctl_path *path, struct ctl_table *table)
  242. {
  243. return NULL;
  244. }
  245. static inline struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table)
  246. {
  247. return NULL;
  248. }
  249. static inline void unregister_sysctl_table(struct ctl_table_header * table)
  250. {
  251. }
  252. static inline void setup_sysctl_set(struct ctl_table_set *p,
  253. struct ctl_table_root *root,
  254. int (*is_seen)(struct ctl_table_set *))
  255. {
  256. }
  257. static inline void do_sysctl_args(void)
  258. {
  259. }
  260. static inline bool sysctl_is_alias(char *param)
  261. {
  262. return false;
  263. }
  264. #endif /* CONFIG_SYSCTL */
  265. int sysctl_max_threads(struct ctl_table *table, int write, void *buffer,
  266. size_t *lenp, loff_t *ppos);
  267. #endif /* _LINUX_SYSCTL_H */