sysctl.c 64 KB

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