sysctl.c 58 KB

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