sysctl.c 68 KB

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