sysctl.c 60 KB

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