sysctl.c 62 KB

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