sysctl.c 72 KB

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