sysctl.c 68 KB

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