sysctl.c 68 KB

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