sysctl.c 72 KB

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