sysctl.c 74 KB

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