sysctl.c 74 KB

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