sysctl.c 68 KB

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