sysctl.c 68 KB

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