sysctl.c 71 KB

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