sysctl.c 76 KB

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