sysctl.c 55 KB

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