sysctl.c 76 KB

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