sysctl.c 71 KB

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