sysctl.c 68 KB

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