sysctl.c 73 KB

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