sysctl.c 69 KB

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