sysctl.c 68 KB

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