sysctl.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * sysctl.c: General linux system control interface
  4. *
  5. * Begun 24 March 1995, Stephen Tweedie
  6. * Added /proc support, Dec 1995
  7. * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
  8. * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
  9. * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
  10. * Dynamic registration fixes, Stephen Tweedie.
  11. * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
  12. * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
  13. * Horn.
  14. * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
  15. * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
  16. * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
  17. * Wendling.
  18. * The list_for_each() macro wasn't appropriate for the sysctl loop.
  19. * Removed it and replaced it with older style, 03/23/00, Bill Wendling
  20. */
  21. #include <linux/module.h>
  22. #include <linux/mm.h>
  23. #include <linux/swap.h>
  24. #include <linux/slab.h>
  25. #include <linux/sysctl.h>
  26. #include <linux/bitmap.h>
  27. #include <linux/signal.h>
  28. #include <linux/panic.h>
  29. #include <linux/printk.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/security.h>
  32. #include <linux/ctype.h>
  33. #include <linux/kmemleak.h>
  34. #include <linux/filter.h>
  35. #include <linux/fs.h>
  36. #include <linux/init.h>
  37. #include <linux/kernel.h>
  38. #include <linux/kobject.h>
  39. #include <linux/net.h>
  40. #include <linux/sysrq.h>
  41. #include <linux/highuid.h>
  42. #include <linux/writeback.h>
  43. #include <linux/ratelimit.h>
  44. #include <linux/hugetlb.h>
  45. #include <linux/initrd.h>
  46. #include <linux/key.h>
  47. #include <linux/times.h>
  48. #include <linux/limits.h>
  49. #include <linux/dcache.h>
  50. #include <linux/syscalls.h>
  51. #include <linux/vmstat.h>
  52. #include <linux/nfs_fs.h>
  53. #include <linux/acpi.h>
  54. #include <linux/reboot.h>
  55. #include <linux/ftrace.h>
  56. #include <linux/perf_event.h>
  57. #include <linux/oom.h>
  58. #include <linux/kmod.h>
  59. #include <linux/capability.h>
  60. #include <linux/binfmts.h>
  61. #include <linux/sched/sysctl.h>
  62. #include <linux/mount.h>
  63. #include <linux/userfaultfd_k.h>
  64. #include <linux/pid.h>
  65. #include "../lib/kstrtox.h"
  66. #include <linux/uaccess.h>
  67. #include <asm/processor.h>
  68. #ifdef CONFIG_X86
  69. #include <asm/nmi.h>
  70. #include <asm/stacktrace.h>
  71. #include <asm/io.h>
  72. #endif
  73. #ifdef CONFIG_SPARC
  74. #include <asm/setup.h>
  75. #endif
  76. #ifdef CONFIG_RT_MUTEXES
  77. #include <linux/rtmutex.h>
  78. #endif
  79. /* shared constants to be used in various sysctls */
  80. const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
  81. EXPORT_SYMBOL(sysctl_vals);
  82. const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
  83. EXPORT_SYMBOL_GPL(sysctl_long_vals);
  84. #if defined(CONFIG_SYSCTL)
  85. /* Constants used for minimum and maximum */
  86. #ifdef CONFIG_PERF_EVENTS
  87. static const int six_hundred_forty_kb = 640 * 1024;
  88. #endif
  89. static const int ngroups_max = NGROUPS_MAX;
  90. static const int cap_last_cap = CAP_LAST_CAP;
  91. #ifdef CONFIG_PROC_SYSCTL
  92. /**
  93. * enum sysctl_writes_mode - supported sysctl write modes
  94. *
  95. * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
  96. * to be written, and multiple writes on the same sysctl file descriptor
  97. * will rewrite the sysctl value, regardless of file position. No warning
  98. * is issued when the initial position is not 0.
  99. * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
  100. * not 0.
  101. * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
  102. * file position 0 and the value must be fully contained in the buffer
  103. * sent to the write syscall. If dealing with strings respect the file
  104. * position, but restrict this to the max length of the buffer, anything
  105. * passed the max length will be ignored. Multiple writes will append
  106. * to the buffer.
  107. *
  108. * These write modes control how current file position affects the behavior of
  109. * updating sysctl values through the proc interface on each write.
  110. */
  111. enum sysctl_writes_mode {
  112. SYSCTL_WRITES_LEGACY = -1,
  113. SYSCTL_WRITES_WARN = 0,
  114. SYSCTL_WRITES_STRICT = 1,
  115. };
  116. static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
  117. #endif /* CONFIG_PROC_SYSCTL */
  118. #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
  119. defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
  120. int sysctl_legacy_va_layout;
  121. #endif
  122. #endif /* CONFIG_SYSCTL */
  123. /*
  124. * /proc/sys support
  125. */
  126. #ifdef CONFIG_PROC_SYSCTL
  127. static int _proc_do_string(char *data, int maxlen, int write,
  128. char *buffer, size_t *lenp, loff_t *ppos)
  129. {
  130. size_t len;
  131. char c, *p;
  132. if (!data || !maxlen || !*lenp) {
  133. *lenp = 0;
  134. return 0;
  135. }
  136. if (write) {
  137. if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
  138. /* Only continue writes not past the end of buffer. */
  139. len = strlen(data);
  140. if (len > maxlen - 1)
  141. len = maxlen - 1;
  142. if (*ppos > len)
  143. return 0;
  144. len = *ppos;
  145. } else {
  146. /* Start writing from beginning of buffer. */
  147. len = 0;
  148. }
  149. *ppos += *lenp;
  150. p = buffer;
  151. while ((p - buffer) < *lenp && len < maxlen - 1) {
  152. c = *(p++);
  153. if (c == 0 || c == '\n')
  154. break;
  155. data[len++] = c;
  156. }
  157. data[len] = 0;
  158. } else {
  159. len = strlen(data);
  160. if (len > maxlen)
  161. len = maxlen;
  162. if (*ppos > len) {
  163. *lenp = 0;
  164. return 0;
  165. }
  166. data += *ppos;
  167. len -= *ppos;
  168. if (len > *lenp)
  169. len = *lenp;
  170. if (len)
  171. memcpy(buffer, data, len);
  172. if (len < *lenp) {
  173. buffer[len] = '\n';
  174. len++;
  175. }
  176. *lenp = len;
  177. *ppos += len;
  178. }
  179. return 0;
  180. }
  181. static void warn_sysctl_write(const struct ctl_table *table)
  182. {
  183. pr_warn_once("%s wrote to %s when file position was not 0!\n"
  184. "This will not be supported in the future. To silence this\n"
  185. "warning, set kernel.sysctl_writes_strict = -1\n",
  186. current->comm, table->procname);
  187. }
  188. /**
  189. * proc_first_pos_non_zero_ignore - check if first position is allowed
  190. * @ppos: file position
  191. * @table: the sysctl table
  192. *
  193. * Returns true if the first position is non-zero and the sysctl_writes_strict
  194. * mode indicates this is not allowed for numeric input types. String proc
  195. * handlers can ignore the return value.
  196. */
  197. static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
  198. const struct ctl_table *table)
  199. {
  200. if (!*ppos)
  201. return false;
  202. switch (sysctl_writes_strict) {
  203. case SYSCTL_WRITES_STRICT:
  204. return true;
  205. case SYSCTL_WRITES_WARN:
  206. warn_sysctl_write(table);
  207. return false;
  208. default:
  209. return false;
  210. }
  211. }
  212. /**
  213. * proc_dostring - read a string sysctl
  214. * @table: the sysctl table
  215. * @write: %TRUE if this is a write to the sysctl file
  216. * @buffer: the user buffer
  217. * @lenp: the size of the user buffer
  218. * @ppos: file position
  219. *
  220. * Reads/writes a string from/to the user buffer. If the kernel
  221. * buffer provided is not large enough to hold the string, the
  222. * string is truncated. The copied string is %NULL-terminated.
  223. * If the string is being read by the user process, it is copied
  224. * and a newline '\n' is added. It is truncated if the buffer is
  225. * not large enough.
  226. *
  227. * Returns 0 on success.
  228. */
  229. int proc_dostring(const struct ctl_table *table, int write,
  230. void *buffer, size_t *lenp, loff_t *ppos)
  231. {
  232. if (write)
  233. proc_first_pos_non_zero_ignore(ppos, table);
  234. return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
  235. ppos);
  236. }
  237. static void proc_skip_spaces(char **buf, size_t *size)
  238. {
  239. while (*size) {
  240. if (!isspace(**buf))
  241. break;
  242. (*size)--;
  243. (*buf)++;
  244. }
  245. }
  246. static void proc_skip_char(char **buf, size_t *size, const char v)
  247. {
  248. while (*size) {
  249. if (**buf != v)
  250. break;
  251. (*size)--;
  252. (*buf)++;
  253. }
  254. }
  255. /**
  256. * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
  257. * fail on overflow
  258. *
  259. * @cp: kernel buffer containing the string to parse
  260. * @endp: pointer to store the trailing characters
  261. * @base: the base to use
  262. * @res: where the parsed integer will be stored
  263. *
  264. * In case of success 0 is returned and @res will contain the parsed integer,
  265. * @endp will hold any trailing characters.
  266. * This function will fail the parse on overflow. If there wasn't an overflow
  267. * the function will defer the decision what characters count as invalid to the
  268. * caller.
  269. */
  270. static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
  271. unsigned long *res)
  272. {
  273. unsigned long long result;
  274. unsigned int rv;
  275. cp = _parse_integer_fixup_radix(cp, &base);
  276. rv = _parse_integer(cp, base, &result);
  277. if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
  278. return -ERANGE;
  279. cp += rv;
  280. if (endp)
  281. *endp = (char *)cp;
  282. *res = (unsigned long)result;
  283. return 0;
  284. }
  285. #define TMPBUFLEN 22
  286. /**
  287. * proc_get_long - reads an ASCII formatted integer from a user buffer
  288. *
  289. * @buf: a kernel buffer
  290. * @size: size of the kernel buffer
  291. * @val: this is where the number will be stored
  292. * @neg: set to %TRUE if number is negative
  293. * @perm_tr: a vector which contains the allowed trailers
  294. * @perm_tr_len: size of the perm_tr vector
  295. * @tr: pointer to store the trailer character
  296. *
  297. * In case of success %0 is returned and @buf and @size are updated with
  298. * the amount of bytes read. If @tr is non-NULL and a trailing
  299. * character exists (size is non-zero after returning from this
  300. * function), @tr is updated with the trailing character.
  301. */
  302. static int proc_get_long(char **buf, size_t *size,
  303. unsigned long *val, bool *neg,
  304. const char *perm_tr, unsigned perm_tr_len, char *tr)
  305. {
  306. char *p, tmp[TMPBUFLEN];
  307. ssize_t len = *size;
  308. if (len <= 0)
  309. return -EINVAL;
  310. if (len > TMPBUFLEN - 1)
  311. len = TMPBUFLEN - 1;
  312. memcpy(tmp, *buf, len);
  313. tmp[len] = 0;
  314. p = tmp;
  315. if (*p == '-' && *size > 1) {
  316. *neg = true;
  317. p++;
  318. } else
  319. *neg = false;
  320. if (!isdigit(*p))
  321. return -EINVAL;
  322. if (strtoul_lenient(p, &p, 0, val))
  323. return -EINVAL;
  324. len = p - tmp;
  325. /* We don't know if the next char is whitespace thus we may accept
  326. * invalid integers (e.g. 1234...a) or two integers instead of one
  327. * (e.g. 123...1). So lets not allow such large numbers. */
  328. if (len == TMPBUFLEN - 1)
  329. return -EINVAL;
  330. if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
  331. return -EINVAL;
  332. if (tr && (len < *size))
  333. *tr = *p;
  334. *buf += len;
  335. *size -= len;
  336. return 0;
  337. }
  338. /**
  339. * proc_put_long - converts an integer to a decimal ASCII formatted string
  340. *
  341. * @buf: the user buffer
  342. * @size: the size of the user buffer
  343. * @val: the integer to be converted
  344. * @neg: sign of the number, %TRUE for negative
  345. *
  346. * In case of success @buf and @size are updated with the amount of bytes
  347. * written.
  348. */
  349. static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
  350. {
  351. int len;
  352. char tmp[TMPBUFLEN], *p = tmp;
  353. sprintf(p, "%s%lu", neg ? "-" : "", val);
  354. len = strlen(tmp);
  355. if (len > *size)
  356. len = *size;
  357. memcpy(*buf, tmp, len);
  358. *size -= len;
  359. *buf += len;
  360. }
  361. #undef TMPBUFLEN
  362. static void proc_put_char(void **buf, size_t *size, char c)
  363. {
  364. if (*size) {
  365. char **buffer = (char **)buf;
  366. **buffer = c;
  367. (*size)--;
  368. (*buffer)++;
  369. *buf = *buffer;
  370. }
  371. }
  372. static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
  373. int *valp,
  374. int write, void *data)
  375. {
  376. if (write) {
  377. if (*negp) {
  378. if (*lvalp > (unsigned long) INT_MAX + 1)
  379. return -EINVAL;
  380. WRITE_ONCE(*valp, -*lvalp);
  381. } else {
  382. if (*lvalp > (unsigned long) INT_MAX)
  383. return -EINVAL;
  384. WRITE_ONCE(*valp, *lvalp);
  385. }
  386. } else {
  387. int val = READ_ONCE(*valp);
  388. if (val < 0) {
  389. *negp = true;
  390. *lvalp = -(unsigned long)val;
  391. } else {
  392. *negp = false;
  393. *lvalp = (unsigned long)val;
  394. }
  395. }
  396. return 0;
  397. }
  398. static int do_proc_douintvec_conv(unsigned long *lvalp,
  399. unsigned int *valp,
  400. int write, void *data)
  401. {
  402. if (write) {
  403. if (*lvalp > UINT_MAX)
  404. return -EINVAL;
  405. WRITE_ONCE(*valp, *lvalp);
  406. } else {
  407. unsigned int val = READ_ONCE(*valp);
  408. *lvalp = (unsigned long)val;
  409. }
  410. return 0;
  411. }
  412. static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
  413. static int __do_proc_dointvec(void *tbl_data, const struct ctl_table *table,
  414. int write, void *buffer,
  415. size_t *lenp, loff_t *ppos,
  416. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  417. int write, void *data),
  418. void *data)
  419. {
  420. int *i, vleft, first = 1, err = 0;
  421. size_t left;
  422. char *p;
  423. if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
  424. *lenp = 0;
  425. return 0;
  426. }
  427. i = (int *) tbl_data;
  428. vleft = table->maxlen / sizeof(*i);
  429. left = *lenp;
  430. if (!conv)
  431. conv = do_proc_dointvec_conv;
  432. if (write) {
  433. if (proc_first_pos_non_zero_ignore(ppos, table))
  434. goto out;
  435. if (left > PAGE_SIZE - 1)
  436. left = PAGE_SIZE - 1;
  437. p = buffer;
  438. }
  439. for (; left && vleft--; i++, first=0) {
  440. unsigned long lval;
  441. bool neg;
  442. if (write) {
  443. proc_skip_spaces(&p, &left);
  444. if (!left)
  445. break;
  446. err = proc_get_long(&p, &left, &lval, &neg,
  447. proc_wspace_sep,
  448. sizeof(proc_wspace_sep), NULL);
  449. if (err)
  450. break;
  451. if (conv(&neg, &lval, i, 1, data)) {
  452. err = -EINVAL;
  453. break;
  454. }
  455. } else {
  456. if (conv(&neg, &lval, i, 0, data)) {
  457. err = -EINVAL;
  458. break;
  459. }
  460. if (!first)
  461. proc_put_char(&buffer, &left, '\t');
  462. proc_put_long(&buffer, &left, lval, neg);
  463. }
  464. }
  465. if (!write && !first && left && !err)
  466. proc_put_char(&buffer, &left, '\n');
  467. if (write && !err && left)
  468. proc_skip_spaces(&p, &left);
  469. if (write && first)
  470. return err ? : -EINVAL;
  471. *lenp -= left;
  472. out:
  473. *ppos += *lenp;
  474. return err;
  475. }
  476. static int do_proc_dointvec(const struct ctl_table *table, int write,
  477. void *buffer, size_t *lenp, loff_t *ppos,
  478. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  479. int write, void *data),
  480. void *data)
  481. {
  482. return __do_proc_dointvec(table->data, table, write,
  483. buffer, lenp, ppos, conv, data);
  484. }
  485. static int do_proc_douintvec_w(unsigned int *tbl_data,
  486. const struct ctl_table *table,
  487. void *buffer,
  488. size_t *lenp, loff_t *ppos,
  489. int (*conv)(unsigned long *lvalp,
  490. unsigned int *valp,
  491. int write, void *data),
  492. void *data)
  493. {
  494. unsigned long lval;
  495. int err = 0;
  496. size_t left;
  497. bool neg;
  498. char *p = buffer;
  499. left = *lenp;
  500. if (proc_first_pos_non_zero_ignore(ppos, table))
  501. goto bail_early;
  502. if (left > PAGE_SIZE - 1)
  503. left = PAGE_SIZE - 1;
  504. proc_skip_spaces(&p, &left);
  505. if (!left) {
  506. err = -EINVAL;
  507. goto out_free;
  508. }
  509. err = proc_get_long(&p, &left, &lval, &neg,
  510. proc_wspace_sep,
  511. sizeof(proc_wspace_sep), NULL);
  512. if (err || neg) {
  513. err = -EINVAL;
  514. goto out_free;
  515. }
  516. if (conv(&lval, tbl_data, 1, data)) {
  517. err = -EINVAL;
  518. goto out_free;
  519. }
  520. if (!err && left)
  521. proc_skip_spaces(&p, &left);
  522. out_free:
  523. if (err)
  524. return -EINVAL;
  525. return 0;
  526. /* This is in keeping with old __do_proc_dointvec() */
  527. bail_early:
  528. *ppos += *lenp;
  529. return err;
  530. }
  531. static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
  532. size_t *lenp, loff_t *ppos,
  533. int (*conv)(unsigned long *lvalp,
  534. unsigned int *valp,
  535. int write, void *data),
  536. void *data)
  537. {
  538. unsigned long lval;
  539. int err = 0;
  540. size_t left;
  541. left = *lenp;
  542. if (conv(&lval, tbl_data, 0, data)) {
  543. err = -EINVAL;
  544. goto out;
  545. }
  546. proc_put_long(&buffer, &left, lval, false);
  547. if (!left)
  548. goto out;
  549. proc_put_char(&buffer, &left, '\n');
  550. out:
  551. *lenp -= left;
  552. *ppos += *lenp;
  553. return err;
  554. }
  555. static int __do_proc_douintvec(void *tbl_data, const struct ctl_table *table,
  556. int write, void *buffer,
  557. size_t *lenp, loff_t *ppos,
  558. int (*conv)(unsigned long *lvalp,
  559. unsigned int *valp,
  560. int write, void *data),
  561. void *data)
  562. {
  563. unsigned int *i, vleft;
  564. if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
  565. *lenp = 0;
  566. return 0;
  567. }
  568. i = (unsigned int *) tbl_data;
  569. vleft = table->maxlen / sizeof(*i);
  570. /*
  571. * Arrays are not supported, keep this simple. *Do not* add
  572. * support for them.
  573. */
  574. if (vleft != 1) {
  575. *lenp = 0;
  576. return -EINVAL;
  577. }
  578. if (!conv)
  579. conv = do_proc_douintvec_conv;
  580. if (write)
  581. return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
  582. conv, data);
  583. return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
  584. }
  585. int do_proc_douintvec(const struct ctl_table *table, int write,
  586. void *buffer, size_t *lenp, loff_t *ppos,
  587. int (*conv)(unsigned long *lvalp,
  588. unsigned int *valp,
  589. int write, void *data),
  590. void *data)
  591. {
  592. return __do_proc_douintvec(table->data, table, write,
  593. buffer, lenp, ppos, conv, data);
  594. }
  595. /**
  596. * proc_dobool - read/write a bool
  597. * @table: the sysctl table
  598. * @write: %TRUE if this is a write to the sysctl file
  599. * @buffer: the user buffer
  600. * @lenp: the size of the user buffer
  601. * @ppos: file position
  602. *
  603. * Reads/writes one integer value from/to the user buffer,
  604. * treated as an ASCII string.
  605. *
  606. * table->data must point to a bool variable and table->maxlen must
  607. * be sizeof(bool).
  608. *
  609. * Returns 0 on success.
  610. */
  611. int proc_dobool(const struct ctl_table *table, int write, void *buffer,
  612. size_t *lenp, loff_t *ppos)
  613. {
  614. struct ctl_table tmp;
  615. bool *data = table->data;
  616. int res, val;
  617. /* Do not support arrays yet. */
  618. if (table->maxlen != sizeof(bool))
  619. return -EINVAL;
  620. tmp = *table;
  621. tmp.maxlen = sizeof(val);
  622. tmp.data = &val;
  623. val = READ_ONCE(*data);
  624. res = proc_dointvec(&tmp, write, buffer, lenp, ppos);
  625. if (res)
  626. return res;
  627. if (write)
  628. WRITE_ONCE(*data, val);
  629. return 0;
  630. }
  631. /**
  632. * proc_dointvec - read a vector of integers
  633. * @table: the sysctl table
  634. * @write: %TRUE if this is a write to the sysctl file
  635. * @buffer: the user buffer
  636. * @lenp: the size of the user buffer
  637. * @ppos: file position
  638. *
  639. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  640. * values from/to the user buffer, treated as an ASCII string.
  641. *
  642. * Returns 0 on success.
  643. */
  644. int proc_dointvec(const struct ctl_table *table, int write, void *buffer,
  645. size_t *lenp, loff_t *ppos)
  646. {
  647. return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
  648. }
  649. /**
  650. * proc_douintvec - read a vector of unsigned integers
  651. * @table: the sysctl table
  652. * @write: %TRUE if this is a write to the sysctl file
  653. * @buffer: the user buffer
  654. * @lenp: the size of the user buffer
  655. * @ppos: file position
  656. *
  657. * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
  658. * values from/to the user buffer, treated as an ASCII string.
  659. *
  660. * Returns 0 on success.
  661. */
  662. int proc_douintvec(const struct ctl_table *table, int write, void *buffer,
  663. size_t *lenp, loff_t *ppos)
  664. {
  665. return do_proc_douintvec(table, write, buffer, lenp, ppos,
  666. do_proc_douintvec_conv, NULL);
  667. }
  668. /*
  669. * Taint values can only be increased
  670. * This means we can safely use a temporary.
  671. */
  672. static int proc_taint(const struct ctl_table *table, int write,
  673. void *buffer, size_t *lenp, loff_t *ppos)
  674. {
  675. struct ctl_table t;
  676. unsigned long tmptaint = get_taint();
  677. int err;
  678. if (write && !capable(CAP_SYS_ADMIN))
  679. return -EPERM;
  680. t = *table;
  681. t.data = &tmptaint;
  682. err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
  683. if (err < 0)
  684. return err;
  685. if (write) {
  686. int i;
  687. /*
  688. * If we are relying on panic_on_taint not producing
  689. * false positives due to userspace input, bail out
  690. * before setting the requested taint flags.
  691. */
  692. if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
  693. return -EINVAL;
  694. /*
  695. * Poor man's atomic or. Not worth adding a primitive
  696. * to everyone's atomic.h for this
  697. */
  698. for (i = 0; i < TAINT_FLAGS_COUNT; i++)
  699. if ((1UL << i) & tmptaint)
  700. add_taint(i, LOCKDEP_STILL_OK);
  701. }
  702. return err;
  703. }
  704. /**
  705. * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
  706. * @min: pointer to minimum allowable value
  707. * @max: pointer to maximum allowable value
  708. *
  709. * The do_proc_dointvec_minmax_conv_param structure provides the
  710. * minimum and maximum values for doing range checking for those sysctl
  711. * parameters that use the proc_dointvec_minmax() handler.
  712. */
  713. struct do_proc_dointvec_minmax_conv_param {
  714. int *min;
  715. int *max;
  716. };
  717. static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
  718. int *valp,
  719. int write, void *data)
  720. {
  721. int tmp, ret;
  722. struct do_proc_dointvec_minmax_conv_param *param = data;
  723. /*
  724. * If writing, first do so via a temporary local int so we can
  725. * bounds-check it before touching *valp.
  726. */
  727. int *ip = write ? &tmp : valp;
  728. ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
  729. if (ret)
  730. return ret;
  731. if (write) {
  732. if ((param->min && *param->min > tmp) ||
  733. (param->max && *param->max < tmp))
  734. return -EINVAL;
  735. WRITE_ONCE(*valp, tmp);
  736. }
  737. return 0;
  738. }
  739. /**
  740. * proc_dointvec_minmax - read a vector of integers with min/max values
  741. * @table: the sysctl table
  742. * @write: %TRUE if this is a write to the sysctl file
  743. * @buffer: the user buffer
  744. * @lenp: the size of the user buffer
  745. * @ppos: file position
  746. *
  747. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  748. * values from/to the user buffer, treated as an ASCII string.
  749. *
  750. * This routine will ensure the values are within the range specified by
  751. * table->extra1 (min) and table->extra2 (max).
  752. *
  753. * Returns 0 on success or -EINVAL on write when the range check fails.
  754. */
  755. int proc_dointvec_minmax(const struct ctl_table *table, int write,
  756. void *buffer, size_t *lenp, loff_t *ppos)
  757. {
  758. struct do_proc_dointvec_minmax_conv_param param = {
  759. .min = (int *) table->extra1,
  760. .max = (int *) table->extra2,
  761. };
  762. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  763. do_proc_dointvec_minmax_conv, &param);
  764. }
  765. /**
  766. * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
  767. * @min: pointer to minimum allowable value
  768. * @max: pointer to maximum allowable value
  769. *
  770. * The do_proc_douintvec_minmax_conv_param structure provides the
  771. * minimum and maximum values for doing range checking for those sysctl
  772. * parameters that use the proc_douintvec_minmax() handler.
  773. */
  774. struct do_proc_douintvec_minmax_conv_param {
  775. unsigned int *min;
  776. unsigned int *max;
  777. };
  778. static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
  779. unsigned int *valp,
  780. int write, void *data)
  781. {
  782. int ret;
  783. unsigned int tmp;
  784. struct do_proc_douintvec_minmax_conv_param *param = data;
  785. /* write via temporary local uint for bounds-checking */
  786. unsigned int *up = write ? &tmp : valp;
  787. ret = do_proc_douintvec_conv(lvalp, up, write, data);
  788. if (ret)
  789. return ret;
  790. if (write) {
  791. if ((param->min && *param->min > tmp) ||
  792. (param->max && *param->max < tmp))
  793. return -ERANGE;
  794. WRITE_ONCE(*valp, tmp);
  795. }
  796. return 0;
  797. }
  798. /**
  799. * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
  800. * @table: the sysctl table
  801. * @write: %TRUE if this is a write to the sysctl file
  802. * @buffer: the user buffer
  803. * @lenp: the size of the user buffer
  804. * @ppos: file position
  805. *
  806. * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
  807. * values from/to the user buffer, treated as an ASCII string. Negative
  808. * strings are not allowed.
  809. *
  810. * This routine will ensure the values are within the range specified by
  811. * table->extra1 (min) and table->extra2 (max). There is a final sanity
  812. * check for UINT_MAX to avoid having to support wrap around uses from
  813. * userspace.
  814. *
  815. * Returns 0 on success or -ERANGE on write when the range check fails.
  816. */
  817. int proc_douintvec_minmax(const struct ctl_table *table, int write,
  818. void *buffer, size_t *lenp, loff_t *ppos)
  819. {
  820. struct do_proc_douintvec_minmax_conv_param param = {
  821. .min = (unsigned int *) table->extra1,
  822. .max = (unsigned int *) table->extra2,
  823. };
  824. return do_proc_douintvec(table, write, buffer, lenp, ppos,
  825. do_proc_douintvec_minmax_conv, &param);
  826. }
  827. /**
  828. * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
  829. * @table: the sysctl table
  830. * @write: %TRUE if this is a write to the sysctl file
  831. * @buffer: the user buffer
  832. * @lenp: the size of the user buffer
  833. * @ppos: file position
  834. *
  835. * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
  836. * values from/to the user buffer, treated as an ASCII string. Negative
  837. * strings are not allowed.
  838. *
  839. * This routine will ensure the values are within the range specified by
  840. * table->extra1 (min) and table->extra2 (max).
  841. *
  842. * Returns 0 on success or an error on write when the range check fails.
  843. */
  844. int proc_dou8vec_minmax(const struct ctl_table *table, int write,
  845. void *buffer, size_t *lenp, loff_t *ppos)
  846. {
  847. struct ctl_table tmp;
  848. unsigned int min = 0, max = 255U, val;
  849. u8 *data = table->data;
  850. struct do_proc_douintvec_minmax_conv_param param = {
  851. .min = &min,
  852. .max = &max,
  853. };
  854. int res;
  855. /* Do not support arrays yet. */
  856. if (table->maxlen != sizeof(u8))
  857. return -EINVAL;
  858. if (table->extra1)
  859. min = *(unsigned int *) table->extra1;
  860. if (table->extra2)
  861. max = *(unsigned int *) table->extra2;
  862. tmp = *table;
  863. tmp.maxlen = sizeof(val);
  864. tmp.data = &val;
  865. val = READ_ONCE(*data);
  866. res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
  867. do_proc_douintvec_minmax_conv, &param);
  868. if (res)
  869. return res;
  870. if (write)
  871. WRITE_ONCE(*data, val);
  872. return 0;
  873. }
  874. EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
  875. #ifdef CONFIG_MAGIC_SYSRQ
  876. static int sysrq_sysctl_handler(const struct ctl_table *table, int write,
  877. void *buffer, size_t *lenp, loff_t *ppos)
  878. {
  879. int tmp, ret;
  880. tmp = sysrq_mask();
  881. ret = __do_proc_dointvec(&tmp, table, write, buffer,
  882. lenp, ppos, NULL, NULL);
  883. if (ret || !write)
  884. return ret;
  885. if (write)
  886. sysrq_toggle_support(tmp);
  887. return 0;
  888. }
  889. #endif
  890. static int __do_proc_doulongvec_minmax(void *data,
  891. const struct ctl_table *table, int write,
  892. void *buffer, size_t *lenp, loff_t *ppos,
  893. unsigned long convmul, unsigned long convdiv)
  894. {
  895. unsigned long *i, *min, *max;
  896. int vleft, first = 1, err = 0;
  897. size_t left;
  898. char *p;
  899. if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
  900. *lenp = 0;
  901. return 0;
  902. }
  903. i = data;
  904. min = table->extra1;
  905. max = table->extra2;
  906. vleft = table->maxlen / sizeof(unsigned long);
  907. left = *lenp;
  908. if (write) {
  909. if (proc_first_pos_non_zero_ignore(ppos, table))
  910. goto out;
  911. if (left > PAGE_SIZE - 1)
  912. left = PAGE_SIZE - 1;
  913. p = buffer;
  914. }
  915. for (; left && vleft--; i++, first = 0) {
  916. unsigned long val;
  917. if (write) {
  918. bool neg;
  919. proc_skip_spaces(&p, &left);
  920. if (!left)
  921. break;
  922. err = proc_get_long(&p, &left, &val, &neg,
  923. proc_wspace_sep,
  924. sizeof(proc_wspace_sep), NULL);
  925. if (err || neg) {
  926. err = -EINVAL;
  927. break;
  928. }
  929. val = convmul * val / convdiv;
  930. if ((min && val < *min) || (max && val > *max)) {
  931. err = -EINVAL;
  932. break;
  933. }
  934. WRITE_ONCE(*i, val);
  935. } else {
  936. val = convdiv * READ_ONCE(*i) / convmul;
  937. if (!first)
  938. proc_put_char(&buffer, &left, '\t');
  939. proc_put_long(&buffer, &left, val, false);
  940. }
  941. }
  942. if (!write && !first && left && !err)
  943. proc_put_char(&buffer, &left, '\n');
  944. if (write && !err)
  945. proc_skip_spaces(&p, &left);
  946. if (write && first)
  947. return err ? : -EINVAL;
  948. *lenp -= left;
  949. out:
  950. *ppos += *lenp;
  951. return err;
  952. }
  953. static int do_proc_doulongvec_minmax(const struct ctl_table *table, int write,
  954. void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
  955. unsigned long convdiv)
  956. {
  957. return __do_proc_doulongvec_minmax(table->data, table, write,
  958. buffer, lenp, ppos, convmul, convdiv);
  959. }
  960. /**
  961. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  962. * @table: the sysctl table
  963. * @write: %TRUE if this is a write to the sysctl file
  964. * @buffer: the user buffer
  965. * @lenp: the size of the user buffer
  966. * @ppos: file position
  967. *
  968. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  969. * values from/to the user buffer, treated as an ASCII string.
  970. *
  971. * This routine will ensure the values are within the range specified by
  972. * table->extra1 (min) and table->extra2 (max).
  973. *
  974. * Returns 0 on success.
  975. */
  976. int proc_doulongvec_minmax(const struct ctl_table *table, int write,
  977. void *buffer, size_t *lenp, loff_t *ppos)
  978. {
  979. return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
  980. }
  981. /**
  982. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  983. * @table: the sysctl table
  984. * @write: %TRUE if this is a write to the sysctl file
  985. * @buffer: the user buffer
  986. * @lenp: the size of the user buffer
  987. * @ppos: file position
  988. *
  989. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  990. * values from/to the user buffer, treated as an ASCII string. The values
  991. * are treated as milliseconds, and converted to jiffies when they are stored.
  992. *
  993. * This routine will ensure the values are within the range specified by
  994. * table->extra1 (min) and table->extra2 (max).
  995. *
  996. * Returns 0 on success.
  997. */
  998. int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int write,
  999. void *buffer, size_t *lenp, loff_t *ppos)
  1000. {
  1001. return do_proc_doulongvec_minmax(table, write, buffer,
  1002. lenp, ppos, HZ, 1000l);
  1003. }
  1004. static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
  1005. int *valp,
  1006. int write, void *data)
  1007. {
  1008. if (write) {
  1009. if (*lvalp > INT_MAX / HZ)
  1010. return 1;
  1011. if (*negp)
  1012. WRITE_ONCE(*valp, -*lvalp * HZ);
  1013. else
  1014. WRITE_ONCE(*valp, *lvalp * HZ);
  1015. } else {
  1016. int val = READ_ONCE(*valp);
  1017. unsigned long lval;
  1018. if (val < 0) {
  1019. *negp = true;
  1020. lval = -(unsigned long)val;
  1021. } else {
  1022. *negp = false;
  1023. lval = (unsigned long)val;
  1024. }
  1025. *lvalp = lval / HZ;
  1026. }
  1027. return 0;
  1028. }
  1029. static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
  1030. int *valp,
  1031. int write, void *data)
  1032. {
  1033. if (write) {
  1034. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  1035. return 1;
  1036. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  1037. } else {
  1038. int val = *valp;
  1039. unsigned long lval;
  1040. if (val < 0) {
  1041. *negp = true;
  1042. lval = -(unsigned long)val;
  1043. } else {
  1044. *negp = false;
  1045. lval = (unsigned long)val;
  1046. }
  1047. *lvalp = jiffies_to_clock_t(lval);
  1048. }
  1049. return 0;
  1050. }
  1051. static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
  1052. int *valp,
  1053. int write, void *data)
  1054. {
  1055. if (write) {
  1056. unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  1057. if (jif > INT_MAX)
  1058. return 1;
  1059. WRITE_ONCE(*valp, (int)jif);
  1060. } else {
  1061. int val = READ_ONCE(*valp);
  1062. unsigned long lval;
  1063. if (val < 0) {
  1064. *negp = true;
  1065. lval = -(unsigned long)val;
  1066. } else {
  1067. *negp = false;
  1068. lval = (unsigned long)val;
  1069. }
  1070. *lvalp = jiffies_to_msecs(lval);
  1071. }
  1072. return 0;
  1073. }
  1074. static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp,
  1075. int *valp, int write, void *data)
  1076. {
  1077. int tmp, ret;
  1078. struct do_proc_dointvec_minmax_conv_param *param = data;
  1079. /*
  1080. * If writing, first do so via a temporary local int so we can
  1081. * bounds-check it before touching *valp.
  1082. */
  1083. int *ip = write ? &tmp : valp;
  1084. ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data);
  1085. if (ret)
  1086. return ret;
  1087. if (write) {
  1088. if ((param->min && *param->min > tmp) ||
  1089. (param->max && *param->max < tmp))
  1090. return -EINVAL;
  1091. *valp = tmp;
  1092. }
  1093. return 0;
  1094. }
  1095. /**
  1096. * proc_dointvec_jiffies - read a vector of integers as seconds
  1097. * @table: the sysctl table
  1098. * @write: %TRUE if this is a write to the sysctl file
  1099. * @buffer: the user buffer
  1100. * @lenp: the size of the user buffer
  1101. * @ppos: file position
  1102. *
  1103. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1104. * values from/to the user buffer, treated as an ASCII string.
  1105. * The values read are assumed to be in seconds, and are converted into
  1106. * jiffies.
  1107. *
  1108. * Returns 0 on success.
  1109. */
  1110. int proc_dointvec_jiffies(const struct ctl_table *table, int write,
  1111. void *buffer, size_t *lenp, loff_t *ppos)
  1112. {
  1113. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  1114. do_proc_dointvec_jiffies_conv,NULL);
  1115. }
  1116. int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int write,
  1117. void *buffer, size_t *lenp, loff_t *ppos)
  1118. {
  1119. struct do_proc_dointvec_minmax_conv_param param = {
  1120. .min = (int *) table->extra1,
  1121. .max = (int *) table->extra2,
  1122. };
  1123. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  1124. do_proc_dointvec_ms_jiffies_minmax_conv, &param);
  1125. }
  1126. /**
  1127. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  1128. * @table: the sysctl table
  1129. * @write: %TRUE if this is a write to the sysctl file
  1130. * @buffer: the user buffer
  1131. * @lenp: the size of the user buffer
  1132. * @ppos: pointer to the file position
  1133. *
  1134. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1135. * values from/to the user buffer, treated as an ASCII string.
  1136. * The values read are assumed to be in 1/USER_HZ seconds, and
  1137. * are converted into jiffies.
  1138. *
  1139. * Returns 0 on success.
  1140. */
  1141. int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int write,
  1142. void *buffer, size_t *lenp, loff_t *ppos)
  1143. {
  1144. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  1145. do_proc_dointvec_userhz_jiffies_conv, NULL);
  1146. }
  1147. /**
  1148. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  1149. * @table: the sysctl table
  1150. * @write: %TRUE if this is a write to the sysctl file
  1151. * @buffer: the user buffer
  1152. * @lenp: the size of the user buffer
  1153. * @ppos: file position
  1154. * @ppos: the current position in the file
  1155. *
  1156. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1157. * values from/to the user buffer, treated as an ASCII string.
  1158. * The values read are assumed to be in 1/1000 seconds, and
  1159. * are converted into jiffies.
  1160. *
  1161. * Returns 0 on success.
  1162. */
  1163. int proc_dointvec_ms_jiffies(const struct ctl_table *table, int write, void *buffer,
  1164. size_t *lenp, loff_t *ppos)
  1165. {
  1166. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  1167. do_proc_dointvec_ms_jiffies_conv, NULL);
  1168. }
  1169. static int proc_do_cad_pid(const struct ctl_table *table, int write, void *buffer,
  1170. size_t *lenp, loff_t *ppos)
  1171. {
  1172. struct pid *new_pid;
  1173. pid_t tmp;
  1174. int r;
  1175. tmp = pid_vnr(cad_pid);
  1176. r = __do_proc_dointvec(&tmp, table, write, buffer,
  1177. lenp, ppos, NULL, NULL);
  1178. if (r || !write)
  1179. return r;
  1180. new_pid = find_get_pid(tmp);
  1181. if (!new_pid)
  1182. return -ESRCH;
  1183. put_pid(xchg(&cad_pid, new_pid));
  1184. return 0;
  1185. }
  1186. /**
  1187. * proc_do_large_bitmap - read/write from/to a large bitmap
  1188. * @table: the sysctl table
  1189. * @write: %TRUE if this is a write to the sysctl file
  1190. * @buffer: the user buffer
  1191. * @lenp: the size of the user buffer
  1192. * @ppos: file position
  1193. *
  1194. * The bitmap is stored at table->data and the bitmap length (in bits)
  1195. * in table->maxlen.
  1196. *
  1197. * We use a range comma separated format (e.g. 1,3-4,10-10) so that
  1198. * large bitmaps may be represented in a compact manner. Writing into
  1199. * the file will clear the bitmap then update it with the given input.
  1200. *
  1201. * Returns 0 on success.
  1202. */
  1203. int proc_do_large_bitmap(const struct ctl_table *table, int write,
  1204. void *buffer, size_t *lenp, loff_t *ppos)
  1205. {
  1206. int err = 0;
  1207. size_t left = *lenp;
  1208. unsigned long bitmap_len = table->maxlen;
  1209. unsigned long *bitmap = *(unsigned long **) table->data;
  1210. unsigned long *tmp_bitmap = NULL;
  1211. char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
  1212. if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
  1213. *lenp = 0;
  1214. return 0;
  1215. }
  1216. if (write) {
  1217. char *p = buffer;
  1218. size_t skipped = 0;
  1219. if (left > PAGE_SIZE - 1) {
  1220. left = PAGE_SIZE - 1;
  1221. /* How much of the buffer we'll skip this pass */
  1222. skipped = *lenp - left;
  1223. }
  1224. tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
  1225. if (!tmp_bitmap)
  1226. return -ENOMEM;
  1227. proc_skip_char(&p, &left, '\n');
  1228. while (!err && left) {
  1229. unsigned long val_a, val_b;
  1230. bool neg;
  1231. size_t saved_left;
  1232. /* In case we stop parsing mid-number, we can reset */
  1233. saved_left = left;
  1234. err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
  1235. sizeof(tr_a), &c);
  1236. /*
  1237. * If we consumed the entirety of a truncated buffer or
  1238. * only one char is left (may be a "-"), then stop here,
  1239. * reset, & come back for more.
  1240. */
  1241. if ((left <= 1) && skipped) {
  1242. left = saved_left;
  1243. break;
  1244. }
  1245. if (err)
  1246. break;
  1247. if (val_a >= bitmap_len || neg) {
  1248. err = -EINVAL;
  1249. break;
  1250. }
  1251. val_b = val_a;
  1252. if (left) {
  1253. p++;
  1254. left--;
  1255. }
  1256. if (c == '-') {
  1257. err = proc_get_long(&p, &left, &val_b,
  1258. &neg, tr_b, sizeof(tr_b),
  1259. &c);
  1260. /*
  1261. * If we consumed all of a truncated buffer or
  1262. * then stop here, reset, & come back for more.
  1263. */
  1264. if (!left && skipped) {
  1265. left = saved_left;
  1266. break;
  1267. }
  1268. if (err)
  1269. break;
  1270. if (val_b >= bitmap_len || neg ||
  1271. val_a > val_b) {
  1272. err = -EINVAL;
  1273. break;
  1274. }
  1275. if (left) {
  1276. p++;
  1277. left--;
  1278. }
  1279. }
  1280. bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
  1281. proc_skip_char(&p, &left, '\n');
  1282. }
  1283. left += skipped;
  1284. } else {
  1285. unsigned long bit_a, bit_b = 0;
  1286. bool first = 1;
  1287. while (left) {
  1288. bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
  1289. if (bit_a >= bitmap_len)
  1290. break;
  1291. bit_b = find_next_zero_bit(bitmap, bitmap_len,
  1292. bit_a + 1) - 1;
  1293. if (!first)
  1294. proc_put_char(&buffer, &left, ',');
  1295. proc_put_long(&buffer, &left, bit_a, false);
  1296. if (bit_a != bit_b) {
  1297. proc_put_char(&buffer, &left, '-');
  1298. proc_put_long(&buffer, &left, bit_b, false);
  1299. }
  1300. first = 0; bit_b++;
  1301. }
  1302. proc_put_char(&buffer, &left, '\n');
  1303. }
  1304. if (!err) {
  1305. if (write) {
  1306. if (*ppos)
  1307. bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
  1308. else
  1309. bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
  1310. }
  1311. *lenp -= left;
  1312. *ppos += *lenp;
  1313. }
  1314. bitmap_free(tmp_bitmap);
  1315. return err;
  1316. }
  1317. #else /* CONFIG_PROC_SYSCTL */
  1318. int proc_dostring(const struct ctl_table *table, int write,
  1319. void *buffer, size_t *lenp, loff_t *ppos)
  1320. {
  1321. return -ENOSYS;
  1322. }
  1323. int proc_dobool(const struct ctl_table *table, int write,
  1324. void *buffer, size_t *lenp, loff_t *ppos)
  1325. {
  1326. return -ENOSYS;
  1327. }
  1328. int proc_dointvec(const struct ctl_table *table, int write,
  1329. void *buffer, size_t *lenp, loff_t *ppos)
  1330. {
  1331. return -ENOSYS;
  1332. }
  1333. int proc_douintvec(const struct ctl_table *table, int write,
  1334. void *buffer, size_t *lenp, loff_t *ppos)
  1335. {
  1336. return -ENOSYS;
  1337. }
  1338. int proc_dointvec_minmax(const struct ctl_table *table, int write,
  1339. void *buffer, size_t *lenp, loff_t *ppos)
  1340. {
  1341. return -ENOSYS;
  1342. }
  1343. int proc_douintvec_minmax(const struct ctl_table *table, int write,
  1344. void *buffer, size_t *lenp, loff_t *ppos)
  1345. {
  1346. return -ENOSYS;
  1347. }
  1348. int proc_dou8vec_minmax(const struct ctl_table *table, int write,
  1349. void *buffer, size_t *lenp, loff_t *ppos)
  1350. {
  1351. return -ENOSYS;
  1352. }
  1353. int proc_dointvec_jiffies(const struct ctl_table *table, int write,
  1354. void *buffer, size_t *lenp, loff_t *ppos)
  1355. {
  1356. return -ENOSYS;
  1357. }
  1358. int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int write,
  1359. void *buffer, size_t *lenp, loff_t *ppos)
  1360. {
  1361. return -ENOSYS;
  1362. }
  1363. int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int write,
  1364. void *buffer, size_t *lenp, loff_t *ppos)
  1365. {
  1366. return -ENOSYS;
  1367. }
  1368. int proc_dointvec_ms_jiffies(const struct ctl_table *table, int write,
  1369. void *buffer, size_t *lenp, loff_t *ppos)
  1370. {
  1371. return -ENOSYS;
  1372. }
  1373. int proc_doulongvec_minmax(const struct ctl_table *table, int write,
  1374. void *buffer, size_t *lenp, loff_t *ppos)
  1375. {
  1376. return -ENOSYS;
  1377. }
  1378. int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int write,
  1379. void *buffer, size_t *lenp, loff_t *ppos)
  1380. {
  1381. return -ENOSYS;
  1382. }
  1383. int proc_do_large_bitmap(const struct ctl_table *table, int write,
  1384. void *buffer, size_t *lenp, loff_t *ppos)
  1385. {
  1386. return -ENOSYS;
  1387. }
  1388. #endif /* CONFIG_PROC_SYSCTL */
  1389. #if defined(CONFIG_SYSCTL)
  1390. int proc_do_static_key(const struct ctl_table *table, int write,
  1391. void *buffer, size_t *lenp, loff_t *ppos)
  1392. {
  1393. struct static_key *key = (struct static_key *)table->data;
  1394. static DEFINE_MUTEX(static_key_mutex);
  1395. int val, ret;
  1396. struct ctl_table tmp = {
  1397. .data = &val,
  1398. .maxlen = sizeof(val),
  1399. .mode = table->mode,
  1400. .extra1 = SYSCTL_ZERO,
  1401. .extra2 = SYSCTL_ONE,
  1402. };
  1403. if (write && !capable(CAP_SYS_ADMIN))
  1404. return -EPERM;
  1405. mutex_lock(&static_key_mutex);
  1406. val = static_key_enabled(key);
  1407. ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
  1408. if (write && !ret) {
  1409. if (val)
  1410. static_key_enable(key);
  1411. else
  1412. static_key_disable(key);
  1413. }
  1414. mutex_unlock(&static_key_mutex);
  1415. return ret;
  1416. }
  1417. static struct ctl_table kern_table[] = {
  1418. {
  1419. .procname = "panic",
  1420. .data = &panic_timeout,
  1421. .maxlen = sizeof(int),
  1422. .mode = 0644,
  1423. .proc_handler = proc_dointvec,
  1424. },
  1425. #ifdef CONFIG_PROC_SYSCTL
  1426. {
  1427. .procname = "tainted",
  1428. .maxlen = sizeof(long),
  1429. .mode = 0644,
  1430. .proc_handler = proc_taint,
  1431. },
  1432. {
  1433. .procname = "sysctl_writes_strict",
  1434. .data = &sysctl_writes_strict,
  1435. .maxlen = sizeof(int),
  1436. .mode = 0644,
  1437. .proc_handler = proc_dointvec_minmax,
  1438. .extra1 = SYSCTL_NEG_ONE,
  1439. .extra2 = SYSCTL_ONE,
  1440. },
  1441. #endif
  1442. {
  1443. .procname = "print-fatal-signals",
  1444. .data = &print_fatal_signals,
  1445. .maxlen = sizeof(int),
  1446. .mode = 0644,
  1447. .proc_handler = proc_dointvec,
  1448. },
  1449. #ifdef CONFIG_SPARC
  1450. {
  1451. .procname = "reboot-cmd",
  1452. .data = reboot_command,
  1453. .maxlen = 256,
  1454. .mode = 0644,
  1455. .proc_handler = proc_dostring,
  1456. },
  1457. {
  1458. .procname = "stop-a",
  1459. .data = &stop_a_enabled,
  1460. .maxlen = sizeof (int),
  1461. .mode = 0644,
  1462. .proc_handler = proc_dointvec,
  1463. },
  1464. {
  1465. .procname = "scons-poweroff",
  1466. .data = &scons_pwroff,
  1467. .maxlen = sizeof (int),
  1468. .mode = 0644,
  1469. .proc_handler = proc_dointvec,
  1470. },
  1471. #endif
  1472. #ifdef CONFIG_SPARC64
  1473. {
  1474. .procname = "tsb-ratio",
  1475. .data = &sysctl_tsb_ratio,
  1476. .maxlen = sizeof (int),
  1477. .mode = 0644,
  1478. .proc_handler = proc_dointvec,
  1479. },
  1480. #endif
  1481. #ifdef CONFIG_PARISC
  1482. {
  1483. .procname = "soft-power",
  1484. .data = &pwrsw_enabled,
  1485. .maxlen = sizeof (int),
  1486. .mode = 0644,
  1487. .proc_handler = proc_dointvec,
  1488. },
  1489. #endif
  1490. #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
  1491. {
  1492. .procname = "unaligned-trap",
  1493. .data = &unaligned_enabled,
  1494. .maxlen = sizeof (int),
  1495. .mode = 0644,
  1496. .proc_handler = proc_dointvec,
  1497. },
  1498. #endif
  1499. #ifdef CONFIG_STACK_TRACER
  1500. {
  1501. .procname = "stack_tracer_enabled",
  1502. .data = &stack_tracer_enabled,
  1503. .maxlen = sizeof(int),
  1504. .mode = 0644,
  1505. .proc_handler = stack_trace_sysctl,
  1506. },
  1507. #endif
  1508. #ifdef CONFIG_TRACING
  1509. {
  1510. .procname = "ftrace_dump_on_oops",
  1511. .data = &ftrace_dump_on_oops,
  1512. .maxlen = MAX_TRACER_SIZE,
  1513. .mode = 0644,
  1514. .proc_handler = proc_dostring,
  1515. },
  1516. {
  1517. .procname = "traceoff_on_warning",
  1518. .data = &__disable_trace_on_warning,
  1519. .maxlen = sizeof(__disable_trace_on_warning),
  1520. .mode = 0644,
  1521. .proc_handler = proc_dointvec,
  1522. },
  1523. {
  1524. .procname = "tracepoint_printk",
  1525. .data = &tracepoint_printk,
  1526. .maxlen = sizeof(tracepoint_printk),
  1527. .mode = 0644,
  1528. .proc_handler = tracepoint_printk_sysctl,
  1529. },
  1530. #endif
  1531. #ifdef CONFIG_MODULES
  1532. {
  1533. .procname = "modprobe",
  1534. .data = &modprobe_path,
  1535. .maxlen = KMOD_PATH_LEN,
  1536. .mode = 0644,
  1537. .proc_handler = proc_dostring,
  1538. },
  1539. {
  1540. .procname = "modules_disabled",
  1541. .data = &modules_disabled,
  1542. .maxlen = sizeof(int),
  1543. .mode = 0644,
  1544. /* only handle a transition from default "0" to "1" */
  1545. .proc_handler = proc_dointvec_minmax,
  1546. .extra1 = SYSCTL_ONE,
  1547. .extra2 = SYSCTL_ONE,
  1548. },
  1549. #endif
  1550. #ifdef CONFIG_UEVENT_HELPER
  1551. {
  1552. .procname = "hotplug",
  1553. .data = &uevent_helper,
  1554. .maxlen = UEVENT_HELPER_PATH_LEN,
  1555. .mode = 0644,
  1556. .proc_handler = proc_dostring,
  1557. },
  1558. #endif
  1559. #ifdef CONFIG_MAGIC_SYSRQ
  1560. {
  1561. .procname = "sysrq",
  1562. .data = NULL,
  1563. .maxlen = sizeof (int),
  1564. .mode = 0644,
  1565. .proc_handler = sysrq_sysctl_handler,
  1566. },
  1567. #endif
  1568. #ifdef CONFIG_PROC_SYSCTL
  1569. {
  1570. .procname = "cad_pid",
  1571. .data = NULL,
  1572. .maxlen = sizeof (int),
  1573. .mode = 0600,
  1574. .proc_handler = proc_do_cad_pid,
  1575. },
  1576. #endif
  1577. {
  1578. .procname = "threads-max",
  1579. .data = NULL,
  1580. .maxlen = sizeof(int),
  1581. .mode = 0644,
  1582. .proc_handler = sysctl_max_threads,
  1583. },
  1584. {
  1585. .procname = "overflowuid",
  1586. .data = &overflowuid,
  1587. .maxlen = sizeof(int),
  1588. .mode = 0644,
  1589. .proc_handler = proc_dointvec_minmax,
  1590. .extra1 = SYSCTL_ZERO,
  1591. .extra2 = SYSCTL_MAXOLDUID,
  1592. },
  1593. {
  1594. .procname = "overflowgid",
  1595. .data = &overflowgid,
  1596. .maxlen = sizeof(int),
  1597. .mode = 0644,
  1598. .proc_handler = proc_dointvec_minmax,
  1599. .extra1 = SYSCTL_ZERO,
  1600. .extra2 = SYSCTL_MAXOLDUID,
  1601. },
  1602. #ifdef CONFIG_S390
  1603. {
  1604. .procname = "userprocess_debug",
  1605. .data = &show_unhandled_signals,
  1606. .maxlen = sizeof(int),
  1607. .mode = 0644,
  1608. .proc_handler = proc_dointvec,
  1609. },
  1610. #endif
  1611. {
  1612. .procname = "pid_max",
  1613. .data = &pid_max,
  1614. .maxlen = sizeof (int),
  1615. .mode = 0644,
  1616. .proc_handler = proc_dointvec_minmax,
  1617. .extra1 = &pid_max_min,
  1618. .extra2 = &pid_max_max,
  1619. },
  1620. {
  1621. .procname = "panic_on_oops",
  1622. .data = &panic_on_oops,
  1623. .maxlen = sizeof(int),
  1624. .mode = 0644,
  1625. .proc_handler = proc_dointvec,
  1626. },
  1627. {
  1628. .procname = "panic_print",
  1629. .data = &panic_print,
  1630. .maxlen = sizeof(unsigned long),
  1631. .mode = 0644,
  1632. .proc_handler = proc_doulongvec_minmax,
  1633. },
  1634. {
  1635. .procname = "ngroups_max",
  1636. .data = (void *)&ngroups_max,
  1637. .maxlen = sizeof (int),
  1638. .mode = 0444,
  1639. .proc_handler = proc_dointvec,
  1640. },
  1641. {
  1642. .procname = "cap_last_cap",
  1643. .data = (void *)&cap_last_cap,
  1644. .maxlen = sizeof(int),
  1645. .mode = 0444,
  1646. .proc_handler = proc_dointvec,
  1647. },
  1648. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
  1649. {
  1650. .procname = "unknown_nmi_panic",
  1651. .data = &unknown_nmi_panic,
  1652. .maxlen = sizeof (int),
  1653. .mode = 0644,
  1654. .proc_handler = proc_dointvec,
  1655. },
  1656. #endif
  1657. #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
  1658. defined(CONFIG_DEBUG_STACKOVERFLOW)
  1659. {
  1660. .procname = "panic_on_stackoverflow",
  1661. .data = &sysctl_panic_on_stackoverflow,
  1662. .maxlen = sizeof(int),
  1663. .mode = 0644,
  1664. .proc_handler = proc_dointvec,
  1665. },
  1666. #endif
  1667. #if defined(CONFIG_X86)
  1668. {
  1669. .procname = "panic_on_unrecovered_nmi",
  1670. .data = &panic_on_unrecovered_nmi,
  1671. .maxlen = sizeof(int),
  1672. .mode = 0644,
  1673. .proc_handler = proc_dointvec,
  1674. },
  1675. {
  1676. .procname = "panic_on_io_nmi",
  1677. .data = &panic_on_io_nmi,
  1678. .maxlen = sizeof(int),
  1679. .mode = 0644,
  1680. .proc_handler = proc_dointvec,
  1681. },
  1682. {
  1683. .procname = "bootloader_type",
  1684. .data = &bootloader_type,
  1685. .maxlen = sizeof (int),
  1686. .mode = 0444,
  1687. .proc_handler = proc_dointvec,
  1688. },
  1689. {
  1690. .procname = "bootloader_version",
  1691. .data = &bootloader_version,
  1692. .maxlen = sizeof (int),
  1693. .mode = 0444,
  1694. .proc_handler = proc_dointvec,
  1695. },
  1696. {
  1697. .procname = "io_delay_type",
  1698. .data = &io_delay_type,
  1699. .maxlen = sizeof(int),
  1700. .mode = 0644,
  1701. .proc_handler = proc_dointvec,
  1702. },
  1703. #endif
  1704. #if defined(CONFIG_MMU)
  1705. {
  1706. .procname = "randomize_va_space",
  1707. .data = &randomize_va_space,
  1708. .maxlen = sizeof(int),
  1709. .mode = 0644,
  1710. .proc_handler = proc_dointvec,
  1711. },
  1712. #endif
  1713. #if defined(CONFIG_S390) && defined(CONFIG_SMP)
  1714. {
  1715. .procname = "spin_retry",
  1716. .data = &spin_retry,
  1717. .maxlen = sizeof (int),
  1718. .mode = 0644,
  1719. .proc_handler = proc_dointvec,
  1720. },
  1721. #endif
  1722. #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
  1723. {
  1724. .procname = "acpi_video_flags",
  1725. .data = &acpi_realmode_flags,
  1726. .maxlen = sizeof (unsigned long),
  1727. .mode = 0644,
  1728. .proc_handler = proc_doulongvec_minmax,
  1729. },
  1730. #endif
  1731. #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
  1732. {
  1733. .procname = "ignore-unaligned-usertrap",
  1734. .data = &no_unaligned_warning,
  1735. .maxlen = sizeof (int),
  1736. .mode = 0644,
  1737. .proc_handler = proc_dointvec,
  1738. },
  1739. #endif
  1740. #ifdef CONFIG_RT_MUTEXES
  1741. {
  1742. .procname = "max_lock_depth",
  1743. .data = &max_lock_depth,
  1744. .maxlen = sizeof(int),
  1745. .mode = 0644,
  1746. .proc_handler = proc_dointvec,
  1747. },
  1748. #endif
  1749. #ifdef CONFIG_PERF_EVENTS
  1750. /*
  1751. * User-space scripts rely on the existence of this file
  1752. * as a feature check for perf_events being enabled.
  1753. *
  1754. * So it's an ABI, do not remove!
  1755. */
  1756. {
  1757. .procname = "perf_event_paranoid",
  1758. .data = &sysctl_perf_event_paranoid,
  1759. .maxlen = sizeof(sysctl_perf_event_paranoid),
  1760. .mode = 0644,
  1761. .proc_handler = proc_dointvec,
  1762. },
  1763. {
  1764. .procname = "perf_event_mlock_kb",
  1765. .data = &sysctl_perf_event_mlock,
  1766. .maxlen = sizeof(sysctl_perf_event_mlock),
  1767. .mode = 0644,
  1768. .proc_handler = proc_dointvec,
  1769. },
  1770. {
  1771. .procname = "perf_event_max_sample_rate",
  1772. .data = &sysctl_perf_event_sample_rate,
  1773. .maxlen = sizeof(sysctl_perf_event_sample_rate),
  1774. .mode = 0644,
  1775. .proc_handler = perf_event_max_sample_rate_handler,
  1776. .extra1 = SYSCTL_ONE,
  1777. },
  1778. {
  1779. .procname = "perf_cpu_time_max_percent",
  1780. .data = &sysctl_perf_cpu_time_max_percent,
  1781. .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
  1782. .mode = 0644,
  1783. .proc_handler = perf_cpu_time_max_percent_handler,
  1784. .extra1 = SYSCTL_ZERO,
  1785. .extra2 = SYSCTL_ONE_HUNDRED,
  1786. },
  1787. {
  1788. .procname = "perf_event_max_stack",
  1789. .data = &sysctl_perf_event_max_stack,
  1790. .maxlen = sizeof(sysctl_perf_event_max_stack),
  1791. .mode = 0644,
  1792. .proc_handler = perf_event_max_stack_handler,
  1793. .extra1 = SYSCTL_ZERO,
  1794. .extra2 = (void *)&six_hundred_forty_kb,
  1795. },
  1796. {
  1797. .procname = "perf_event_max_contexts_per_stack",
  1798. .data = &sysctl_perf_event_max_contexts_per_stack,
  1799. .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
  1800. .mode = 0644,
  1801. .proc_handler = perf_event_max_stack_handler,
  1802. .extra1 = SYSCTL_ZERO,
  1803. .extra2 = SYSCTL_ONE_THOUSAND,
  1804. },
  1805. #endif
  1806. {
  1807. .procname = "panic_on_warn",
  1808. .data = &panic_on_warn,
  1809. .maxlen = sizeof(int),
  1810. .mode = 0644,
  1811. .proc_handler = proc_dointvec_minmax,
  1812. .extra1 = SYSCTL_ZERO,
  1813. .extra2 = SYSCTL_ONE,
  1814. },
  1815. #ifdef CONFIG_TREE_RCU
  1816. {
  1817. .procname = "panic_on_rcu_stall",
  1818. .data = &sysctl_panic_on_rcu_stall,
  1819. .maxlen = sizeof(sysctl_panic_on_rcu_stall),
  1820. .mode = 0644,
  1821. .proc_handler = proc_dointvec_minmax,
  1822. .extra1 = SYSCTL_ZERO,
  1823. .extra2 = SYSCTL_ONE,
  1824. },
  1825. {
  1826. .procname = "max_rcu_stall_to_panic",
  1827. .data = &sysctl_max_rcu_stall_to_panic,
  1828. .maxlen = sizeof(sysctl_max_rcu_stall_to_panic),
  1829. .mode = 0644,
  1830. .proc_handler = proc_dointvec_minmax,
  1831. .extra1 = SYSCTL_ONE,
  1832. .extra2 = SYSCTL_INT_MAX,
  1833. },
  1834. #endif
  1835. };
  1836. static struct ctl_table vm_table[] = {
  1837. {
  1838. .procname = "overcommit_memory",
  1839. .data = &sysctl_overcommit_memory,
  1840. .maxlen = sizeof(sysctl_overcommit_memory),
  1841. .mode = 0644,
  1842. .proc_handler = overcommit_policy_handler,
  1843. .extra1 = SYSCTL_ZERO,
  1844. .extra2 = SYSCTL_TWO,
  1845. },
  1846. {
  1847. .procname = "overcommit_ratio",
  1848. .data = &sysctl_overcommit_ratio,
  1849. .maxlen = sizeof(sysctl_overcommit_ratio),
  1850. .mode = 0644,
  1851. .proc_handler = overcommit_ratio_handler,
  1852. },
  1853. {
  1854. .procname = "overcommit_kbytes",
  1855. .data = &sysctl_overcommit_kbytes,
  1856. .maxlen = sizeof(sysctl_overcommit_kbytes),
  1857. .mode = 0644,
  1858. .proc_handler = overcommit_kbytes_handler,
  1859. },
  1860. {
  1861. .procname = "page-cluster",
  1862. .data = &page_cluster,
  1863. .maxlen = sizeof(int),
  1864. .mode = 0644,
  1865. .proc_handler = proc_dointvec_minmax,
  1866. .extra1 = SYSCTL_ZERO,
  1867. .extra2 = (void *)&page_cluster_max,
  1868. },
  1869. {
  1870. .procname = "dirtytime_expire_seconds",
  1871. .data = &dirtytime_expire_interval,
  1872. .maxlen = sizeof(dirtytime_expire_interval),
  1873. .mode = 0644,
  1874. .proc_handler = dirtytime_interval_handler,
  1875. .extra1 = SYSCTL_ZERO,
  1876. },
  1877. {
  1878. .procname = "swappiness",
  1879. .data = &vm_swappiness,
  1880. .maxlen = sizeof(vm_swappiness),
  1881. .mode = 0644,
  1882. .proc_handler = proc_dointvec_minmax,
  1883. .extra1 = SYSCTL_ZERO,
  1884. .extra2 = SYSCTL_TWO_HUNDRED,
  1885. },
  1886. #ifdef CONFIG_NUMA
  1887. {
  1888. .procname = "numa_stat",
  1889. .data = &sysctl_vm_numa_stat,
  1890. .maxlen = sizeof(int),
  1891. .mode = 0644,
  1892. .proc_handler = sysctl_vm_numa_stat_handler,
  1893. .extra1 = SYSCTL_ZERO,
  1894. .extra2 = SYSCTL_ONE,
  1895. },
  1896. #endif
  1897. {
  1898. .procname = "drop_caches",
  1899. .data = &sysctl_drop_caches,
  1900. .maxlen = sizeof(int),
  1901. .mode = 0200,
  1902. .proc_handler = drop_caches_sysctl_handler,
  1903. .extra1 = SYSCTL_ONE,
  1904. .extra2 = SYSCTL_FOUR,
  1905. },
  1906. {
  1907. .procname = "page_lock_unfairness",
  1908. .data = &sysctl_page_lock_unfairness,
  1909. .maxlen = sizeof(sysctl_page_lock_unfairness),
  1910. .mode = 0644,
  1911. .proc_handler = proc_dointvec_minmax,
  1912. .extra1 = SYSCTL_ZERO,
  1913. },
  1914. #ifdef CONFIG_MMU
  1915. {
  1916. .procname = "max_map_count",
  1917. .data = &sysctl_max_map_count,
  1918. .maxlen = sizeof(sysctl_max_map_count),
  1919. .mode = 0644,
  1920. .proc_handler = proc_dointvec_minmax,
  1921. .extra1 = SYSCTL_ZERO,
  1922. },
  1923. #else
  1924. {
  1925. .procname = "nr_trim_pages",
  1926. .data = &sysctl_nr_trim_pages,
  1927. .maxlen = sizeof(sysctl_nr_trim_pages),
  1928. .mode = 0644,
  1929. .proc_handler = proc_dointvec_minmax,
  1930. .extra1 = SYSCTL_ZERO,
  1931. },
  1932. #endif
  1933. {
  1934. .procname = "vfs_cache_pressure",
  1935. .data = &sysctl_vfs_cache_pressure,
  1936. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  1937. .mode = 0644,
  1938. .proc_handler = proc_dointvec_minmax,
  1939. .extra1 = SYSCTL_ZERO,
  1940. },
  1941. #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
  1942. defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
  1943. {
  1944. .procname = "legacy_va_layout",
  1945. .data = &sysctl_legacy_va_layout,
  1946. .maxlen = sizeof(sysctl_legacy_va_layout),
  1947. .mode = 0644,
  1948. .proc_handler = proc_dointvec_minmax,
  1949. .extra1 = SYSCTL_ZERO,
  1950. },
  1951. #endif
  1952. #ifdef CONFIG_NUMA
  1953. {
  1954. .procname = "zone_reclaim_mode",
  1955. .data = &node_reclaim_mode,
  1956. .maxlen = sizeof(node_reclaim_mode),
  1957. .mode = 0644,
  1958. .proc_handler = proc_dointvec_minmax,
  1959. .extra1 = SYSCTL_ZERO,
  1960. },
  1961. #endif
  1962. #ifdef CONFIG_SMP
  1963. {
  1964. .procname = "stat_interval",
  1965. .data = &sysctl_stat_interval,
  1966. .maxlen = sizeof(sysctl_stat_interval),
  1967. .mode = 0644,
  1968. .proc_handler = proc_dointvec_jiffies,
  1969. },
  1970. {
  1971. .procname = "stat_refresh",
  1972. .data = NULL,
  1973. .maxlen = 0,
  1974. .mode = 0600,
  1975. .proc_handler = vmstat_refresh,
  1976. },
  1977. #endif
  1978. #ifdef CONFIG_MMU
  1979. {
  1980. .procname = "mmap_min_addr",
  1981. .data = &dac_mmap_min_addr,
  1982. .maxlen = sizeof(unsigned long),
  1983. .mode = 0644,
  1984. .proc_handler = mmap_min_addr_handler,
  1985. },
  1986. #endif
  1987. #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
  1988. (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
  1989. {
  1990. .procname = "vdso_enabled",
  1991. #ifdef CONFIG_X86_32
  1992. .data = &vdso32_enabled,
  1993. .maxlen = sizeof(vdso32_enabled),
  1994. #else
  1995. .data = &vdso_enabled,
  1996. .maxlen = sizeof(vdso_enabled),
  1997. #endif
  1998. .mode = 0644,
  1999. .proc_handler = proc_dointvec,
  2000. .extra1 = SYSCTL_ZERO,
  2001. },
  2002. #endif
  2003. {
  2004. .procname = "user_reserve_kbytes",
  2005. .data = &sysctl_user_reserve_kbytes,
  2006. .maxlen = sizeof(sysctl_user_reserve_kbytes),
  2007. .mode = 0644,
  2008. .proc_handler = proc_doulongvec_minmax,
  2009. },
  2010. {
  2011. .procname = "admin_reserve_kbytes",
  2012. .data = &sysctl_admin_reserve_kbytes,
  2013. .maxlen = sizeof(sysctl_admin_reserve_kbytes),
  2014. .mode = 0644,
  2015. .proc_handler = proc_doulongvec_minmax,
  2016. },
  2017. #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
  2018. {
  2019. .procname = "mmap_rnd_bits",
  2020. .data = &mmap_rnd_bits,
  2021. .maxlen = sizeof(mmap_rnd_bits),
  2022. .mode = 0600,
  2023. .proc_handler = proc_dointvec_minmax,
  2024. .extra1 = (void *)&mmap_rnd_bits_min,
  2025. .extra2 = (void *)&mmap_rnd_bits_max,
  2026. },
  2027. #endif
  2028. #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
  2029. {
  2030. .procname = "mmap_rnd_compat_bits",
  2031. .data = &mmap_rnd_compat_bits,
  2032. .maxlen = sizeof(mmap_rnd_compat_bits),
  2033. .mode = 0600,
  2034. .proc_handler = proc_dointvec_minmax,
  2035. .extra1 = (void *)&mmap_rnd_compat_bits_min,
  2036. .extra2 = (void *)&mmap_rnd_compat_bits_max,
  2037. },
  2038. #endif
  2039. };
  2040. int __init sysctl_init_bases(void)
  2041. {
  2042. register_sysctl_init("kernel", kern_table);
  2043. register_sysctl_init("vm", vm_table);
  2044. return 0;
  2045. }
  2046. #endif /* CONFIG_SYSCTL */
  2047. /*
  2048. * No sense putting this after each symbol definition, twice,
  2049. * exception granted :-)
  2050. */
  2051. EXPORT_SYMBOL(proc_dobool);
  2052. EXPORT_SYMBOL(proc_dointvec);
  2053. EXPORT_SYMBOL(proc_douintvec);
  2054. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2055. EXPORT_SYMBOL(proc_dointvec_minmax);
  2056. EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
  2057. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2058. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2059. EXPORT_SYMBOL(proc_dostring);
  2060. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2061. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2062. EXPORT_SYMBOL(proc_do_large_bitmap);