sysctl.c 74 KB

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