sysctl.c 71 KB

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