sysctl.c 68 KB

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