sysctl.c 59 KB

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