sysctl.c 69 KB

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