sysctl.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522
  1. /*
  2. * sysctl.c: General linux system control interface
  3. *
  4. * Begun 24 March 1995, Stephen Tweedie
  5. * Added /proc support, Dec 1995
  6. * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
  7. * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
  8. * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
  9. * Dynamic registration fixes, Stephen Tweedie.
  10. * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
  11. * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
  12. * Horn.
  13. * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
  14. * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
  15. * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
  16. * Wendling.
  17. * The list_for_each() macro wasn't appropriate for the sysctl loop.
  18. * Removed it and replaced it with older style, 03/23/00, Bill Wendling
  19. */
  20. #include <linux/module.h>
  21. #include <linux/mm.h>
  22. #include <linux/swap.h>
  23. #include <linux/slab.h>
  24. #include <linux/sysctl.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/capability.h>
  27. #include <linux/ctype.h>
  28. #include <linux/utsname.h>
  29. #include <linux/capability.h>
  30. #include <linux/smp_lock.h>
  31. #include <linux/fs.h>
  32. #include <linux/init.h>
  33. #include <linux/kernel.h>
  34. #include <linux/kobject.h>
  35. #include <linux/net.h>
  36. #include <linux/sysrq.h>
  37. #include <linux/highuid.h>
  38. #include <linux/writeback.h>
  39. #include <linux/hugetlb.h>
  40. #include <linux/security.h>
  41. #include <linux/initrd.h>
  42. #include <linux/times.h>
  43. #include <linux/limits.h>
  44. #include <linux/dcache.h>
  45. #include <linux/syscalls.h>
  46. #include <linux/nfs_fs.h>
  47. #include <linux/acpi.h>
  48. #include <asm/uaccess.h>
  49. #include <asm/processor.h>
  50. #ifdef CONFIG_X86
  51. #include <asm/nmi.h>
  52. #include <asm/stacktrace.h>
  53. #endif
  54. #if defined(CONFIG_SYSCTL)
  55. /* External variables not in a header file. */
  56. extern int C_A_D;
  57. extern int print_fatal_signals;
  58. extern int sysctl_overcommit_memory;
  59. extern int sysctl_overcommit_ratio;
  60. extern int sysctl_panic_on_oom;
  61. extern int max_threads;
  62. extern int core_uses_pid;
  63. extern int suid_dumpable;
  64. extern char core_pattern[];
  65. extern int pid_max;
  66. extern int min_free_kbytes;
  67. extern int printk_ratelimit_jiffies;
  68. extern int printk_ratelimit_burst;
  69. extern int pid_max_min, pid_max_max;
  70. extern int sysctl_drop_caches;
  71. extern int percpu_pagelist_fraction;
  72. extern int compat_log;
  73. extern int maps_protect;
  74. extern int sysctl_stat_interval;
  75. /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
  76. static int maxolduid = 65535;
  77. static int minolduid;
  78. static int min_percpu_pagelist_fract = 8;
  79. static int ngroups_max = NGROUPS_MAX;
  80. #ifdef CONFIG_KMOD
  81. extern char modprobe_path[];
  82. #endif
  83. #ifdef CONFIG_CHR_DEV_SG
  84. extern int sg_big_buff;
  85. #endif
  86. #ifdef __sparc__
  87. extern char reboot_command [];
  88. extern int stop_a_enabled;
  89. extern int scons_pwroff;
  90. #endif
  91. #ifdef __hppa__
  92. extern int pwrsw_enabled;
  93. extern int unaligned_enabled;
  94. #endif
  95. #ifdef CONFIG_S390
  96. #ifdef CONFIG_MATHEMU
  97. extern int sysctl_ieee_emulation_warnings;
  98. #endif
  99. extern int sysctl_userprocess_debug;
  100. extern int spin_retry;
  101. #endif
  102. extern int sysctl_hz_timer;
  103. #ifdef CONFIG_BSD_PROCESS_ACCT
  104. extern int acct_parm[];
  105. #endif
  106. #ifdef CONFIG_IA64
  107. extern int no_unaligned_warning;
  108. #endif
  109. #ifdef CONFIG_RT_MUTEXES
  110. extern int max_lock_depth;
  111. #endif
  112. #ifdef CONFIG_SYSCTL_SYSCALL
  113. static int parse_table(int __user *, int, void __user *, size_t __user *,
  114. void __user *, size_t, ctl_table *);
  115. #endif
  116. #ifdef CONFIG_PROC_SYSCTL
  117. static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
  118. void __user *buffer, size_t *lenp, loff_t *ppos);
  119. static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
  120. void __user *buffer, size_t *lenp, loff_t *ppos);
  121. #endif
  122. static ctl_table root_table[];
  123. static struct ctl_table_header root_table_header =
  124. { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
  125. static ctl_table kern_table[];
  126. static ctl_table vm_table[];
  127. static ctl_table fs_table[];
  128. static ctl_table debug_table[];
  129. static ctl_table dev_table[];
  130. extern ctl_table random_table[];
  131. #ifdef CONFIG_UNIX98_PTYS
  132. extern ctl_table pty_table[];
  133. #endif
  134. #ifdef CONFIG_INOTIFY_USER
  135. extern ctl_table inotify_table[];
  136. #endif
  137. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  138. int sysctl_legacy_va_layout;
  139. #endif
  140. /* The default sysctl tables: */
  141. static ctl_table root_table[] = {
  142. {
  143. .ctl_name = CTL_KERN,
  144. .procname = "kernel",
  145. .mode = 0555,
  146. .child = kern_table,
  147. },
  148. {
  149. .ctl_name = CTL_VM,
  150. .procname = "vm",
  151. .mode = 0555,
  152. .child = vm_table,
  153. },
  154. #ifdef CONFIG_NET
  155. {
  156. .ctl_name = CTL_NET,
  157. .procname = "net",
  158. .mode = 0555,
  159. .child = net_table,
  160. },
  161. #endif
  162. {
  163. .ctl_name = CTL_FS,
  164. .procname = "fs",
  165. .mode = 0555,
  166. .child = fs_table,
  167. },
  168. {
  169. .ctl_name = CTL_DEBUG,
  170. .procname = "debug",
  171. .mode = 0555,
  172. .child = debug_table,
  173. },
  174. {
  175. .ctl_name = CTL_DEV,
  176. .procname = "dev",
  177. .mode = 0555,
  178. .child = dev_table,
  179. },
  180. /*
  181. * NOTE: do not add new entries to this table unless you have read
  182. * Documentation/sysctl/ctl_unnumbered.txt
  183. */
  184. { .ctl_name = 0 }
  185. };
  186. #ifdef CONFIG_SCHED_DEBUG
  187. static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
  188. static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
  189. static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
  190. static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
  191. #endif
  192. static ctl_table kern_table[] = {
  193. #ifdef CONFIG_SCHED_DEBUG
  194. {
  195. .ctl_name = CTL_UNNUMBERED,
  196. .procname = "sched_granularity_ns",
  197. .data = &sysctl_sched_granularity,
  198. .maxlen = sizeof(unsigned int),
  199. .mode = 0644,
  200. .proc_handler = &proc_dointvec_minmax,
  201. .strategy = &sysctl_intvec,
  202. .extra1 = &min_sched_granularity_ns,
  203. .extra2 = &max_sched_granularity_ns,
  204. },
  205. {
  206. .ctl_name = CTL_UNNUMBERED,
  207. .procname = "sched_wakeup_granularity_ns",
  208. .data = &sysctl_sched_wakeup_granularity,
  209. .maxlen = sizeof(unsigned int),
  210. .mode = 0644,
  211. .proc_handler = &proc_dointvec_minmax,
  212. .strategy = &sysctl_intvec,
  213. .extra1 = &min_wakeup_granularity_ns,
  214. .extra2 = &max_wakeup_granularity_ns,
  215. },
  216. {
  217. .ctl_name = CTL_UNNUMBERED,
  218. .procname = "sched_batch_wakeup_granularity_ns",
  219. .data = &sysctl_sched_batch_wakeup_granularity,
  220. .maxlen = sizeof(unsigned int),
  221. .mode = 0644,
  222. .proc_handler = &proc_dointvec_minmax,
  223. .strategy = &sysctl_intvec,
  224. .extra1 = &min_wakeup_granularity_ns,
  225. .extra2 = &max_wakeup_granularity_ns,
  226. },
  227. {
  228. .ctl_name = CTL_UNNUMBERED,
  229. .procname = "sched_stat_granularity_ns",
  230. .data = &sysctl_sched_stat_granularity,
  231. .maxlen = sizeof(unsigned int),
  232. .mode = 0644,
  233. .proc_handler = &proc_dointvec_minmax,
  234. .strategy = &sysctl_intvec,
  235. .extra1 = &min_wakeup_granularity_ns,
  236. .extra2 = &max_wakeup_granularity_ns,
  237. },
  238. {
  239. .ctl_name = CTL_UNNUMBERED,
  240. .procname = "sched_runtime_limit_ns",
  241. .data = &sysctl_sched_runtime_limit,
  242. .maxlen = sizeof(unsigned int),
  243. .mode = 0644,
  244. .proc_handler = &proc_dointvec_minmax,
  245. .strategy = &sysctl_intvec,
  246. .extra1 = &min_sched_granularity_ns,
  247. .extra2 = &max_sched_granularity_ns,
  248. },
  249. {
  250. .ctl_name = CTL_UNNUMBERED,
  251. .procname = "sched_child_runs_first",
  252. .data = &sysctl_sched_child_runs_first,
  253. .maxlen = sizeof(unsigned int),
  254. .mode = 0644,
  255. .proc_handler = &proc_dointvec,
  256. },
  257. {
  258. .ctl_name = CTL_UNNUMBERED,
  259. .procname = "sched_features",
  260. .data = &sysctl_sched_features,
  261. .maxlen = sizeof(unsigned int),
  262. .mode = 0644,
  263. .proc_handler = &proc_dointvec,
  264. },
  265. #endif
  266. {
  267. .ctl_name = KERN_PANIC,
  268. .procname = "panic",
  269. .data = &panic_timeout,
  270. .maxlen = sizeof(int),
  271. .mode = 0644,
  272. .proc_handler = &proc_dointvec,
  273. },
  274. {
  275. .ctl_name = KERN_CORE_USES_PID,
  276. .procname = "core_uses_pid",
  277. .data = &core_uses_pid,
  278. .maxlen = sizeof(int),
  279. .mode = 0644,
  280. .proc_handler = &proc_dointvec,
  281. },
  282. {
  283. .ctl_name = KERN_CORE_PATTERN,
  284. .procname = "core_pattern",
  285. .data = core_pattern,
  286. .maxlen = CORENAME_MAX_SIZE,
  287. .mode = 0644,
  288. .proc_handler = &proc_dostring,
  289. .strategy = &sysctl_string,
  290. },
  291. #ifdef CONFIG_PROC_SYSCTL
  292. {
  293. .ctl_name = KERN_TAINTED,
  294. .procname = "tainted",
  295. .data = &tainted,
  296. .maxlen = sizeof(int),
  297. .mode = 0644,
  298. .proc_handler = &proc_dointvec_taint,
  299. },
  300. #endif
  301. {
  302. .ctl_name = KERN_CAP_BSET,
  303. .procname = "cap-bound",
  304. .data = &cap_bset,
  305. .maxlen = sizeof(kernel_cap_t),
  306. .mode = 0600,
  307. .proc_handler = &proc_dointvec_bset,
  308. },
  309. #ifdef CONFIG_BLK_DEV_INITRD
  310. {
  311. .ctl_name = KERN_REALROOTDEV,
  312. .procname = "real-root-dev",
  313. .data = &real_root_dev,
  314. .maxlen = sizeof(int),
  315. .mode = 0644,
  316. .proc_handler = &proc_dointvec,
  317. },
  318. #endif
  319. {
  320. .ctl_name = CTL_UNNUMBERED,
  321. .procname = "print-fatal-signals",
  322. .data = &print_fatal_signals,
  323. .maxlen = sizeof(int),
  324. .mode = 0644,
  325. .proc_handler = &proc_dointvec,
  326. },
  327. #ifdef __sparc__
  328. {
  329. .ctl_name = KERN_SPARC_REBOOT,
  330. .procname = "reboot-cmd",
  331. .data = reboot_command,
  332. .maxlen = 256,
  333. .mode = 0644,
  334. .proc_handler = &proc_dostring,
  335. .strategy = &sysctl_string,
  336. },
  337. {
  338. .ctl_name = KERN_SPARC_STOP_A,
  339. .procname = "stop-a",
  340. .data = &stop_a_enabled,
  341. .maxlen = sizeof (int),
  342. .mode = 0644,
  343. .proc_handler = &proc_dointvec,
  344. },
  345. {
  346. .ctl_name = KERN_SPARC_SCONS_PWROFF,
  347. .procname = "scons-poweroff",
  348. .data = &scons_pwroff,
  349. .maxlen = sizeof (int),
  350. .mode = 0644,
  351. .proc_handler = &proc_dointvec,
  352. },
  353. #endif
  354. #ifdef __hppa__
  355. {
  356. .ctl_name = KERN_HPPA_PWRSW,
  357. .procname = "soft-power",
  358. .data = &pwrsw_enabled,
  359. .maxlen = sizeof (int),
  360. .mode = 0644,
  361. .proc_handler = &proc_dointvec,
  362. },
  363. {
  364. .ctl_name = KERN_HPPA_UNALIGNED,
  365. .procname = "unaligned-trap",
  366. .data = &unaligned_enabled,
  367. .maxlen = sizeof (int),
  368. .mode = 0644,
  369. .proc_handler = &proc_dointvec,
  370. },
  371. #endif
  372. {
  373. .ctl_name = KERN_CTLALTDEL,
  374. .procname = "ctrl-alt-del",
  375. .data = &C_A_D,
  376. .maxlen = sizeof(int),
  377. .mode = 0644,
  378. .proc_handler = &proc_dointvec,
  379. },
  380. {
  381. .ctl_name = KERN_PRINTK,
  382. .procname = "printk",
  383. .data = &console_loglevel,
  384. .maxlen = 4*sizeof(int),
  385. .mode = 0644,
  386. .proc_handler = &proc_dointvec,
  387. },
  388. #ifdef CONFIG_KMOD
  389. {
  390. .ctl_name = KERN_MODPROBE,
  391. .procname = "modprobe",
  392. .data = &modprobe_path,
  393. .maxlen = KMOD_PATH_LEN,
  394. .mode = 0644,
  395. .proc_handler = &proc_dostring,
  396. .strategy = &sysctl_string,
  397. },
  398. #endif
  399. #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
  400. {
  401. .ctl_name = KERN_HOTPLUG,
  402. .procname = "hotplug",
  403. .data = &uevent_helper,
  404. .maxlen = UEVENT_HELPER_PATH_LEN,
  405. .mode = 0644,
  406. .proc_handler = &proc_dostring,
  407. .strategy = &sysctl_string,
  408. },
  409. #endif
  410. #ifdef CONFIG_CHR_DEV_SG
  411. {
  412. .ctl_name = KERN_SG_BIG_BUFF,
  413. .procname = "sg-big-buff",
  414. .data = &sg_big_buff,
  415. .maxlen = sizeof (int),
  416. .mode = 0444,
  417. .proc_handler = &proc_dointvec,
  418. },
  419. #endif
  420. #ifdef CONFIG_BSD_PROCESS_ACCT
  421. {
  422. .ctl_name = KERN_ACCT,
  423. .procname = "acct",
  424. .data = &acct_parm,
  425. .maxlen = 3*sizeof(int),
  426. .mode = 0644,
  427. .proc_handler = &proc_dointvec,
  428. },
  429. #endif
  430. #ifdef CONFIG_MAGIC_SYSRQ
  431. {
  432. .ctl_name = KERN_SYSRQ,
  433. .procname = "sysrq",
  434. .data = &__sysrq_enabled,
  435. .maxlen = sizeof (int),
  436. .mode = 0644,
  437. .proc_handler = &proc_dointvec,
  438. },
  439. #endif
  440. #ifdef CONFIG_PROC_SYSCTL
  441. {
  442. .ctl_name = KERN_CADPID,
  443. .procname = "cad_pid",
  444. .data = NULL,
  445. .maxlen = sizeof (int),
  446. .mode = 0600,
  447. .proc_handler = &proc_do_cad_pid,
  448. },
  449. #endif
  450. {
  451. .ctl_name = KERN_MAX_THREADS,
  452. .procname = "threads-max",
  453. .data = &max_threads,
  454. .maxlen = sizeof(int),
  455. .mode = 0644,
  456. .proc_handler = &proc_dointvec,
  457. },
  458. {
  459. .ctl_name = KERN_RANDOM,
  460. .procname = "random",
  461. .mode = 0555,
  462. .child = random_table,
  463. },
  464. #ifdef CONFIG_UNIX98_PTYS
  465. {
  466. .ctl_name = KERN_PTY,
  467. .procname = "pty",
  468. .mode = 0555,
  469. .child = pty_table,
  470. },
  471. #endif
  472. {
  473. .ctl_name = KERN_OVERFLOWUID,
  474. .procname = "overflowuid",
  475. .data = &overflowuid,
  476. .maxlen = sizeof(int),
  477. .mode = 0644,
  478. .proc_handler = &proc_dointvec_minmax,
  479. .strategy = &sysctl_intvec,
  480. .extra1 = &minolduid,
  481. .extra2 = &maxolduid,
  482. },
  483. {
  484. .ctl_name = KERN_OVERFLOWGID,
  485. .procname = "overflowgid",
  486. .data = &overflowgid,
  487. .maxlen = sizeof(int),
  488. .mode = 0644,
  489. .proc_handler = &proc_dointvec_minmax,
  490. .strategy = &sysctl_intvec,
  491. .extra1 = &minolduid,
  492. .extra2 = &maxolduid,
  493. },
  494. #ifdef CONFIG_S390
  495. #ifdef CONFIG_MATHEMU
  496. {
  497. .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
  498. .procname = "ieee_emulation_warnings",
  499. .data = &sysctl_ieee_emulation_warnings,
  500. .maxlen = sizeof(int),
  501. .mode = 0644,
  502. .proc_handler = &proc_dointvec,
  503. },
  504. #endif
  505. #ifdef CONFIG_NO_IDLE_HZ
  506. {
  507. .ctl_name = KERN_HZ_TIMER,
  508. .procname = "hz_timer",
  509. .data = &sysctl_hz_timer,
  510. .maxlen = sizeof(int),
  511. .mode = 0644,
  512. .proc_handler = &proc_dointvec,
  513. },
  514. #endif
  515. {
  516. .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
  517. .procname = "userprocess_debug",
  518. .data = &sysctl_userprocess_debug,
  519. .maxlen = sizeof(int),
  520. .mode = 0644,
  521. .proc_handler = &proc_dointvec,
  522. },
  523. #endif
  524. {
  525. .ctl_name = KERN_PIDMAX,
  526. .procname = "pid_max",
  527. .data = &pid_max,
  528. .maxlen = sizeof (int),
  529. .mode = 0644,
  530. .proc_handler = &proc_dointvec_minmax,
  531. .strategy = sysctl_intvec,
  532. .extra1 = &pid_max_min,
  533. .extra2 = &pid_max_max,
  534. },
  535. {
  536. .ctl_name = KERN_PANIC_ON_OOPS,
  537. .procname = "panic_on_oops",
  538. .data = &panic_on_oops,
  539. .maxlen = sizeof(int),
  540. .mode = 0644,
  541. .proc_handler = &proc_dointvec,
  542. },
  543. {
  544. .ctl_name = KERN_PRINTK_RATELIMIT,
  545. .procname = "printk_ratelimit",
  546. .data = &printk_ratelimit_jiffies,
  547. .maxlen = sizeof(int),
  548. .mode = 0644,
  549. .proc_handler = &proc_dointvec_jiffies,
  550. .strategy = &sysctl_jiffies,
  551. },
  552. {
  553. .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
  554. .procname = "printk_ratelimit_burst",
  555. .data = &printk_ratelimit_burst,
  556. .maxlen = sizeof(int),
  557. .mode = 0644,
  558. .proc_handler = &proc_dointvec,
  559. },
  560. {
  561. .ctl_name = KERN_NGROUPS_MAX,
  562. .procname = "ngroups_max",
  563. .data = &ngroups_max,
  564. .maxlen = sizeof (int),
  565. .mode = 0444,
  566. .proc_handler = &proc_dointvec,
  567. },
  568. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
  569. {
  570. .ctl_name = KERN_UNKNOWN_NMI_PANIC,
  571. .procname = "unknown_nmi_panic",
  572. .data = &unknown_nmi_panic,
  573. .maxlen = sizeof (int),
  574. .mode = 0644,
  575. .proc_handler = &proc_dointvec,
  576. },
  577. {
  578. .ctl_name = KERN_NMI_WATCHDOG,
  579. .procname = "nmi_watchdog",
  580. .data = &nmi_watchdog_enabled,
  581. .maxlen = sizeof (int),
  582. .mode = 0644,
  583. .proc_handler = &proc_nmi_enabled,
  584. },
  585. #endif
  586. #if defined(CONFIG_X86)
  587. {
  588. .ctl_name = KERN_PANIC_ON_NMI,
  589. .procname = "panic_on_unrecovered_nmi",
  590. .data = &panic_on_unrecovered_nmi,
  591. .maxlen = sizeof(int),
  592. .mode = 0644,
  593. .proc_handler = &proc_dointvec,
  594. },
  595. {
  596. .ctl_name = KERN_BOOTLOADER_TYPE,
  597. .procname = "bootloader_type",
  598. .data = &bootloader_type,
  599. .maxlen = sizeof (int),
  600. .mode = 0444,
  601. .proc_handler = &proc_dointvec,
  602. },
  603. {
  604. .ctl_name = CTL_UNNUMBERED,
  605. .procname = "kstack_depth_to_print",
  606. .data = &kstack_depth_to_print,
  607. .maxlen = sizeof(int),
  608. .mode = 0644,
  609. .proc_handler = &proc_dointvec,
  610. },
  611. #endif
  612. #if defined(CONFIG_MMU)
  613. {
  614. .ctl_name = KERN_RANDOMIZE,
  615. .procname = "randomize_va_space",
  616. .data = &randomize_va_space,
  617. .maxlen = sizeof(int),
  618. .mode = 0644,
  619. .proc_handler = &proc_dointvec,
  620. },
  621. #endif
  622. #if defined(CONFIG_S390) && defined(CONFIG_SMP)
  623. {
  624. .ctl_name = KERN_SPIN_RETRY,
  625. .procname = "spin_retry",
  626. .data = &spin_retry,
  627. .maxlen = sizeof (int),
  628. .mode = 0644,
  629. .proc_handler = &proc_dointvec,
  630. },
  631. #endif
  632. #ifdef CONFIG_ACPI_SLEEP
  633. {
  634. .ctl_name = KERN_ACPI_VIDEO_FLAGS,
  635. .procname = "acpi_video_flags",
  636. .data = &acpi_video_flags,
  637. .maxlen = sizeof (unsigned long),
  638. .mode = 0644,
  639. .proc_handler = &proc_doulongvec_minmax,
  640. },
  641. #endif
  642. #ifdef CONFIG_IA64
  643. {
  644. .ctl_name = KERN_IA64_UNALIGNED,
  645. .procname = "ignore-unaligned-usertrap",
  646. .data = &no_unaligned_warning,
  647. .maxlen = sizeof (int),
  648. .mode = 0644,
  649. .proc_handler = &proc_dointvec,
  650. },
  651. #endif
  652. #ifdef CONFIG_COMPAT
  653. {
  654. .ctl_name = KERN_COMPAT_LOG,
  655. .procname = "compat-log",
  656. .data = &compat_log,
  657. .maxlen = sizeof (int),
  658. .mode = 0644,
  659. .proc_handler = &proc_dointvec,
  660. },
  661. #endif
  662. #ifdef CONFIG_RT_MUTEXES
  663. {
  664. .ctl_name = KERN_MAX_LOCK_DEPTH,
  665. .procname = "max_lock_depth",
  666. .data = &max_lock_depth,
  667. .maxlen = sizeof(int),
  668. .mode = 0644,
  669. .proc_handler = &proc_dointvec,
  670. },
  671. #endif
  672. #ifdef CONFIG_PROC_FS
  673. {
  674. .ctl_name = CTL_UNNUMBERED,
  675. .procname = "maps_protect",
  676. .data = &maps_protect,
  677. .maxlen = sizeof(int),
  678. .mode = 0644,
  679. .proc_handler = &proc_dointvec,
  680. },
  681. #endif
  682. { .ctl_name = 0 }
  683. };
  684. /* Constants for minimum and maximum testing in vm_table.
  685. We use these as one-element integer vectors. */
  686. static int zero;
  687. static int one_hundred = 100;
  688. static ctl_table vm_table[] = {
  689. {
  690. .ctl_name = VM_OVERCOMMIT_MEMORY,
  691. .procname = "overcommit_memory",
  692. .data = &sysctl_overcommit_memory,
  693. .maxlen = sizeof(sysctl_overcommit_memory),
  694. .mode = 0644,
  695. .proc_handler = &proc_dointvec,
  696. },
  697. {
  698. .ctl_name = VM_PANIC_ON_OOM,
  699. .procname = "panic_on_oom",
  700. .data = &sysctl_panic_on_oom,
  701. .maxlen = sizeof(sysctl_panic_on_oom),
  702. .mode = 0644,
  703. .proc_handler = &proc_dointvec,
  704. },
  705. {
  706. .ctl_name = VM_OVERCOMMIT_RATIO,
  707. .procname = "overcommit_ratio",
  708. .data = &sysctl_overcommit_ratio,
  709. .maxlen = sizeof(sysctl_overcommit_ratio),
  710. .mode = 0644,
  711. .proc_handler = &proc_dointvec,
  712. },
  713. {
  714. .ctl_name = VM_PAGE_CLUSTER,
  715. .procname = "page-cluster",
  716. .data = &page_cluster,
  717. .maxlen = sizeof(int),
  718. .mode = 0644,
  719. .proc_handler = &proc_dointvec,
  720. },
  721. {
  722. .ctl_name = VM_DIRTY_BACKGROUND,
  723. .procname = "dirty_background_ratio",
  724. .data = &dirty_background_ratio,
  725. .maxlen = sizeof(dirty_background_ratio),
  726. .mode = 0644,
  727. .proc_handler = &proc_dointvec_minmax,
  728. .strategy = &sysctl_intvec,
  729. .extra1 = &zero,
  730. .extra2 = &one_hundred,
  731. },
  732. {
  733. .ctl_name = VM_DIRTY_RATIO,
  734. .procname = "dirty_ratio",
  735. .data = &vm_dirty_ratio,
  736. .maxlen = sizeof(vm_dirty_ratio),
  737. .mode = 0644,
  738. .proc_handler = &proc_dointvec_minmax,
  739. .strategy = &sysctl_intvec,
  740. .extra1 = &zero,
  741. .extra2 = &one_hundred,
  742. },
  743. {
  744. .ctl_name = VM_DIRTY_WB_CS,
  745. .procname = "dirty_writeback_centisecs",
  746. .data = &dirty_writeback_interval,
  747. .maxlen = sizeof(dirty_writeback_interval),
  748. .mode = 0644,
  749. .proc_handler = &dirty_writeback_centisecs_handler,
  750. },
  751. {
  752. .ctl_name = VM_DIRTY_EXPIRE_CS,
  753. .procname = "dirty_expire_centisecs",
  754. .data = &dirty_expire_interval,
  755. .maxlen = sizeof(dirty_expire_interval),
  756. .mode = 0644,
  757. .proc_handler = &proc_dointvec_userhz_jiffies,
  758. },
  759. {
  760. .ctl_name = VM_NR_PDFLUSH_THREADS,
  761. .procname = "nr_pdflush_threads",
  762. .data = &nr_pdflush_threads,
  763. .maxlen = sizeof nr_pdflush_threads,
  764. .mode = 0444 /* read-only*/,
  765. .proc_handler = &proc_dointvec,
  766. },
  767. {
  768. .ctl_name = VM_SWAPPINESS,
  769. .procname = "swappiness",
  770. .data = &vm_swappiness,
  771. .maxlen = sizeof(vm_swappiness),
  772. .mode = 0644,
  773. .proc_handler = &proc_dointvec_minmax,
  774. .strategy = &sysctl_intvec,
  775. .extra1 = &zero,
  776. .extra2 = &one_hundred,
  777. },
  778. #ifdef CONFIG_HUGETLB_PAGE
  779. {
  780. .ctl_name = VM_HUGETLB_PAGES,
  781. .procname = "nr_hugepages",
  782. .data = &max_huge_pages,
  783. .maxlen = sizeof(unsigned long),
  784. .mode = 0644,
  785. .proc_handler = &hugetlb_sysctl_handler,
  786. .extra1 = (void *)&hugetlb_zero,
  787. .extra2 = (void *)&hugetlb_infinity,
  788. },
  789. {
  790. .ctl_name = VM_HUGETLB_GROUP,
  791. .procname = "hugetlb_shm_group",
  792. .data = &sysctl_hugetlb_shm_group,
  793. .maxlen = sizeof(gid_t),
  794. .mode = 0644,
  795. .proc_handler = &proc_dointvec,
  796. },
  797. {
  798. .ctl_name = CTL_UNNUMBERED,
  799. .procname = "hugepages_treat_as_movable",
  800. .data = &hugepages_treat_as_movable,
  801. .maxlen = sizeof(int),
  802. .mode = 0644,
  803. .proc_handler = &hugetlb_treat_movable_handler,
  804. },
  805. #endif
  806. {
  807. .ctl_name = VM_LOWMEM_RESERVE_RATIO,
  808. .procname = "lowmem_reserve_ratio",
  809. .data = &sysctl_lowmem_reserve_ratio,
  810. .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
  811. .mode = 0644,
  812. .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
  813. .strategy = &sysctl_intvec,
  814. },
  815. {
  816. .ctl_name = VM_DROP_PAGECACHE,
  817. .procname = "drop_caches",
  818. .data = &sysctl_drop_caches,
  819. .maxlen = sizeof(int),
  820. .mode = 0644,
  821. .proc_handler = drop_caches_sysctl_handler,
  822. .strategy = &sysctl_intvec,
  823. },
  824. {
  825. .ctl_name = VM_MIN_FREE_KBYTES,
  826. .procname = "min_free_kbytes",
  827. .data = &min_free_kbytes,
  828. .maxlen = sizeof(min_free_kbytes),
  829. .mode = 0644,
  830. .proc_handler = &min_free_kbytes_sysctl_handler,
  831. .strategy = &sysctl_intvec,
  832. .extra1 = &zero,
  833. },
  834. {
  835. .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
  836. .procname = "percpu_pagelist_fraction",
  837. .data = &percpu_pagelist_fraction,
  838. .maxlen = sizeof(percpu_pagelist_fraction),
  839. .mode = 0644,
  840. .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
  841. .strategy = &sysctl_intvec,
  842. .extra1 = &min_percpu_pagelist_fract,
  843. },
  844. #ifdef CONFIG_MMU
  845. {
  846. .ctl_name = VM_MAX_MAP_COUNT,
  847. .procname = "max_map_count",
  848. .data = &sysctl_max_map_count,
  849. .maxlen = sizeof(sysctl_max_map_count),
  850. .mode = 0644,
  851. .proc_handler = &proc_dointvec
  852. },
  853. #endif
  854. {
  855. .ctl_name = VM_LAPTOP_MODE,
  856. .procname = "laptop_mode",
  857. .data = &laptop_mode,
  858. .maxlen = sizeof(laptop_mode),
  859. .mode = 0644,
  860. .proc_handler = &proc_dointvec_jiffies,
  861. .strategy = &sysctl_jiffies,
  862. },
  863. {
  864. .ctl_name = VM_BLOCK_DUMP,
  865. .procname = "block_dump",
  866. .data = &block_dump,
  867. .maxlen = sizeof(block_dump),
  868. .mode = 0644,
  869. .proc_handler = &proc_dointvec,
  870. .strategy = &sysctl_intvec,
  871. .extra1 = &zero,
  872. },
  873. {
  874. .ctl_name = VM_VFS_CACHE_PRESSURE,
  875. .procname = "vfs_cache_pressure",
  876. .data = &sysctl_vfs_cache_pressure,
  877. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  878. .mode = 0644,
  879. .proc_handler = &proc_dointvec,
  880. .strategy = &sysctl_intvec,
  881. .extra1 = &zero,
  882. },
  883. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  884. {
  885. .ctl_name = VM_LEGACY_VA_LAYOUT,
  886. .procname = "legacy_va_layout",
  887. .data = &sysctl_legacy_va_layout,
  888. .maxlen = sizeof(sysctl_legacy_va_layout),
  889. .mode = 0644,
  890. .proc_handler = &proc_dointvec,
  891. .strategy = &sysctl_intvec,
  892. .extra1 = &zero,
  893. },
  894. #endif
  895. #ifdef CONFIG_NUMA
  896. {
  897. .ctl_name = VM_ZONE_RECLAIM_MODE,
  898. .procname = "zone_reclaim_mode",
  899. .data = &zone_reclaim_mode,
  900. .maxlen = sizeof(zone_reclaim_mode),
  901. .mode = 0644,
  902. .proc_handler = &proc_dointvec,
  903. .strategy = &sysctl_intvec,
  904. .extra1 = &zero,
  905. },
  906. {
  907. .ctl_name = VM_MIN_UNMAPPED,
  908. .procname = "min_unmapped_ratio",
  909. .data = &sysctl_min_unmapped_ratio,
  910. .maxlen = sizeof(sysctl_min_unmapped_ratio),
  911. .mode = 0644,
  912. .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
  913. .strategy = &sysctl_intvec,
  914. .extra1 = &zero,
  915. .extra2 = &one_hundred,
  916. },
  917. {
  918. .ctl_name = VM_MIN_SLAB,
  919. .procname = "min_slab_ratio",
  920. .data = &sysctl_min_slab_ratio,
  921. .maxlen = sizeof(sysctl_min_slab_ratio),
  922. .mode = 0644,
  923. .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
  924. .strategy = &sysctl_intvec,
  925. .extra1 = &zero,
  926. .extra2 = &one_hundred,
  927. },
  928. #endif
  929. #ifdef CONFIG_SMP
  930. {
  931. .ctl_name = CTL_UNNUMBERED,
  932. .procname = "stat_interval",
  933. .data = &sysctl_stat_interval,
  934. .maxlen = sizeof(sysctl_stat_interval),
  935. .mode = 0644,
  936. .proc_handler = &proc_dointvec_jiffies,
  937. .strategy = &sysctl_jiffies,
  938. },
  939. #endif
  940. #ifdef CONFIG_SECURITY
  941. {
  942. .ctl_name = CTL_UNNUMBERED,
  943. .procname = "mmap_min_addr",
  944. .data = &mmap_min_addr,
  945. .maxlen = sizeof(unsigned long),
  946. .mode = 0644,
  947. .proc_handler = &proc_doulongvec_minmax,
  948. },
  949. #ifdef CONFIG_NUMA
  950. {
  951. .ctl_name = CTL_UNNUMBERED,
  952. .procname = "numa_zonelist_order",
  953. .data = &numa_zonelist_order,
  954. .maxlen = NUMA_ZONELIST_ORDER_LEN,
  955. .mode = 0644,
  956. .proc_handler = &numa_zonelist_order_handler,
  957. .strategy = &sysctl_string,
  958. },
  959. #endif
  960. #endif
  961. #if defined(CONFIG_X86_32) || \
  962. (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
  963. {
  964. .ctl_name = VM_VDSO_ENABLED,
  965. .procname = "vdso_enabled",
  966. .data = &vdso_enabled,
  967. .maxlen = sizeof(vdso_enabled),
  968. .mode = 0644,
  969. .proc_handler = &proc_dointvec,
  970. .strategy = &sysctl_intvec,
  971. .extra1 = &zero,
  972. },
  973. #endif
  974. /*
  975. * NOTE: do not add new entries to this table unless you have read
  976. * Documentation/sysctl/ctl_unnumbered.txt
  977. */
  978. { .ctl_name = 0 }
  979. };
  980. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  981. static ctl_table binfmt_misc_table[] = {
  982. { .ctl_name = 0 }
  983. };
  984. #endif
  985. static ctl_table fs_table[] = {
  986. {
  987. .ctl_name = FS_NRINODE,
  988. .procname = "inode-nr",
  989. .data = &inodes_stat,
  990. .maxlen = 2*sizeof(int),
  991. .mode = 0444,
  992. .proc_handler = &proc_dointvec,
  993. },
  994. {
  995. .ctl_name = FS_STATINODE,
  996. .procname = "inode-state",
  997. .data = &inodes_stat,
  998. .maxlen = 7*sizeof(int),
  999. .mode = 0444,
  1000. .proc_handler = &proc_dointvec,
  1001. },
  1002. {
  1003. .ctl_name = FS_NRFILE,
  1004. .procname = "file-nr",
  1005. .data = &files_stat,
  1006. .maxlen = 3*sizeof(int),
  1007. .mode = 0444,
  1008. .proc_handler = &proc_nr_files,
  1009. },
  1010. {
  1011. .ctl_name = FS_MAXFILE,
  1012. .procname = "file-max",
  1013. .data = &files_stat.max_files,
  1014. .maxlen = sizeof(int),
  1015. .mode = 0644,
  1016. .proc_handler = &proc_dointvec,
  1017. },
  1018. {
  1019. .ctl_name = FS_DENTRY,
  1020. .procname = "dentry-state",
  1021. .data = &dentry_stat,
  1022. .maxlen = 6*sizeof(int),
  1023. .mode = 0444,
  1024. .proc_handler = &proc_dointvec,
  1025. },
  1026. {
  1027. .ctl_name = FS_OVERFLOWUID,
  1028. .procname = "overflowuid",
  1029. .data = &fs_overflowuid,
  1030. .maxlen = sizeof(int),
  1031. .mode = 0644,
  1032. .proc_handler = &proc_dointvec_minmax,
  1033. .strategy = &sysctl_intvec,
  1034. .extra1 = &minolduid,
  1035. .extra2 = &maxolduid,
  1036. },
  1037. {
  1038. .ctl_name = FS_OVERFLOWGID,
  1039. .procname = "overflowgid",
  1040. .data = &fs_overflowgid,
  1041. .maxlen = sizeof(int),
  1042. .mode = 0644,
  1043. .proc_handler = &proc_dointvec_minmax,
  1044. .strategy = &sysctl_intvec,
  1045. .extra1 = &minolduid,
  1046. .extra2 = &maxolduid,
  1047. },
  1048. {
  1049. .ctl_name = FS_LEASES,
  1050. .procname = "leases-enable",
  1051. .data = &leases_enable,
  1052. .maxlen = sizeof(int),
  1053. .mode = 0644,
  1054. .proc_handler = &proc_dointvec,
  1055. },
  1056. #ifdef CONFIG_DNOTIFY
  1057. {
  1058. .ctl_name = FS_DIR_NOTIFY,
  1059. .procname = "dir-notify-enable",
  1060. .data = &dir_notify_enable,
  1061. .maxlen = sizeof(int),
  1062. .mode = 0644,
  1063. .proc_handler = &proc_dointvec,
  1064. },
  1065. #endif
  1066. #ifdef CONFIG_MMU
  1067. {
  1068. .ctl_name = FS_LEASE_TIME,
  1069. .procname = "lease-break-time",
  1070. .data = &lease_break_time,
  1071. .maxlen = sizeof(int),
  1072. .mode = 0644,
  1073. .proc_handler = &proc_dointvec,
  1074. },
  1075. {
  1076. .ctl_name = FS_AIO_NR,
  1077. .procname = "aio-nr",
  1078. .data = &aio_nr,
  1079. .maxlen = sizeof(aio_nr),
  1080. .mode = 0444,
  1081. .proc_handler = &proc_doulongvec_minmax,
  1082. },
  1083. {
  1084. .ctl_name = FS_AIO_MAX_NR,
  1085. .procname = "aio-max-nr",
  1086. .data = &aio_max_nr,
  1087. .maxlen = sizeof(aio_max_nr),
  1088. .mode = 0644,
  1089. .proc_handler = &proc_doulongvec_minmax,
  1090. },
  1091. #ifdef CONFIG_INOTIFY_USER
  1092. {
  1093. .ctl_name = FS_INOTIFY,
  1094. .procname = "inotify",
  1095. .mode = 0555,
  1096. .child = inotify_table,
  1097. },
  1098. #endif
  1099. #endif
  1100. {
  1101. .ctl_name = KERN_SETUID_DUMPABLE,
  1102. .procname = "suid_dumpable",
  1103. .data = &suid_dumpable,
  1104. .maxlen = sizeof(int),
  1105. .mode = 0644,
  1106. .proc_handler = &proc_dointvec,
  1107. },
  1108. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1109. {
  1110. .ctl_name = CTL_UNNUMBERED,
  1111. .procname = "binfmt_misc",
  1112. .mode = 0555,
  1113. .child = binfmt_misc_table,
  1114. },
  1115. #endif
  1116. /*
  1117. * NOTE: do not add new entries to this table unless you have read
  1118. * Documentation/sysctl/ctl_unnumbered.txt
  1119. */
  1120. { .ctl_name = 0 }
  1121. };
  1122. static ctl_table debug_table[] = {
  1123. { .ctl_name = 0 }
  1124. };
  1125. static ctl_table dev_table[] = {
  1126. { .ctl_name = 0 }
  1127. };
  1128. static DEFINE_SPINLOCK(sysctl_lock);
  1129. /* called under sysctl_lock */
  1130. static int use_table(struct ctl_table_header *p)
  1131. {
  1132. if (unlikely(p->unregistering))
  1133. return 0;
  1134. p->used++;
  1135. return 1;
  1136. }
  1137. /* called under sysctl_lock */
  1138. static void unuse_table(struct ctl_table_header *p)
  1139. {
  1140. if (!--p->used)
  1141. if (unlikely(p->unregistering))
  1142. complete(p->unregistering);
  1143. }
  1144. /* called under sysctl_lock, will reacquire if has to wait */
  1145. static void start_unregistering(struct ctl_table_header *p)
  1146. {
  1147. /*
  1148. * if p->used is 0, nobody will ever touch that entry again;
  1149. * we'll eliminate all paths to it before dropping sysctl_lock
  1150. */
  1151. if (unlikely(p->used)) {
  1152. struct completion wait;
  1153. init_completion(&wait);
  1154. p->unregistering = &wait;
  1155. spin_unlock(&sysctl_lock);
  1156. wait_for_completion(&wait);
  1157. spin_lock(&sysctl_lock);
  1158. }
  1159. /*
  1160. * do not remove from the list until nobody holds it; walking the
  1161. * list in do_sysctl() relies on that.
  1162. */
  1163. list_del_init(&p->ctl_entry);
  1164. }
  1165. void sysctl_head_finish(struct ctl_table_header *head)
  1166. {
  1167. if (!head)
  1168. return;
  1169. spin_lock(&sysctl_lock);
  1170. unuse_table(head);
  1171. spin_unlock(&sysctl_lock);
  1172. }
  1173. struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
  1174. {
  1175. struct ctl_table_header *head;
  1176. struct list_head *tmp;
  1177. spin_lock(&sysctl_lock);
  1178. if (prev) {
  1179. tmp = &prev->ctl_entry;
  1180. unuse_table(prev);
  1181. goto next;
  1182. }
  1183. tmp = &root_table_header.ctl_entry;
  1184. for (;;) {
  1185. head = list_entry(tmp, struct ctl_table_header, ctl_entry);
  1186. if (!use_table(head))
  1187. goto next;
  1188. spin_unlock(&sysctl_lock);
  1189. return head;
  1190. next:
  1191. tmp = tmp->next;
  1192. if (tmp == &root_table_header.ctl_entry)
  1193. break;
  1194. }
  1195. spin_unlock(&sysctl_lock);
  1196. return NULL;
  1197. }
  1198. #ifdef CONFIG_SYSCTL_SYSCALL
  1199. int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
  1200. void __user *newval, size_t newlen)
  1201. {
  1202. struct ctl_table_header *head;
  1203. int error = -ENOTDIR;
  1204. if (nlen <= 0 || nlen >= CTL_MAXNAME)
  1205. return -ENOTDIR;
  1206. if (oldval) {
  1207. int old_len;
  1208. if (!oldlenp || get_user(old_len, oldlenp))
  1209. return -EFAULT;
  1210. }
  1211. for (head = sysctl_head_next(NULL); head;
  1212. head = sysctl_head_next(head)) {
  1213. error = parse_table(name, nlen, oldval, oldlenp,
  1214. newval, newlen, head->ctl_table);
  1215. if (error != -ENOTDIR) {
  1216. sysctl_head_finish(head);
  1217. break;
  1218. }
  1219. }
  1220. return error;
  1221. }
  1222. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  1223. {
  1224. struct __sysctl_args tmp;
  1225. int error;
  1226. if (copy_from_user(&tmp, args, sizeof(tmp)))
  1227. return -EFAULT;
  1228. lock_kernel();
  1229. error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
  1230. tmp.newval, tmp.newlen);
  1231. unlock_kernel();
  1232. return error;
  1233. }
  1234. #endif /* CONFIG_SYSCTL_SYSCALL */
  1235. /*
  1236. * sysctl_perm does NOT grant the superuser all rights automatically, because
  1237. * some sysctl variables are readonly even to root.
  1238. */
  1239. static int test_perm(int mode, int op)
  1240. {
  1241. if (!current->euid)
  1242. mode >>= 6;
  1243. else if (in_egroup_p(0))
  1244. mode >>= 3;
  1245. if ((mode & op & 0007) == op)
  1246. return 0;
  1247. return -EACCES;
  1248. }
  1249. int sysctl_perm(ctl_table *table, int op)
  1250. {
  1251. int error;
  1252. error = security_sysctl(table, op);
  1253. if (error)
  1254. return error;
  1255. return test_perm(table->mode, op);
  1256. }
  1257. #ifdef CONFIG_SYSCTL_SYSCALL
  1258. static int parse_table(int __user *name, int nlen,
  1259. void __user *oldval, size_t __user *oldlenp,
  1260. void __user *newval, size_t newlen,
  1261. ctl_table *table)
  1262. {
  1263. int n;
  1264. repeat:
  1265. if (!nlen)
  1266. return -ENOTDIR;
  1267. if (get_user(n, name))
  1268. return -EFAULT;
  1269. for ( ; table->ctl_name || table->procname; table++) {
  1270. if (!table->ctl_name)
  1271. continue;
  1272. if (n == table->ctl_name) {
  1273. int error;
  1274. if (table->child) {
  1275. if (sysctl_perm(table, 001))
  1276. return -EPERM;
  1277. name++;
  1278. nlen--;
  1279. table = table->child;
  1280. goto repeat;
  1281. }
  1282. error = do_sysctl_strategy(table, name, nlen,
  1283. oldval, oldlenp,
  1284. newval, newlen);
  1285. return error;
  1286. }
  1287. }
  1288. return -ENOTDIR;
  1289. }
  1290. /* Perform the actual read/write of a sysctl table entry. */
  1291. int do_sysctl_strategy (ctl_table *table,
  1292. int __user *name, int nlen,
  1293. void __user *oldval, size_t __user *oldlenp,
  1294. void __user *newval, size_t newlen)
  1295. {
  1296. int op = 0, rc;
  1297. size_t len;
  1298. if (oldval)
  1299. op |= 004;
  1300. if (newval)
  1301. op |= 002;
  1302. if (sysctl_perm(table, op))
  1303. return -EPERM;
  1304. if (table->strategy) {
  1305. rc = table->strategy(table, name, nlen, oldval, oldlenp,
  1306. newval, newlen);
  1307. if (rc < 0)
  1308. return rc;
  1309. if (rc > 0)
  1310. return 0;
  1311. }
  1312. /* If there is no strategy routine, or if the strategy returns
  1313. * zero, proceed with automatic r/w */
  1314. if (table->data && table->maxlen) {
  1315. if (oldval && oldlenp) {
  1316. if (get_user(len, oldlenp))
  1317. return -EFAULT;
  1318. if (len) {
  1319. if (len > table->maxlen)
  1320. len = table->maxlen;
  1321. if(copy_to_user(oldval, table->data, len))
  1322. return -EFAULT;
  1323. if(put_user(len, oldlenp))
  1324. return -EFAULT;
  1325. }
  1326. }
  1327. if (newval && newlen) {
  1328. len = newlen;
  1329. if (len > table->maxlen)
  1330. len = table->maxlen;
  1331. if(copy_from_user(table->data, newval, len))
  1332. return -EFAULT;
  1333. }
  1334. }
  1335. return 0;
  1336. }
  1337. #endif /* CONFIG_SYSCTL_SYSCALL */
  1338. static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
  1339. {
  1340. for (; table->ctl_name || table->procname; table++) {
  1341. table->parent = parent;
  1342. if (table->child)
  1343. sysctl_set_parent(table, table->child);
  1344. }
  1345. }
  1346. static __init int sysctl_init(void)
  1347. {
  1348. sysctl_set_parent(NULL, root_table);
  1349. return 0;
  1350. }
  1351. core_initcall(sysctl_init);
  1352. /**
  1353. * register_sysctl_table - register a sysctl hierarchy
  1354. * @table: the top-level table structure
  1355. *
  1356. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1357. * array. An entry with a ctl_name of 0 terminates the table.
  1358. *
  1359. * The members of the &ctl_table structure are used as follows:
  1360. *
  1361. * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
  1362. * must be unique within that level of sysctl
  1363. *
  1364. * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
  1365. * enter a sysctl file
  1366. *
  1367. * data - a pointer to data for use by proc_handler
  1368. *
  1369. * maxlen - the maximum size in bytes of the data
  1370. *
  1371. * mode - the file permissions for the /proc/sys file, and for sysctl(2)
  1372. *
  1373. * child - a pointer to the child sysctl table if this entry is a directory, or
  1374. * %NULL.
  1375. *
  1376. * proc_handler - the text handler routine (described below)
  1377. *
  1378. * strategy - the strategy routine (described below)
  1379. *
  1380. * de - for internal use by the sysctl routines
  1381. *
  1382. * extra1, extra2 - extra pointers usable by the proc handler routines
  1383. *
  1384. * Leaf nodes in the sysctl tree will be represented by a single file
  1385. * under /proc; non-leaf nodes will be represented by directories.
  1386. *
  1387. * sysctl(2) can automatically manage read and write requests through
  1388. * the sysctl table. The data and maxlen fields of the ctl_table
  1389. * struct enable minimal validation of the values being written to be
  1390. * performed, and the mode field allows minimal authentication.
  1391. *
  1392. * More sophisticated management can be enabled by the provision of a
  1393. * strategy routine with the table entry. This will be called before
  1394. * any automatic read or write of the data is performed.
  1395. *
  1396. * The strategy routine may return
  1397. *
  1398. * < 0 - Error occurred (error is passed to user process)
  1399. *
  1400. * 0 - OK - proceed with automatic read or write.
  1401. *
  1402. * > 0 - OK - read or write has been done by the strategy routine, so
  1403. * return immediately.
  1404. *
  1405. * There must be a proc_handler routine for any terminal nodes
  1406. * mirrored under /proc/sys (non-terminals are handled by a built-in
  1407. * directory handler). Several default handlers are available to
  1408. * cover common cases -
  1409. *
  1410. * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
  1411. * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
  1412. * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
  1413. *
  1414. * It is the handler's job to read the input buffer from user memory
  1415. * and process it. The handler should return 0 on success.
  1416. *
  1417. * This routine returns %NULL on a failure to register, and a pointer
  1418. * to the table header on success.
  1419. */
  1420. struct ctl_table_header *register_sysctl_table(ctl_table * table)
  1421. {
  1422. struct ctl_table_header *tmp;
  1423. tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
  1424. if (!tmp)
  1425. return NULL;
  1426. tmp->ctl_table = table;
  1427. INIT_LIST_HEAD(&tmp->ctl_entry);
  1428. tmp->used = 0;
  1429. tmp->unregistering = NULL;
  1430. sysctl_set_parent(NULL, table);
  1431. spin_lock(&sysctl_lock);
  1432. list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1433. spin_unlock(&sysctl_lock);
  1434. return tmp;
  1435. }
  1436. /**
  1437. * unregister_sysctl_table - unregister a sysctl table hierarchy
  1438. * @header: the header returned from register_sysctl_table
  1439. *
  1440. * Unregisters the sysctl table and all children. proc entries may not
  1441. * actually be removed until they are no longer used by anyone.
  1442. */
  1443. void unregister_sysctl_table(struct ctl_table_header * header)
  1444. {
  1445. might_sleep();
  1446. spin_lock(&sysctl_lock);
  1447. start_unregistering(header);
  1448. spin_unlock(&sysctl_lock);
  1449. kfree(header);
  1450. }
  1451. #else /* !CONFIG_SYSCTL */
  1452. struct ctl_table_header *register_sysctl_table(ctl_table * table)
  1453. {
  1454. return NULL;
  1455. }
  1456. void unregister_sysctl_table(struct ctl_table_header * table)
  1457. {
  1458. }
  1459. #endif /* CONFIG_SYSCTL */
  1460. /*
  1461. * /proc/sys support
  1462. */
  1463. #ifdef CONFIG_PROC_SYSCTL
  1464. static int _proc_do_string(void* data, int maxlen, int write,
  1465. struct file *filp, void __user *buffer,
  1466. size_t *lenp, loff_t *ppos)
  1467. {
  1468. size_t len;
  1469. char __user *p;
  1470. char c;
  1471. if (!data || !maxlen || !*lenp) {
  1472. *lenp = 0;
  1473. return 0;
  1474. }
  1475. if (write) {
  1476. len = 0;
  1477. p = buffer;
  1478. while (len < *lenp) {
  1479. if (get_user(c, p++))
  1480. return -EFAULT;
  1481. if (c == 0 || c == '\n')
  1482. break;
  1483. len++;
  1484. }
  1485. if (len >= maxlen)
  1486. len = maxlen-1;
  1487. if(copy_from_user(data, buffer, len))
  1488. return -EFAULT;
  1489. ((char *) data)[len] = 0;
  1490. *ppos += *lenp;
  1491. } else {
  1492. len = strlen(data);
  1493. if (len > maxlen)
  1494. len = maxlen;
  1495. if (*ppos > len) {
  1496. *lenp = 0;
  1497. return 0;
  1498. }
  1499. data += *ppos;
  1500. len -= *ppos;
  1501. if (len > *lenp)
  1502. len = *lenp;
  1503. if (len)
  1504. if(copy_to_user(buffer, data, len))
  1505. return -EFAULT;
  1506. if (len < *lenp) {
  1507. if(put_user('\n', ((char __user *) buffer) + len))
  1508. return -EFAULT;
  1509. len++;
  1510. }
  1511. *lenp = len;
  1512. *ppos += len;
  1513. }
  1514. return 0;
  1515. }
  1516. /**
  1517. * proc_dostring - read a string sysctl
  1518. * @table: the sysctl table
  1519. * @write: %TRUE if this is a write to the sysctl file
  1520. * @filp: the file structure
  1521. * @buffer: the user buffer
  1522. * @lenp: the size of the user buffer
  1523. * @ppos: file position
  1524. *
  1525. * Reads/writes a string from/to the user buffer. If the kernel
  1526. * buffer provided is not large enough to hold the string, the
  1527. * string is truncated. The copied string is %NULL-terminated.
  1528. * If the string is being read by the user process, it is copied
  1529. * and a newline '\n' is added. It is truncated if the buffer is
  1530. * not large enough.
  1531. *
  1532. * Returns 0 on success.
  1533. */
  1534. int proc_dostring(ctl_table *table, int write, struct file *filp,
  1535. void __user *buffer, size_t *lenp, loff_t *ppos)
  1536. {
  1537. return _proc_do_string(table->data, table->maxlen, write, filp,
  1538. buffer, lenp, ppos);
  1539. }
  1540. static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
  1541. int *valp,
  1542. int write, void *data)
  1543. {
  1544. if (write) {
  1545. *valp = *negp ? -*lvalp : *lvalp;
  1546. } else {
  1547. int val = *valp;
  1548. if (val < 0) {
  1549. *negp = -1;
  1550. *lvalp = (unsigned long)-val;
  1551. } else {
  1552. *negp = 0;
  1553. *lvalp = (unsigned long)val;
  1554. }
  1555. }
  1556. return 0;
  1557. }
  1558. static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
  1559. int write, struct file *filp, void __user *buffer,
  1560. size_t *lenp, loff_t *ppos,
  1561. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1562. int write, void *data),
  1563. void *data)
  1564. {
  1565. #define TMPBUFLEN 21
  1566. int *i, vleft, first=1, neg, val;
  1567. unsigned long lval;
  1568. size_t left, len;
  1569. char buf[TMPBUFLEN], *p;
  1570. char __user *s = buffer;
  1571. if (!tbl_data || !table->maxlen || !*lenp ||
  1572. (*ppos && !write)) {
  1573. *lenp = 0;
  1574. return 0;
  1575. }
  1576. i = (int *) tbl_data;
  1577. vleft = table->maxlen / sizeof(*i);
  1578. left = *lenp;
  1579. if (!conv)
  1580. conv = do_proc_dointvec_conv;
  1581. for (; left && vleft--; i++, first=0) {
  1582. if (write) {
  1583. while (left) {
  1584. char c;
  1585. if (get_user(c, s))
  1586. return -EFAULT;
  1587. if (!isspace(c))
  1588. break;
  1589. left--;
  1590. s++;
  1591. }
  1592. if (!left)
  1593. break;
  1594. neg = 0;
  1595. len = left;
  1596. if (len > sizeof(buf) - 1)
  1597. len = sizeof(buf) - 1;
  1598. if (copy_from_user(buf, s, len))
  1599. return -EFAULT;
  1600. buf[len] = 0;
  1601. p = buf;
  1602. if (*p == '-' && left > 1) {
  1603. neg = 1;
  1604. p++;
  1605. }
  1606. if (*p < '0' || *p > '9')
  1607. break;
  1608. lval = simple_strtoul(p, &p, 0);
  1609. len = p-buf;
  1610. if ((len < left) && *p && !isspace(*p))
  1611. break;
  1612. if (neg)
  1613. val = -val;
  1614. s += len;
  1615. left -= len;
  1616. if (conv(&neg, &lval, i, 1, data))
  1617. break;
  1618. } else {
  1619. p = buf;
  1620. if (!first)
  1621. *p++ = '\t';
  1622. if (conv(&neg, &lval, i, 0, data))
  1623. break;
  1624. sprintf(p, "%s%lu", neg ? "-" : "", lval);
  1625. len = strlen(buf);
  1626. if (len > left)
  1627. len = left;
  1628. if(copy_to_user(s, buf, len))
  1629. return -EFAULT;
  1630. left -= len;
  1631. s += len;
  1632. }
  1633. }
  1634. if (!write && !first && left) {
  1635. if(put_user('\n', s))
  1636. return -EFAULT;
  1637. left--, s++;
  1638. }
  1639. if (write) {
  1640. while (left) {
  1641. char c;
  1642. if (get_user(c, s++))
  1643. return -EFAULT;
  1644. if (!isspace(c))
  1645. break;
  1646. left--;
  1647. }
  1648. }
  1649. if (write && first)
  1650. return -EINVAL;
  1651. *lenp -= left;
  1652. *ppos += *lenp;
  1653. return 0;
  1654. #undef TMPBUFLEN
  1655. }
  1656. static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
  1657. void __user *buffer, size_t *lenp, loff_t *ppos,
  1658. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1659. int write, void *data),
  1660. void *data)
  1661. {
  1662. return __do_proc_dointvec(table->data, table, write, filp,
  1663. buffer, lenp, ppos, conv, data);
  1664. }
  1665. /**
  1666. * proc_dointvec - read a vector of integers
  1667. * @table: the sysctl table
  1668. * @write: %TRUE if this is a write to the sysctl file
  1669. * @filp: the file structure
  1670. * @buffer: the user buffer
  1671. * @lenp: the size of the user buffer
  1672. * @ppos: file position
  1673. *
  1674. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1675. * values from/to the user buffer, treated as an ASCII string.
  1676. *
  1677. * Returns 0 on success.
  1678. */
  1679. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  1680. void __user *buffer, size_t *lenp, loff_t *ppos)
  1681. {
  1682. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1683. NULL,NULL);
  1684. }
  1685. #define OP_SET 0
  1686. #define OP_AND 1
  1687. #define OP_OR 2
  1688. static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
  1689. int *valp,
  1690. int write, void *data)
  1691. {
  1692. int op = *(int *)data;
  1693. if (write) {
  1694. int val = *negp ? -*lvalp : *lvalp;
  1695. switch(op) {
  1696. case OP_SET: *valp = val; break;
  1697. case OP_AND: *valp &= val; break;
  1698. case OP_OR: *valp |= val; break;
  1699. }
  1700. } else {
  1701. int val = *valp;
  1702. if (val < 0) {
  1703. *negp = -1;
  1704. *lvalp = (unsigned long)-val;
  1705. } else {
  1706. *negp = 0;
  1707. *lvalp = (unsigned long)val;
  1708. }
  1709. }
  1710. return 0;
  1711. }
  1712. /*
  1713. * init may raise the set.
  1714. */
  1715. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  1716. void __user *buffer, size_t *lenp, loff_t *ppos)
  1717. {
  1718. int op;
  1719. if (write && !capable(CAP_SYS_MODULE)) {
  1720. return -EPERM;
  1721. }
  1722. op = is_init(current) ? OP_SET : OP_AND;
  1723. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1724. do_proc_dointvec_bset_conv,&op);
  1725. }
  1726. /*
  1727. * Taint values can only be increased
  1728. */
  1729. static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
  1730. void __user *buffer, size_t *lenp, loff_t *ppos)
  1731. {
  1732. int op;
  1733. if (write && !capable(CAP_SYS_ADMIN))
  1734. return -EPERM;
  1735. op = OP_OR;
  1736. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1737. do_proc_dointvec_bset_conv,&op);
  1738. }
  1739. struct do_proc_dointvec_minmax_conv_param {
  1740. int *min;
  1741. int *max;
  1742. };
  1743. static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
  1744. int *valp,
  1745. int write, void *data)
  1746. {
  1747. struct do_proc_dointvec_minmax_conv_param *param = data;
  1748. if (write) {
  1749. int val = *negp ? -*lvalp : *lvalp;
  1750. if ((param->min && *param->min > val) ||
  1751. (param->max && *param->max < val))
  1752. return -EINVAL;
  1753. *valp = val;
  1754. } else {
  1755. int val = *valp;
  1756. if (val < 0) {
  1757. *negp = -1;
  1758. *lvalp = (unsigned long)-val;
  1759. } else {
  1760. *negp = 0;
  1761. *lvalp = (unsigned long)val;
  1762. }
  1763. }
  1764. return 0;
  1765. }
  1766. /**
  1767. * proc_dointvec_minmax - read a vector of integers with min/max values
  1768. * @table: the sysctl table
  1769. * @write: %TRUE if this is a write to the sysctl file
  1770. * @filp: the file structure
  1771. * @buffer: the user buffer
  1772. * @lenp: the size of the user buffer
  1773. * @ppos: file position
  1774. *
  1775. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1776. * values from/to the user buffer, treated as an ASCII string.
  1777. *
  1778. * This routine will ensure the values are within the range specified by
  1779. * table->extra1 (min) and table->extra2 (max).
  1780. *
  1781. * Returns 0 on success.
  1782. */
  1783. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  1784. void __user *buffer, size_t *lenp, loff_t *ppos)
  1785. {
  1786. struct do_proc_dointvec_minmax_conv_param param = {
  1787. .min = (int *) table->extra1,
  1788. .max = (int *) table->extra2,
  1789. };
  1790. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  1791. do_proc_dointvec_minmax_conv, &param);
  1792. }
  1793. static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
  1794. struct file *filp,
  1795. void __user *buffer,
  1796. size_t *lenp, loff_t *ppos,
  1797. unsigned long convmul,
  1798. unsigned long convdiv)
  1799. {
  1800. #define TMPBUFLEN 21
  1801. unsigned long *i, *min, *max, val;
  1802. int vleft, first=1, neg;
  1803. size_t len, left;
  1804. char buf[TMPBUFLEN], *p;
  1805. char __user *s = buffer;
  1806. if (!data || !table->maxlen || !*lenp ||
  1807. (*ppos && !write)) {
  1808. *lenp = 0;
  1809. return 0;
  1810. }
  1811. i = (unsigned long *) data;
  1812. min = (unsigned long *) table->extra1;
  1813. max = (unsigned long *) table->extra2;
  1814. vleft = table->maxlen / sizeof(unsigned long);
  1815. left = *lenp;
  1816. for (; left && vleft--; i++, min++, max++, first=0) {
  1817. if (write) {
  1818. while (left) {
  1819. char c;
  1820. if (get_user(c, s))
  1821. return -EFAULT;
  1822. if (!isspace(c))
  1823. break;
  1824. left--;
  1825. s++;
  1826. }
  1827. if (!left)
  1828. break;
  1829. neg = 0;
  1830. len = left;
  1831. if (len > TMPBUFLEN-1)
  1832. len = TMPBUFLEN-1;
  1833. if (copy_from_user(buf, s, len))
  1834. return -EFAULT;
  1835. buf[len] = 0;
  1836. p = buf;
  1837. if (*p == '-' && left > 1) {
  1838. neg = 1;
  1839. p++;
  1840. }
  1841. if (*p < '0' || *p > '9')
  1842. break;
  1843. val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
  1844. len = p-buf;
  1845. if ((len < left) && *p && !isspace(*p))
  1846. break;
  1847. if (neg)
  1848. val = -val;
  1849. s += len;
  1850. left -= len;
  1851. if(neg)
  1852. continue;
  1853. if ((min && val < *min) || (max && val > *max))
  1854. continue;
  1855. *i = val;
  1856. } else {
  1857. p = buf;
  1858. if (!first)
  1859. *p++ = '\t';
  1860. sprintf(p, "%lu", convdiv * (*i) / convmul);
  1861. len = strlen(buf);
  1862. if (len > left)
  1863. len = left;
  1864. if(copy_to_user(s, buf, len))
  1865. return -EFAULT;
  1866. left -= len;
  1867. s += len;
  1868. }
  1869. }
  1870. if (!write && !first && left) {
  1871. if(put_user('\n', s))
  1872. return -EFAULT;
  1873. left--, s++;
  1874. }
  1875. if (write) {
  1876. while (left) {
  1877. char c;
  1878. if (get_user(c, s++))
  1879. return -EFAULT;
  1880. if (!isspace(c))
  1881. break;
  1882. left--;
  1883. }
  1884. }
  1885. if (write && first)
  1886. return -EINVAL;
  1887. *lenp -= left;
  1888. *ppos += *lenp;
  1889. return 0;
  1890. #undef TMPBUFLEN
  1891. }
  1892. static int do_proc_doulongvec_minmax(ctl_table *table, int write,
  1893. struct file *filp,
  1894. void __user *buffer,
  1895. size_t *lenp, loff_t *ppos,
  1896. unsigned long convmul,
  1897. unsigned long convdiv)
  1898. {
  1899. return __do_proc_doulongvec_minmax(table->data, table, write,
  1900. filp, buffer, lenp, ppos, convmul, convdiv);
  1901. }
  1902. /**
  1903. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  1904. * @table: the sysctl table
  1905. * @write: %TRUE if this is a write to the sysctl file
  1906. * @filp: the file structure
  1907. * @buffer: the user buffer
  1908. * @lenp: the size of the user buffer
  1909. * @ppos: file position
  1910. *
  1911. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1912. * values from/to the user buffer, treated as an ASCII string.
  1913. *
  1914. * This routine will ensure the values are within the range specified by
  1915. * table->extra1 (min) and table->extra2 (max).
  1916. *
  1917. * Returns 0 on success.
  1918. */
  1919. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  1920. void __user *buffer, size_t *lenp, loff_t *ppos)
  1921. {
  1922. return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
  1923. }
  1924. /**
  1925. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  1926. * @table: the sysctl table
  1927. * @write: %TRUE if this is a write to the sysctl file
  1928. * @filp: the file structure
  1929. * @buffer: the user buffer
  1930. * @lenp: the size of the user buffer
  1931. * @ppos: file position
  1932. *
  1933. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1934. * values from/to the user buffer, treated as an ASCII string. The values
  1935. * are treated as milliseconds, and converted to jiffies when they are stored.
  1936. *
  1937. * This routine will ensure the values are within the range specified by
  1938. * table->extra1 (min) and table->extra2 (max).
  1939. *
  1940. * Returns 0 on success.
  1941. */
  1942. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  1943. struct file *filp,
  1944. void __user *buffer,
  1945. size_t *lenp, loff_t *ppos)
  1946. {
  1947. return do_proc_doulongvec_minmax(table, write, filp, buffer,
  1948. lenp, ppos, HZ, 1000l);
  1949. }
  1950. static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
  1951. int *valp,
  1952. int write, void *data)
  1953. {
  1954. if (write) {
  1955. if (*lvalp > LONG_MAX / HZ)
  1956. return 1;
  1957. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  1958. } else {
  1959. int val = *valp;
  1960. unsigned long lval;
  1961. if (val < 0) {
  1962. *negp = -1;
  1963. lval = (unsigned long)-val;
  1964. } else {
  1965. *negp = 0;
  1966. lval = (unsigned long)val;
  1967. }
  1968. *lvalp = lval / HZ;
  1969. }
  1970. return 0;
  1971. }
  1972. static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
  1973. int *valp,
  1974. int write, void *data)
  1975. {
  1976. if (write) {
  1977. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  1978. return 1;
  1979. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  1980. } else {
  1981. int val = *valp;
  1982. unsigned long lval;
  1983. if (val < 0) {
  1984. *negp = -1;
  1985. lval = (unsigned long)-val;
  1986. } else {
  1987. *negp = 0;
  1988. lval = (unsigned long)val;
  1989. }
  1990. *lvalp = jiffies_to_clock_t(lval);
  1991. }
  1992. return 0;
  1993. }
  1994. static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
  1995. int *valp,
  1996. int write, void *data)
  1997. {
  1998. if (write) {
  1999. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  2000. } else {
  2001. int val = *valp;
  2002. unsigned long lval;
  2003. if (val < 0) {
  2004. *negp = -1;
  2005. lval = (unsigned long)-val;
  2006. } else {
  2007. *negp = 0;
  2008. lval = (unsigned long)val;
  2009. }
  2010. *lvalp = jiffies_to_msecs(lval);
  2011. }
  2012. return 0;
  2013. }
  2014. /**
  2015. * proc_dointvec_jiffies - read a vector of integers as seconds
  2016. * @table: the sysctl table
  2017. * @write: %TRUE if this is a write to the sysctl file
  2018. * @filp: the file structure
  2019. * @buffer: the user buffer
  2020. * @lenp: the size of the user buffer
  2021. * @ppos: file position
  2022. *
  2023. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2024. * values from/to the user buffer, treated as an ASCII string.
  2025. * The values read are assumed to be in seconds, and are converted into
  2026. * jiffies.
  2027. *
  2028. * Returns 0 on success.
  2029. */
  2030. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2031. void __user *buffer, size_t *lenp, loff_t *ppos)
  2032. {
  2033. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2034. do_proc_dointvec_jiffies_conv,NULL);
  2035. }
  2036. /**
  2037. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  2038. * @table: the sysctl table
  2039. * @write: %TRUE if this is a write to the sysctl file
  2040. * @filp: the file structure
  2041. * @buffer: the user buffer
  2042. * @lenp: the size of the user buffer
  2043. * @ppos: pointer to the file position
  2044. *
  2045. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2046. * values from/to the user buffer, treated as an ASCII string.
  2047. * The values read are assumed to be in 1/USER_HZ seconds, and
  2048. * are converted into jiffies.
  2049. *
  2050. * Returns 0 on success.
  2051. */
  2052. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2053. void __user *buffer, size_t *lenp, loff_t *ppos)
  2054. {
  2055. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2056. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2057. }
  2058. /**
  2059. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2060. * @table: the sysctl table
  2061. * @write: %TRUE if this is a write to the sysctl file
  2062. * @filp: the file structure
  2063. * @buffer: the user buffer
  2064. * @lenp: the size of the user buffer
  2065. * @ppos: file position
  2066. * @ppos: the current position in the file
  2067. *
  2068. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2069. * values from/to the user buffer, treated as an ASCII string.
  2070. * The values read are assumed to be in 1/1000 seconds, and
  2071. * are converted into jiffies.
  2072. *
  2073. * Returns 0 on success.
  2074. */
  2075. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2076. void __user *buffer, size_t *lenp, loff_t *ppos)
  2077. {
  2078. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  2079. do_proc_dointvec_ms_jiffies_conv, NULL);
  2080. }
  2081. static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
  2082. void __user *buffer, size_t *lenp, loff_t *ppos)
  2083. {
  2084. struct pid *new_pid;
  2085. pid_t tmp;
  2086. int r;
  2087. tmp = pid_nr(cad_pid);
  2088. r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
  2089. lenp, ppos, NULL, NULL);
  2090. if (r || !write)
  2091. return r;
  2092. new_pid = find_get_pid(tmp);
  2093. if (!new_pid)
  2094. return -ESRCH;
  2095. put_pid(xchg(&cad_pid, new_pid));
  2096. return 0;
  2097. }
  2098. #else /* CONFIG_PROC_FS */
  2099. int proc_dostring(ctl_table *table, int write, struct file *filp,
  2100. void __user *buffer, size_t *lenp, loff_t *ppos)
  2101. {
  2102. return -ENOSYS;
  2103. }
  2104. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2105. void __user *buffer, size_t *lenp, loff_t *ppos)
  2106. {
  2107. return -ENOSYS;
  2108. }
  2109. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2110. void __user *buffer, size_t *lenp, loff_t *ppos)
  2111. {
  2112. return -ENOSYS;
  2113. }
  2114. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2115. void __user *buffer, size_t *lenp, loff_t *ppos)
  2116. {
  2117. return -ENOSYS;
  2118. }
  2119. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2120. void __user *buffer, size_t *lenp, loff_t *ppos)
  2121. {
  2122. return -ENOSYS;
  2123. }
  2124. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2125. void __user *buffer, size_t *lenp, loff_t *ppos)
  2126. {
  2127. return -ENOSYS;
  2128. }
  2129. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2130. void __user *buffer, size_t *lenp, loff_t *ppos)
  2131. {
  2132. return -ENOSYS;
  2133. }
  2134. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2135. void __user *buffer, size_t *lenp, loff_t *ppos)
  2136. {
  2137. return -ENOSYS;
  2138. }
  2139. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2140. struct file *filp,
  2141. void __user *buffer,
  2142. size_t *lenp, loff_t *ppos)
  2143. {
  2144. return -ENOSYS;
  2145. }
  2146. #endif /* CONFIG_PROC_FS */
  2147. #ifdef CONFIG_SYSCTL_SYSCALL
  2148. /*
  2149. * General sysctl support routines
  2150. */
  2151. /* The generic string strategy routine: */
  2152. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2153. void __user *oldval, size_t __user *oldlenp,
  2154. void __user *newval, size_t newlen)
  2155. {
  2156. if (!table->data || !table->maxlen)
  2157. return -ENOTDIR;
  2158. if (oldval && oldlenp) {
  2159. size_t bufsize;
  2160. if (get_user(bufsize, oldlenp))
  2161. return -EFAULT;
  2162. if (bufsize) {
  2163. size_t len = strlen(table->data), copied;
  2164. /* This shouldn't trigger for a well-formed sysctl */
  2165. if (len > table->maxlen)
  2166. len = table->maxlen;
  2167. /* Copy up to a max of bufsize-1 bytes of the string */
  2168. copied = (len >= bufsize) ? bufsize - 1 : len;
  2169. if (copy_to_user(oldval, table->data, copied) ||
  2170. put_user(0, (char __user *)(oldval + copied)))
  2171. return -EFAULT;
  2172. if (put_user(len, oldlenp))
  2173. return -EFAULT;
  2174. }
  2175. }
  2176. if (newval && newlen) {
  2177. size_t len = newlen;
  2178. if (len > table->maxlen)
  2179. len = table->maxlen;
  2180. if(copy_from_user(table->data, newval, len))
  2181. return -EFAULT;
  2182. if (len == table->maxlen)
  2183. len--;
  2184. ((char *) table->data)[len] = 0;
  2185. }
  2186. return 1;
  2187. }
  2188. /*
  2189. * This function makes sure that all of the integers in the vector
  2190. * are between the minimum and maximum values given in the arrays
  2191. * table->extra1 and table->extra2, respectively.
  2192. */
  2193. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2194. void __user *oldval, size_t __user *oldlenp,
  2195. void __user *newval, size_t newlen)
  2196. {
  2197. if (newval && newlen) {
  2198. int __user *vec = (int __user *) newval;
  2199. int *min = (int *) table->extra1;
  2200. int *max = (int *) table->extra2;
  2201. size_t length;
  2202. int i;
  2203. if (newlen % sizeof(int) != 0)
  2204. return -EINVAL;
  2205. if (!table->extra1 && !table->extra2)
  2206. return 0;
  2207. if (newlen > table->maxlen)
  2208. newlen = table->maxlen;
  2209. length = newlen / sizeof(int);
  2210. for (i = 0; i < length; i++) {
  2211. int value;
  2212. if (get_user(value, vec + i))
  2213. return -EFAULT;
  2214. if (min && value < min[i])
  2215. return -EINVAL;
  2216. if (max && value > max[i])
  2217. return -EINVAL;
  2218. }
  2219. }
  2220. return 0;
  2221. }
  2222. /* Strategy function to convert jiffies to seconds */
  2223. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2224. void __user *oldval, size_t __user *oldlenp,
  2225. void __user *newval, size_t newlen)
  2226. {
  2227. if (oldval && oldlenp) {
  2228. size_t olen;
  2229. if (get_user(olen, oldlenp))
  2230. return -EFAULT;
  2231. if (olen) {
  2232. int val;
  2233. if (olen < sizeof(int))
  2234. return -EINVAL;
  2235. val = *(int *)(table->data) / HZ;
  2236. if (put_user(val, (int __user *)oldval))
  2237. return -EFAULT;
  2238. if (put_user(sizeof(int), oldlenp))
  2239. return -EFAULT;
  2240. }
  2241. }
  2242. if (newval && newlen) {
  2243. int new;
  2244. if (newlen != sizeof(int))
  2245. return -EINVAL;
  2246. if (get_user(new, (int __user *)newval))
  2247. return -EFAULT;
  2248. *(int *)(table->data) = new*HZ;
  2249. }
  2250. return 1;
  2251. }
  2252. /* Strategy function to convert jiffies to seconds */
  2253. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2254. void __user *oldval, size_t __user *oldlenp,
  2255. void __user *newval, size_t newlen)
  2256. {
  2257. if (oldval && oldlenp) {
  2258. size_t olen;
  2259. if (get_user(olen, oldlenp))
  2260. return -EFAULT;
  2261. if (olen) {
  2262. int val;
  2263. if (olen < sizeof(int))
  2264. return -EINVAL;
  2265. val = jiffies_to_msecs(*(int *)(table->data));
  2266. if (put_user(val, (int __user *)oldval))
  2267. return -EFAULT;
  2268. if (put_user(sizeof(int), oldlenp))
  2269. return -EFAULT;
  2270. }
  2271. }
  2272. if (newval && newlen) {
  2273. int new;
  2274. if (newlen != sizeof(int))
  2275. return -EINVAL;
  2276. if (get_user(new, (int __user *)newval))
  2277. return -EFAULT;
  2278. *(int *)(table->data) = msecs_to_jiffies(new);
  2279. }
  2280. return 1;
  2281. }
  2282. #else /* CONFIG_SYSCTL_SYSCALL */
  2283. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  2284. {
  2285. static int msg_count;
  2286. struct __sysctl_args tmp;
  2287. int name[CTL_MAXNAME];
  2288. int i;
  2289. /* Read in the sysctl name for better debug message logging */
  2290. if (copy_from_user(&tmp, args, sizeof(tmp)))
  2291. return -EFAULT;
  2292. if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
  2293. return -ENOTDIR;
  2294. for (i = 0; i < tmp.nlen; i++)
  2295. if (get_user(name[i], tmp.name + i))
  2296. return -EFAULT;
  2297. /* Ignore accesses to kernel.version */
  2298. if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
  2299. goto out;
  2300. if (msg_count < 5) {
  2301. msg_count++;
  2302. printk(KERN_INFO
  2303. "warning: process `%s' used the removed sysctl "
  2304. "system call with ", current->comm);
  2305. for (i = 0; i < tmp.nlen; i++)
  2306. printk("%d.", name[i]);
  2307. printk("\n");
  2308. }
  2309. out:
  2310. return -ENOSYS;
  2311. }
  2312. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2313. void __user *oldval, size_t __user *oldlenp,
  2314. void __user *newval, size_t newlen)
  2315. {
  2316. return -ENOSYS;
  2317. }
  2318. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2319. void __user *oldval, size_t __user *oldlenp,
  2320. void __user *newval, size_t newlen)
  2321. {
  2322. return -ENOSYS;
  2323. }
  2324. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2325. void __user *oldval, size_t __user *oldlenp,
  2326. void __user *newval, size_t newlen)
  2327. {
  2328. return -ENOSYS;
  2329. }
  2330. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2331. void __user *oldval, size_t __user *oldlenp,
  2332. void __user *newval, size_t newlen)
  2333. {
  2334. return -ENOSYS;
  2335. }
  2336. #endif /* CONFIG_SYSCTL_SYSCALL */
  2337. /*
  2338. * No sense putting this after each symbol definition, twice,
  2339. * exception granted :-)
  2340. */
  2341. EXPORT_SYMBOL(proc_dointvec);
  2342. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2343. EXPORT_SYMBOL(proc_dointvec_minmax);
  2344. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2345. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2346. EXPORT_SYMBOL(proc_dostring);
  2347. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2348. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2349. EXPORT_SYMBOL(register_sysctl_table);
  2350. EXPORT_SYMBOL(sysctl_intvec);
  2351. EXPORT_SYMBOL(sysctl_jiffies);
  2352. EXPORT_SYMBOL(sysctl_ms_jiffies);
  2353. EXPORT_SYMBOL(sysctl_string);
  2354. EXPORT_SYMBOL(unregister_sysctl_table);