sysctl.c 76 KB

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