sysctl.c 69 KB

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