sysctl.c 68 KB

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