sysctl.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475
  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. #if defined(CONFIG_X86_32) || \
  921. (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
  922. {
  923. .ctl_name = VM_VDSO_ENABLED,
  924. .procname = "vdso_enabled",
  925. .data = &vdso_enabled,
  926. .maxlen = sizeof(vdso_enabled),
  927. .mode = 0644,
  928. .proc_handler = &proc_dointvec,
  929. .strategy = &sysctl_intvec,
  930. .extra1 = &zero,
  931. },
  932. #endif
  933. { .ctl_name = 0 }
  934. };
  935. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  936. static ctl_table binfmt_misc_table[] = {
  937. { .ctl_name = 0 }
  938. };
  939. #endif
  940. static ctl_table fs_table[] = {
  941. {
  942. .ctl_name = FS_NRINODE,
  943. .procname = "inode-nr",
  944. .data = &inodes_stat,
  945. .maxlen = 2*sizeof(int),
  946. .mode = 0444,
  947. .proc_handler = &proc_dointvec,
  948. },
  949. {
  950. .ctl_name = FS_STATINODE,
  951. .procname = "inode-state",
  952. .data = &inodes_stat,
  953. .maxlen = 7*sizeof(int),
  954. .mode = 0444,
  955. .proc_handler = &proc_dointvec,
  956. },
  957. {
  958. .ctl_name = FS_NRFILE,
  959. .procname = "file-nr",
  960. .data = &files_stat,
  961. .maxlen = 3*sizeof(int),
  962. .mode = 0444,
  963. .proc_handler = &proc_nr_files,
  964. },
  965. {
  966. .ctl_name = FS_MAXFILE,
  967. .procname = "file-max",
  968. .data = &files_stat.max_files,
  969. .maxlen = sizeof(int),
  970. .mode = 0644,
  971. .proc_handler = &proc_dointvec,
  972. },
  973. {
  974. .ctl_name = FS_DENTRY,
  975. .procname = "dentry-state",
  976. .data = &dentry_stat,
  977. .maxlen = 6*sizeof(int),
  978. .mode = 0444,
  979. .proc_handler = &proc_dointvec,
  980. },
  981. {
  982. .ctl_name = FS_OVERFLOWUID,
  983. .procname = "overflowuid",
  984. .data = &fs_overflowuid,
  985. .maxlen = sizeof(int),
  986. .mode = 0644,
  987. .proc_handler = &proc_dointvec_minmax,
  988. .strategy = &sysctl_intvec,
  989. .extra1 = &minolduid,
  990. .extra2 = &maxolduid,
  991. },
  992. {
  993. .ctl_name = FS_OVERFLOWGID,
  994. .procname = "overflowgid",
  995. .data = &fs_overflowgid,
  996. .maxlen = sizeof(int),
  997. .mode = 0644,
  998. .proc_handler = &proc_dointvec_minmax,
  999. .strategy = &sysctl_intvec,
  1000. .extra1 = &minolduid,
  1001. .extra2 = &maxolduid,
  1002. },
  1003. {
  1004. .ctl_name = FS_LEASES,
  1005. .procname = "leases-enable",
  1006. .data = &leases_enable,
  1007. .maxlen = sizeof(int),
  1008. .mode = 0644,
  1009. .proc_handler = &proc_dointvec,
  1010. },
  1011. #ifdef CONFIG_DNOTIFY
  1012. {
  1013. .ctl_name = FS_DIR_NOTIFY,
  1014. .procname = "dir-notify-enable",
  1015. .data = &dir_notify_enable,
  1016. .maxlen = sizeof(int),
  1017. .mode = 0644,
  1018. .proc_handler = &proc_dointvec,
  1019. },
  1020. #endif
  1021. #ifdef CONFIG_MMU
  1022. {
  1023. .ctl_name = FS_LEASE_TIME,
  1024. .procname = "lease-break-time",
  1025. .data = &lease_break_time,
  1026. .maxlen = sizeof(int),
  1027. .mode = 0644,
  1028. .proc_handler = &proc_dointvec,
  1029. },
  1030. {
  1031. .ctl_name = FS_AIO_NR,
  1032. .procname = "aio-nr",
  1033. .data = &aio_nr,
  1034. .maxlen = sizeof(aio_nr),
  1035. .mode = 0444,
  1036. .proc_handler = &proc_doulongvec_minmax,
  1037. },
  1038. {
  1039. .ctl_name = FS_AIO_MAX_NR,
  1040. .procname = "aio-max-nr",
  1041. .data = &aio_max_nr,
  1042. .maxlen = sizeof(aio_max_nr),
  1043. .mode = 0644,
  1044. .proc_handler = &proc_doulongvec_minmax,
  1045. },
  1046. #ifdef CONFIG_INOTIFY_USER
  1047. {
  1048. .ctl_name = FS_INOTIFY,
  1049. .procname = "inotify",
  1050. .mode = 0555,
  1051. .child = inotify_table,
  1052. },
  1053. #endif
  1054. #endif
  1055. {
  1056. .ctl_name = KERN_SETUID_DUMPABLE,
  1057. .procname = "suid_dumpable",
  1058. .data = &suid_dumpable,
  1059. .maxlen = sizeof(int),
  1060. .mode = 0644,
  1061. .proc_handler = &proc_dointvec,
  1062. },
  1063. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1064. {
  1065. .ctl_name = CTL_UNNUMBERED,
  1066. .procname = "binfmt_misc",
  1067. .mode = 0555,
  1068. .child = binfmt_misc_table,
  1069. },
  1070. #endif
  1071. { .ctl_name = 0 }
  1072. };
  1073. static ctl_table debug_table[] = {
  1074. { .ctl_name = 0 }
  1075. };
  1076. static ctl_table dev_table[] = {
  1077. { .ctl_name = 0 }
  1078. };
  1079. static DEFINE_SPINLOCK(sysctl_lock);
  1080. /* called under sysctl_lock */
  1081. static int use_table(struct ctl_table_header *p)
  1082. {
  1083. if (unlikely(p->unregistering))
  1084. return 0;
  1085. p->used++;
  1086. return 1;
  1087. }
  1088. /* called under sysctl_lock */
  1089. static void unuse_table(struct ctl_table_header *p)
  1090. {
  1091. if (!--p->used)
  1092. if (unlikely(p->unregistering))
  1093. complete(p->unregistering);
  1094. }
  1095. /* called under sysctl_lock, will reacquire if has to wait */
  1096. static void start_unregistering(struct ctl_table_header *p)
  1097. {
  1098. /*
  1099. * if p->used is 0, nobody will ever touch that entry again;
  1100. * we'll eliminate all paths to it before dropping sysctl_lock
  1101. */
  1102. if (unlikely(p->used)) {
  1103. struct completion wait;
  1104. init_completion(&wait);
  1105. p->unregistering = &wait;
  1106. spin_unlock(&sysctl_lock);
  1107. wait_for_completion(&wait);
  1108. spin_lock(&sysctl_lock);
  1109. }
  1110. /*
  1111. * do not remove from the list until nobody holds it; walking the
  1112. * list in do_sysctl() relies on that.
  1113. */
  1114. list_del_init(&p->ctl_entry);
  1115. }
  1116. void sysctl_head_finish(struct ctl_table_header *head)
  1117. {
  1118. if (!head)
  1119. return;
  1120. spin_lock(&sysctl_lock);
  1121. unuse_table(head);
  1122. spin_unlock(&sysctl_lock);
  1123. }
  1124. struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
  1125. {
  1126. struct ctl_table_header *head;
  1127. struct list_head *tmp;
  1128. spin_lock(&sysctl_lock);
  1129. if (prev) {
  1130. tmp = &prev->ctl_entry;
  1131. unuse_table(prev);
  1132. goto next;
  1133. }
  1134. tmp = &root_table_header.ctl_entry;
  1135. for (;;) {
  1136. head = list_entry(tmp, struct ctl_table_header, ctl_entry);
  1137. if (!use_table(head))
  1138. goto next;
  1139. spin_unlock(&sysctl_lock);
  1140. return head;
  1141. next:
  1142. tmp = tmp->next;
  1143. if (tmp == &root_table_header.ctl_entry)
  1144. break;
  1145. }
  1146. spin_unlock(&sysctl_lock);
  1147. return NULL;
  1148. }
  1149. #ifdef CONFIG_SYSCTL_SYSCALL
  1150. int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
  1151. void __user *newval, size_t newlen)
  1152. {
  1153. struct ctl_table_header *head;
  1154. int error = -ENOTDIR;
  1155. if (nlen <= 0 || nlen >= CTL_MAXNAME)
  1156. return -ENOTDIR;
  1157. if (oldval) {
  1158. int old_len;
  1159. if (!oldlenp || get_user(old_len, oldlenp))
  1160. return -EFAULT;
  1161. }
  1162. for (head = sysctl_head_next(NULL); head;
  1163. head = sysctl_head_next(head)) {
  1164. error = parse_table(name, nlen, oldval, oldlenp,
  1165. newval, newlen, head->ctl_table);
  1166. if (error != -ENOTDIR) {
  1167. sysctl_head_finish(head);
  1168. break;
  1169. }
  1170. }
  1171. return error;
  1172. }
  1173. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  1174. {
  1175. struct __sysctl_args tmp;
  1176. int error;
  1177. if (copy_from_user(&tmp, args, sizeof(tmp)))
  1178. return -EFAULT;
  1179. lock_kernel();
  1180. error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
  1181. tmp.newval, tmp.newlen);
  1182. unlock_kernel();
  1183. return error;
  1184. }
  1185. #endif /* CONFIG_SYSCTL_SYSCALL */
  1186. /*
  1187. * sysctl_perm does NOT grant the superuser all rights automatically, because
  1188. * some sysctl variables are readonly even to root.
  1189. */
  1190. static int test_perm(int mode, int op)
  1191. {
  1192. if (!current->euid)
  1193. mode >>= 6;
  1194. else if (in_egroup_p(0))
  1195. mode >>= 3;
  1196. if ((mode & op & 0007) == op)
  1197. return 0;
  1198. return -EACCES;
  1199. }
  1200. int sysctl_perm(ctl_table *table, int op)
  1201. {
  1202. int error;
  1203. error = security_sysctl(table, op);
  1204. if (error)
  1205. return error;
  1206. return test_perm(table->mode, op);
  1207. }
  1208. #ifdef CONFIG_SYSCTL_SYSCALL
  1209. static int parse_table(int __user *name, int nlen,
  1210. void __user *oldval, size_t __user *oldlenp,
  1211. void __user *newval, size_t newlen,
  1212. ctl_table *table)
  1213. {
  1214. int n;
  1215. repeat:
  1216. if (!nlen)
  1217. return -ENOTDIR;
  1218. if (get_user(n, name))
  1219. return -EFAULT;
  1220. for ( ; table->ctl_name || table->procname; table++) {
  1221. if (!table->ctl_name)
  1222. continue;
  1223. if (n == table->ctl_name) {
  1224. int error;
  1225. if (table->child) {
  1226. if (sysctl_perm(table, 001))
  1227. return -EPERM;
  1228. name++;
  1229. nlen--;
  1230. table = table->child;
  1231. goto repeat;
  1232. }
  1233. error = do_sysctl_strategy(table, name, nlen,
  1234. oldval, oldlenp,
  1235. newval, newlen);
  1236. return error;
  1237. }
  1238. }
  1239. return -ENOTDIR;
  1240. }
  1241. /* Perform the actual read/write of a sysctl table entry. */
  1242. int do_sysctl_strategy (ctl_table *table,
  1243. int __user *name, int nlen,
  1244. void __user *oldval, size_t __user *oldlenp,
  1245. void __user *newval, size_t newlen)
  1246. {
  1247. int op = 0, rc;
  1248. size_t len;
  1249. if (oldval)
  1250. op |= 004;
  1251. if (newval)
  1252. op |= 002;
  1253. if (sysctl_perm(table, op))
  1254. return -EPERM;
  1255. if (table->strategy) {
  1256. rc = table->strategy(table, name, nlen, oldval, oldlenp,
  1257. newval, newlen);
  1258. if (rc < 0)
  1259. return rc;
  1260. if (rc > 0)
  1261. return 0;
  1262. }
  1263. /* If there is no strategy routine, or if the strategy returns
  1264. * zero, proceed with automatic r/w */
  1265. if (table->data && table->maxlen) {
  1266. if (oldval && oldlenp) {
  1267. if (get_user(len, oldlenp))
  1268. return -EFAULT;
  1269. if (len) {
  1270. if (len > table->maxlen)
  1271. len = table->maxlen;
  1272. if(copy_to_user(oldval, table->data, len))
  1273. return -EFAULT;
  1274. if(put_user(len, oldlenp))
  1275. return -EFAULT;
  1276. }
  1277. }
  1278. if (newval && newlen) {
  1279. len = newlen;
  1280. if (len > table->maxlen)
  1281. len = table->maxlen;
  1282. if(copy_from_user(table->data, newval, len))
  1283. return -EFAULT;
  1284. }
  1285. }
  1286. return 0;
  1287. }
  1288. #endif /* CONFIG_SYSCTL_SYSCALL */
  1289. static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
  1290. {
  1291. for (; table->ctl_name || table->procname; table++) {
  1292. table->parent = parent;
  1293. if (table->child)
  1294. sysctl_set_parent(table, table->child);
  1295. }
  1296. }
  1297. static __init int sysctl_init(void)
  1298. {
  1299. sysctl_set_parent(NULL, root_table);
  1300. return 0;
  1301. }
  1302. core_initcall(sysctl_init);
  1303. /**
  1304. * register_sysctl_table - register a sysctl hierarchy
  1305. * @table: the top-level table structure
  1306. *
  1307. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1308. * array. An entry with a ctl_name of 0 terminates the table.
  1309. *
  1310. * The members of the &ctl_table structure are used as follows:
  1311. *
  1312. * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
  1313. * must be unique within that level of sysctl
  1314. *
  1315. * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
  1316. * enter a sysctl file
  1317. *
  1318. * data - a pointer to data for use by proc_handler
  1319. *
  1320. * maxlen - the maximum size in bytes of the data
  1321. *
  1322. * mode - the file permissions for the /proc/sys file, and for sysctl(2)
  1323. *
  1324. * child - a pointer to the child sysctl table if this entry is a directory, or
  1325. * %NULL.
  1326. *
  1327. * proc_handler - the text handler routine (described below)
  1328. *
  1329. * strategy - the strategy routine (described below)
  1330. *
  1331. * de - for internal use by the sysctl routines
  1332. *
  1333. * extra1, extra2 - extra pointers usable by the proc handler routines
  1334. *
  1335. * Leaf nodes in the sysctl tree will be represented by a single file
  1336. * under /proc; non-leaf nodes will be represented by directories.
  1337. *
  1338. * sysctl(2) can automatically manage read and write requests through
  1339. * the sysctl table. The data and maxlen fields of the ctl_table
  1340. * struct enable minimal validation of the values being written to be
  1341. * performed, and the mode field allows minimal authentication.
  1342. *
  1343. * More sophisticated management can be enabled by the provision of a
  1344. * strategy routine with the table entry. This will be called before
  1345. * any automatic read or write of the data is performed.
  1346. *
  1347. * The strategy routine may return
  1348. *
  1349. * < 0 - Error occurred (error is passed to user process)
  1350. *
  1351. * 0 - OK - proceed with automatic read or write.
  1352. *
  1353. * > 0 - OK - read or write has been done by the strategy routine, so
  1354. * return immediately.
  1355. *
  1356. * There must be a proc_handler routine for any terminal nodes
  1357. * mirrored under /proc/sys (non-terminals are handled by a built-in
  1358. * directory handler). Several default handlers are available to
  1359. * cover common cases -
  1360. *
  1361. * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
  1362. * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
  1363. * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
  1364. *
  1365. * It is the handler's job to read the input buffer from user memory
  1366. * and process it. The handler should return 0 on success.
  1367. *
  1368. * This routine returns %NULL on a failure to register, and a pointer
  1369. * to the table header on success.
  1370. */
  1371. struct ctl_table_header *register_sysctl_table(ctl_table * table)
  1372. {
  1373. struct ctl_table_header *tmp;
  1374. tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
  1375. if (!tmp)
  1376. return NULL;
  1377. tmp->ctl_table = table;
  1378. INIT_LIST_HEAD(&tmp->ctl_entry);
  1379. tmp->used = 0;
  1380. tmp->unregistering = NULL;
  1381. sysctl_set_parent(NULL, table);
  1382. spin_lock(&sysctl_lock);
  1383. list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1384. spin_unlock(&sysctl_lock);
  1385. return tmp;
  1386. }
  1387. /**
  1388. * unregister_sysctl_table - unregister a sysctl table hierarchy
  1389. * @header: the header returned from register_sysctl_table
  1390. *
  1391. * Unregisters the sysctl table and all children. proc entries may not
  1392. * actually be removed until they are no longer used by anyone.
  1393. */
  1394. void unregister_sysctl_table(struct ctl_table_header * header)
  1395. {
  1396. might_sleep();
  1397. spin_lock(&sysctl_lock);
  1398. start_unregistering(header);
  1399. spin_unlock(&sysctl_lock);
  1400. kfree(header);
  1401. }
  1402. #else /* !CONFIG_SYSCTL */
  1403. struct ctl_table_header *register_sysctl_table(ctl_table * table)
  1404. {
  1405. return NULL;
  1406. }
  1407. void unregister_sysctl_table(struct ctl_table_header * table)
  1408. {
  1409. }
  1410. #endif /* CONFIG_SYSCTL */
  1411. /*
  1412. * /proc/sys support
  1413. */
  1414. #ifdef CONFIG_PROC_SYSCTL
  1415. static int _proc_do_string(void* data, int maxlen, int write,
  1416. struct file *filp, void __user *buffer,
  1417. size_t *lenp, loff_t *ppos)
  1418. {
  1419. size_t len;
  1420. char __user *p;
  1421. char c;
  1422. if (!data || !maxlen || !*lenp) {
  1423. *lenp = 0;
  1424. return 0;
  1425. }
  1426. if (write) {
  1427. len = 0;
  1428. p = buffer;
  1429. while (len < *lenp) {
  1430. if (get_user(c, p++))
  1431. return -EFAULT;
  1432. if (c == 0 || c == '\n')
  1433. break;
  1434. len++;
  1435. }
  1436. if (len >= maxlen)
  1437. len = maxlen-1;
  1438. if(copy_from_user(data, buffer, len))
  1439. return -EFAULT;
  1440. ((char *) data)[len] = 0;
  1441. *ppos += *lenp;
  1442. } else {
  1443. len = strlen(data);
  1444. if (len > maxlen)
  1445. len = maxlen;
  1446. if (*ppos > len) {
  1447. *lenp = 0;
  1448. return 0;
  1449. }
  1450. data += *ppos;
  1451. len -= *ppos;
  1452. if (len > *lenp)
  1453. len = *lenp;
  1454. if (len)
  1455. if(copy_to_user(buffer, data, len))
  1456. return -EFAULT;
  1457. if (len < *lenp) {
  1458. if(put_user('\n', ((char __user *) buffer) + len))
  1459. return -EFAULT;
  1460. len++;
  1461. }
  1462. *lenp = len;
  1463. *ppos += len;
  1464. }
  1465. return 0;
  1466. }
  1467. /**
  1468. * proc_dostring - read a string sysctl
  1469. * @table: the sysctl table
  1470. * @write: %TRUE if this is a write to the sysctl file
  1471. * @filp: the file structure
  1472. * @buffer: the user buffer
  1473. * @lenp: the size of the user buffer
  1474. * @ppos: file position
  1475. *
  1476. * Reads/writes a string from/to the user buffer. If the kernel
  1477. * buffer provided is not large enough to hold the string, the
  1478. * string is truncated. The copied string is %NULL-terminated.
  1479. * If the string is being read by the user process, it is copied
  1480. * and a newline '\n' is added. It is truncated if the buffer is
  1481. * not large enough.
  1482. *
  1483. * Returns 0 on success.
  1484. */
  1485. int proc_dostring(ctl_table *table, int write, struct file *filp,
  1486. void __user *buffer, size_t *lenp, loff_t *ppos)
  1487. {
  1488. return _proc_do_string(table->data, table->maxlen, write, filp,
  1489. buffer, lenp, ppos);
  1490. }
  1491. static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
  1492. int *valp,
  1493. int write, void *data)
  1494. {
  1495. if (write) {
  1496. *valp = *negp ? -*lvalp : *lvalp;
  1497. } else {
  1498. int val = *valp;
  1499. if (val < 0) {
  1500. *negp = -1;
  1501. *lvalp = (unsigned long)-val;
  1502. } else {
  1503. *negp = 0;
  1504. *lvalp = (unsigned long)val;
  1505. }
  1506. }
  1507. return 0;
  1508. }
  1509. static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
  1510. int write, struct file *filp, void __user *buffer,
  1511. size_t *lenp, loff_t *ppos,
  1512. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1513. int write, void *data),
  1514. void *data)
  1515. {
  1516. #define TMPBUFLEN 21
  1517. int *i, vleft, first=1, neg, val;
  1518. unsigned long lval;
  1519. size_t left, len;
  1520. char buf[TMPBUFLEN], *p;
  1521. char __user *s = buffer;
  1522. if (!tbl_data || !table->maxlen || !*lenp ||
  1523. (*ppos && !write)) {
  1524. *lenp = 0;
  1525. return 0;
  1526. }
  1527. i = (int *) tbl_data;
  1528. vleft = table->maxlen / sizeof(*i);
  1529. left = *lenp;
  1530. if (!conv)
  1531. conv = do_proc_dointvec_conv;
  1532. for (; left && vleft--; i++, first=0) {
  1533. if (write) {
  1534. while (left) {
  1535. char c;
  1536. if (get_user(c, s))
  1537. return -EFAULT;
  1538. if (!isspace(c))
  1539. break;
  1540. left--;
  1541. s++;
  1542. }
  1543. if (!left)
  1544. break;
  1545. neg = 0;
  1546. len = left;
  1547. if (len > sizeof(buf) - 1)
  1548. len = sizeof(buf) - 1;
  1549. if (copy_from_user(buf, s, len))
  1550. return -EFAULT;
  1551. buf[len] = 0;
  1552. p = buf;
  1553. if (*p == '-' && left > 1) {
  1554. neg = 1;
  1555. p++;
  1556. }
  1557. if (*p < '0' || *p > '9')
  1558. break;
  1559. lval = simple_strtoul(p, &p, 0);
  1560. len = p-buf;
  1561. if ((len < left) && *p && !isspace(*p))
  1562. break;
  1563. if (neg)
  1564. val = -val;
  1565. s += len;
  1566. left -= len;
  1567. if (conv(&neg, &lval, i, 1, data))
  1568. break;
  1569. } else {
  1570. p = buf;
  1571. if (!first)
  1572. *p++ = '\t';
  1573. if (conv(&neg, &lval, i, 0, data))
  1574. break;
  1575. sprintf(p, "%s%lu", neg ? "-" : "", lval);
  1576. len = strlen(buf);
  1577. if (len > left)
  1578. len = left;
  1579. if(copy_to_user(s, buf, len))
  1580. return -EFAULT;
  1581. left -= len;
  1582. s += len;
  1583. }
  1584. }
  1585. if (!write && !first && left) {
  1586. if(put_user('\n', s))
  1587. return -EFAULT;
  1588. left--, s++;
  1589. }
  1590. if (write) {
  1591. while (left) {
  1592. char c;
  1593. if (get_user(c, s++))
  1594. return -EFAULT;
  1595. if (!isspace(c))
  1596. break;
  1597. left--;
  1598. }
  1599. }
  1600. if (write && first)
  1601. return -EINVAL;
  1602. *lenp -= left;
  1603. *ppos += *lenp;
  1604. return 0;
  1605. #undef TMPBUFLEN
  1606. }
  1607. static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
  1608. void __user *buffer, size_t *lenp, loff_t *ppos,
  1609. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1610. int write, void *data),
  1611. void *data)
  1612. {
  1613. return __do_proc_dointvec(table->data, table, write, filp,
  1614. buffer, lenp, ppos, conv, data);
  1615. }
  1616. /**
  1617. * proc_dointvec - read a vector of integers
  1618. * @table: the sysctl table
  1619. * @write: %TRUE if this is a write to the sysctl file
  1620. * @filp: the file structure
  1621. * @buffer: the user buffer
  1622. * @lenp: the size of the user buffer
  1623. * @ppos: file position
  1624. *
  1625. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1626. * values from/to the user buffer, treated as an ASCII string.
  1627. *
  1628. * Returns 0 on success.
  1629. */
  1630. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  1631. void __user *buffer, size_t *lenp, loff_t *ppos)
  1632. {
  1633. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1634. NULL,NULL);
  1635. }
  1636. #define OP_SET 0
  1637. #define OP_AND 1
  1638. #define OP_OR 2
  1639. static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
  1640. int *valp,
  1641. int write, void *data)
  1642. {
  1643. int op = *(int *)data;
  1644. if (write) {
  1645. int val = *negp ? -*lvalp : *lvalp;
  1646. switch(op) {
  1647. case OP_SET: *valp = val; break;
  1648. case OP_AND: *valp &= val; break;
  1649. case OP_OR: *valp |= val; break;
  1650. }
  1651. } else {
  1652. int val = *valp;
  1653. if (val < 0) {
  1654. *negp = -1;
  1655. *lvalp = (unsigned long)-val;
  1656. } else {
  1657. *negp = 0;
  1658. *lvalp = (unsigned long)val;
  1659. }
  1660. }
  1661. return 0;
  1662. }
  1663. /*
  1664. * init may raise the set.
  1665. */
  1666. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  1667. void __user *buffer, size_t *lenp, loff_t *ppos)
  1668. {
  1669. int op;
  1670. if (write && !capable(CAP_SYS_MODULE)) {
  1671. return -EPERM;
  1672. }
  1673. op = is_init(current) ? OP_SET : OP_AND;
  1674. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1675. do_proc_dointvec_bset_conv,&op);
  1676. }
  1677. /*
  1678. * Taint values can only be increased
  1679. */
  1680. static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
  1681. void __user *buffer, size_t *lenp, loff_t *ppos)
  1682. {
  1683. int op;
  1684. if (write && !capable(CAP_SYS_ADMIN))
  1685. return -EPERM;
  1686. op = OP_OR;
  1687. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1688. do_proc_dointvec_bset_conv,&op);
  1689. }
  1690. struct do_proc_dointvec_minmax_conv_param {
  1691. int *min;
  1692. int *max;
  1693. };
  1694. static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
  1695. int *valp,
  1696. int write, void *data)
  1697. {
  1698. struct do_proc_dointvec_minmax_conv_param *param = data;
  1699. if (write) {
  1700. int val = *negp ? -*lvalp : *lvalp;
  1701. if ((param->min && *param->min > val) ||
  1702. (param->max && *param->max < val))
  1703. return -EINVAL;
  1704. *valp = val;
  1705. } else {
  1706. int val = *valp;
  1707. if (val < 0) {
  1708. *negp = -1;
  1709. *lvalp = (unsigned long)-val;
  1710. } else {
  1711. *negp = 0;
  1712. *lvalp = (unsigned long)val;
  1713. }
  1714. }
  1715. return 0;
  1716. }
  1717. /**
  1718. * proc_dointvec_minmax - read a vector of integers with min/max values
  1719. * @table: the sysctl table
  1720. * @write: %TRUE if this is a write to the sysctl file
  1721. * @filp: the file structure
  1722. * @buffer: the user buffer
  1723. * @lenp: the size of the user buffer
  1724. * @ppos: file position
  1725. *
  1726. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1727. * values from/to the user buffer, treated as an ASCII string.
  1728. *
  1729. * This routine will ensure the values are within the range specified by
  1730. * table->extra1 (min) and table->extra2 (max).
  1731. *
  1732. * Returns 0 on success.
  1733. */
  1734. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  1735. void __user *buffer, size_t *lenp, loff_t *ppos)
  1736. {
  1737. struct do_proc_dointvec_minmax_conv_param param = {
  1738. .min = (int *) table->extra1,
  1739. .max = (int *) table->extra2,
  1740. };
  1741. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  1742. do_proc_dointvec_minmax_conv, &param);
  1743. }
  1744. static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
  1745. struct file *filp,
  1746. void __user *buffer,
  1747. size_t *lenp, loff_t *ppos,
  1748. unsigned long convmul,
  1749. unsigned long convdiv)
  1750. {
  1751. #define TMPBUFLEN 21
  1752. unsigned long *i, *min, *max, val;
  1753. int vleft, first=1, neg;
  1754. size_t len, left;
  1755. char buf[TMPBUFLEN], *p;
  1756. char __user *s = buffer;
  1757. if (!data || !table->maxlen || !*lenp ||
  1758. (*ppos && !write)) {
  1759. *lenp = 0;
  1760. return 0;
  1761. }
  1762. i = (unsigned long *) data;
  1763. min = (unsigned long *) table->extra1;
  1764. max = (unsigned long *) table->extra2;
  1765. vleft = table->maxlen / sizeof(unsigned long);
  1766. left = *lenp;
  1767. for (; left && vleft--; i++, min++, max++, first=0) {
  1768. if (write) {
  1769. while (left) {
  1770. char c;
  1771. if (get_user(c, s))
  1772. return -EFAULT;
  1773. if (!isspace(c))
  1774. break;
  1775. left--;
  1776. s++;
  1777. }
  1778. if (!left)
  1779. break;
  1780. neg = 0;
  1781. len = left;
  1782. if (len > TMPBUFLEN-1)
  1783. len = TMPBUFLEN-1;
  1784. if (copy_from_user(buf, s, len))
  1785. return -EFAULT;
  1786. buf[len] = 0;
  1787. p = buf;
  1788. if (*p == '-' && left > 1) {
  1789. neg = 1;
  1790. p++;
  1791. }
  1792. if (*p < '0' || *p > '9')
  1793. break;
  1794. val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
  1795. len = p-buf;
  1796. if ((len < left) && *p && !isspace(*p))
  1797. break;
  1798. if (neg)
  1799. val = -val;
  1800. s += len;
  1801. left -= len;
  1802. if(neg)
  1803. continue;
  1804. if ((min && val < *min) || (max && val > *max))
  1805. continue;
  1806. *i = val;
  1807. } else {
  1808. p = buf;
  1809. if (!first)
  1810. *p++ = '\t';
  1811. sprintf(p, "%lu", convdiv * (*i) / convmul);
  1812. len = strlen(buf);
  1813. if (len > left)
  1814. len = left;
  1815. if(copy_to_user(s, buf, len))
  1816. return -EFAULT;
  1817. left -= len;
  1818. s += len;
  1819. }
  1820. }
  1821. if (!write && !first && left) {
  1822. if(put_user('\n', s))
  1823. return -EFAULT;
  1824. left--, s++;
  1825. }
  1826. if (write) {
  1827. while (left) {
  1828. char c;
  1829. if (get_user(c, s++))
  1830. return -EFAULT;
  1831. if (!isspace(c))
  1832. break;
  1833. left--;
  1834. }
  1835. }
  1836. if (write && first)
  1837. return -EINVAL;
  1838. *lenp -= left;
  1839. *ppos += *lenp;
  1840. return 0;
  1841. #undef TMPBUFLEN
  1842. }
  1843. static int do_proc_doulongvec_minmax(ctl_table *table, int write,
  1844. struct file *filp,
  1845. void __user *buffer,
  1846. size_t *lenp, loff_t *ppos,
  1847. unsigned long convmul,
  1848. unsigned long convdiv)
  1849. {
  1850. return __do_proc_doulongvec_minmax(table->data, table, write,
  1851. filp, buffer, lenp, ppos, convmul, convdiv);
  1852. }
  1853. /**
  1854. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  1855. * @table: the sysctl table
  1856. * @write: %TRUE if this is a write to the sysctl file
  1857. * @filp: the file structure
  1858. * @buffer: the user buffer
  1859. * @lenp: the size of the user buffer
  1860. * @ppos: file position
  1861. *
  1862. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1863. * values from/to the user buffer, treated as an ASCII string.
  1864. *
  1865. * This routine will ensure the values are within the range specified by
  1866. * table->extra1 (min) and table->extra2 (max).
  1867. *
  1868. * Returns 0 on success.
  1869. */
  1870. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  1871. void __user *buffer, size_t *lenp, loff_t *ppos)
  1872. {
  1873. return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
  1874. }
  1875. /**
  1876. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  1877. * @table: the sysctl table
  1878. * @write: %TRUE if this is a write to the sysctl file
  1879. * @filp: the file structure
  1880. * @buffer: the user buffer
  1881. * @lenp: the size of the user buffer
  1882. * @ppos: file position
  1883. *
  1884. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1885. * values from/to the user buffer, treated as an ASCII string. The values
  1886. * are treated as milliseconds, and converted to jiffies when they are stored.
  1887. *
  1888. * This routine will ensure the values are within the range specified by
  1889. * table->extra1 (min) and table->extra2 (max).
  1890. *
  1891. * Returns 0 on success.
  1892. */
  1893. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  1894. struct file *filp,
  1895. void __user *buffer,
  1896. size_t *lenp, loff_t *ppos)
  1897. {
  1898. return do_proc_doulongvec_minmax(table, write, filp, buffer,
  1899. lenp, ppos, HZ, 1000l);
  1900. }
  1901. static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
  1902. int *valp,
  1903. int write, void *data)
  1904. {
  1905. if (write) {
  1906. if (*lvalp > LONG_MAX / HZ)
  1907. return 1;
  1908. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  1909. } else {
  1910. int val = *valp;
  1911. unsigned long lval;
  1912. if (val < 0) {
  1913. *negp = -1;
  1914. lval = (unsigned long)-val;
  1915. } else {
  1916. *negp = 0;
  1917. lval = (unsigned long)val;
  1918. }
  1919. *lvalp = lval / HZ;
  1920. }
  1921. return 0;
  1922. }
  1923. static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
  1924. int *valp,
  1925. int write, void *data)
  1926. {
  1927. if (write) {
  1928. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  1929. return 1;
  1930. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  1931. } else {
  1932. int val = *valp;
  1933. unsigned long lval;
  1934. if (val < 0) {
  1935. *negp = -1;
  1936. lval = (unsigned long)-val;
  1937. } else {
  1938. *negp = 0;
  1939. lval = (unsigned long)val;
  1940. }
  1941. *lvalp = jiffies_to_clock_t(lval);
  1942. }
  1943. return 0;
  1944. }
  1945. static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
  1946. int *valp,
  1947. int write, void *data)
  1948. {
  1949. if (write) {
  1950. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  1951. } else {
  1952. int val = *valp;
  1953. unsigned long lval;
  1954. if (val < 0) {
  1955. *negp = -1;
  1956. lval = (unsigned long)-val;
  1957. } else {
  1958. *negp = 0;
  1959. lval = (unsigned long)val;
  1960. }
  1961. *lvalp = jiffies_to_msecs(lval);
  1962. }
  1963. return 0;
  1964. }
  1965. /**
  1966. * proc_dointvec_jiffies - read a vector of integers as seconds
  1967. * @table: the sysctl table
  1968. * @write: %TRUE if this is a write to the sysctl file
  1969. * @filp: the file structure
  1970. * @buffer: the user buffer
  1971. * @lenp: the size of the user buffer
  1972. * @ppos: file position
  1973. *
  1974. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1975. * values from/to the user buffer, treated as an ASCII string.
  1976. * The values read are assumed to be in seconds, and are converted into
  1977. * jiffies.
  1978. *
  1979. * Returns 0 on success.
  1980. */
  1981. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  1982. void __user *buffer, size_t *lenp, loff_t *ppos)
  1983. {
  1984. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1985. do_proc_dointvec_jiffies_conv,NULL);
  1986. }
  1987. /**
  1988. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  1989. * @table: the sysctl table
  1990. * @write: %TRUE if this is a write to the sysctl file
  1991. * @filp: the file structure
  1992. * @buffer: the user buffer
  1993. * @lenp: the size of the user buffer
  1994. * @ppos: pointer to the file position
  1995. *
  1996. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1997. * values from/to the user buffer, treated as an ASCII string.
  1998. * The values read are assumed to be in 1/USER_HZ seconds, and
  1999. * are converted into jiffies.
  2000. *
  2001. * Returns 0 on success.
  2002. */
  2003. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2004. void __user *buffer, size_t *lenp, loff_t *ppos)
  2005. {
  2006. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2007. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2008. }
  2009. /**
  2010. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2011. * @table: the sysctl table
  2012. * @write: %TRUE if this is a write to the sysctl file
  2013. * @filp: the file structure
  2014. * @buffer: the user buffer
  2015. * @lenp: the size of the user buffer
  2016. * @ppos: file position
  2017. * @ppos: the current position in the file
  2018. *
  2019. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2020. * values from/to the user buffer, treated as an ASCII string.
  2021. * The values read are assumed to be in 1/1000 seconds, and
  2022. * are converted into jiffies.
  2023. *
  2024. * Returns 0 on success.
  2025. */
  2026. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2027. void __user *buffer, size_t *lenp, loff_t *ppos)
  2028. {
  2029. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  2030. do_proc_dointvec_ms_jiffies_conv, NULL);
  2031. }
  2032. static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
  2033. void __user *buffer, size_t *lenp, loff_t *ppos)
  2034. {
  2035. struct pid *new_pid;
  2036. pid_t tmp;
  2037. int r;
  2038. tmp = pid_nr(cad_pid);
  2039. r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
  2040. lenp, ppos, NULL, NULL);
  2041. if (r || !write)
  2042. return r;
  2043. new_pid = find_get_pid(tmp);
  2044. if (!new_pid)
  2045. return -ESRCH;
  2046. put_pid(xchg(&cad_pid, new_pid));
  2047. return 0;
  2048. }
  2049. #else /* CONFIG_PROC_FS */
  2050. int proc_dostring(ctl_table *table, int write, struct file *filp,
  2051. void __user *buffer, size_t *lenp, loff_t *ppos)
  2052. {
  2053. return -ENOSYS;
  2054. }
  2055. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2056. void __user *buffer, size_t *lenp, loff_t *ppos)
  2057. {
  2058. return -ENOSYS;
  2059. }
  2060. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2061. void __user *buffer, size_t *lenp, loff_t *ppos)
  2062. {
  2063. return -ENOSYS;
  2064. }
  2065. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2066. void __user *buffer, size_t *lenp, loff_t *ppos)
  2067. {
  2068. return -ENOSYS;
  2069. }
  2070. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2071. void __user *buffer, size_t *lenp, loff_t *ppos)
  2072. {
  2073. return -ENOSYS;
  2074. }
  2075. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2076. void __user *buffer, size_t *lenp, loff_t *ppos)
  2077. {
  2078. return -ENOSYS;
  2079. }
  2080. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2081. void __user *buffer, size_t *lenp, loff_t *ppos)
  2082. {
  2083. return -ENOSYS;
  2084. }
  2085. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2086. void __user *buffer, size_t *lenp, loff_t *ppos)
  2087. {
  2088. return -ENOSYS;
  2089. }
  2090. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2091. struct file *filp,
  2092. void __user *buffer,
  2093. size_t *lenp, loff_t *ppos)
  2094. {
  2095. return -ENOSYS;
  2096. }
  2097. #endif /* CONFIG_PROC_FS */
  2098. #ifdef CONFIG_SYSCTL_SYSCALL
  2099. /*
  2100. * General sysctl support routines
  2101. */
  2102. /* The generic string strategy routine: */
  2103. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2104. void __user *oldval, size_t __user *oldlenp,
  2105. void __user *newval, size_t newlen)
  2106. {
  2107. if (!table->data || !table->maxlen)
  2108. return -ENOTDIR;
  2109. if (oldval && oldlenp) {
  2110. size_t bufsize;
  2111. if (get_user(bufsize, oldlenp))
  2112. return -EFAULT;
  2113. if (bufsize) {
  2114. size_t len = strlen(table->data), copied;
  2115. /* This shouldn't trigger for a well-formed sysctl */
  2116. if (len > table->maxlen)
  2117. len = table->maxlen;
  2118. /* Copy up to a max of bufsize-1 bytes of the string */
  2119. copied = (len >= bufsize) ? bufsize - 1 : len;
  2120. if (copy_to_user(oldval, table->data, copied) ||
  2121. put_user(0, (char __user *)(oldval + copied)))
  2122. return -EFAULT;
  2123. if (put_user(len, oldlenp))
  2124. return -EFAULT;
  2125. }
  2126. }
  2127. if (newval && newlen) {
  2128. size_t len = newlen;
  2129. if (len > table->maxlen)
  2130. len = table->maxlen;
  2131. if(copy_from_user(table->data, newval, len))
  2132. return -EFAULT;
  2133. if (len == table->maxlen)
  2134. len--;
  2135. ((char *) table->data)[len] = 0;
  2136. }
  2137. return 1;
  2138. }
  2139. /*
  2140. * This function makes sure that all of the integers in the vector
  2141. * are between the minimum and maximum values given in the arrays
  2142. * table->extra1 and table->extra2, respectively.
  2143. */
  2144. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2145. void __user *oldval, size_t __user *oldlenp,
  2146. void __user *newval, size_t newlen)
  2147. {
  2148. if (newval && newlen) {
  2149. int __user *vec = (int __user *) newval;
  2150. int *min = (int *) table->extra1;
  2151. int *max = (int *) table->extra2;
  2152. size_t length;
  2153. int i;
  2154. if (newlen % sizeof(int) != 0)
  2155. return -EINVAL;
  2156. if (!table->extra1 && !table->extra2)
  2157. return 0;
  2158. if (newlen > table->maxlen)
  2159. newlen = table->maxlen;
  2160. length = newlen / sizeof(int);
  2161. for (i = 0; i < length; i++) {
  2162. int value;
  2163. if (get_user(value, vec + i))
  2164. return -EFAULT;
  2165. if (min && value < min[i])
  2166. return -EINVAL;
  2167. if (max && value > max[i])
  2168. return -EINVAL;
  2169. }
  2170. }
  2171. return 0;
  2172. }
  2173. /* Strategy function to convert jiffies to seconds */
  2174. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2175. void __user *oldval, size_t __user *oldlenp,
  2176. void __user *newval, size_t newlen)
  2177. {
  2178. if (oldval && oldlenp) {
  2179. size_t olen;
  2180. if (get_user(olen, oldlenp))
  2181. return -EFAULT;
  2182. if (olen) {
  2183. int val;
  2184. if (olen < sizeof(int))
  2185. return -EINVAL;
  2186. val = *(int *)(table->data) / HZ;
  2187. if (put_user(val, (int __user *)oldval))
  2188. return -EFAULT;
  2189. if (put_user(sizeof(int), oldlenp))
  2190. return -EFAULT;
  2191. }
  2192. }
  2193. if (newval && newlen) {
  2194. int new;
  2195. if (newlen != sizeof(int))
  2196. return -EINVAL;
  2197. if (get_user(new, (int __user *)newval))
  2198. return -EFAULT;
  2199. *(int *)(table->data) = new*HZ;
  2200. }
  2201. return 1;
  2202. }
  2203. /* Strategy function to convert jiffies to seconds */
  2204. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2205. void __user *oldval, size_t __user *oldlenp,
  2206. void __user *newval, size_t newlen)
  2207. {
  2208. if (oldval && oldlenp) {
  2209. size_t olen;
  2210. if (get_user(olen, oldlenp))
  2211. return -EFAULT;
  2212. if (olen) {
  2213. int val;
  2214. if (olen < sizeof(int))
  2215. return -EINVAL;
  2216. val = jiffies_to_msecs(*(int *)(table->data));
  2217. if (put_user(val, (int __user *)oldval))
  2218. return -EFAULT;
  2219. if (put_user(sizeof(int), oldlenp))
  2220. return -EFAULT;
  2221. }
  2222. }
  2223. if (newval && newlen) {
  2224. int new;
  2225. if (newlen != sizeof(int))
  2226. return -EINVAL;
  2227. if (get_user(new, (int __user *)newval))
  2228. return -EFAULT;
  2229. *(int *)(table->data) = msecs_to_jiffies(new);
  2230. }
  2231. return 1;
  2232. }
  2233. #else /* CONFIG_SYSCTL_SYSCALL */
  2234. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  2235. {
  2236. static int msg_count;
  2237. struct __sysctl_args tmp;
  2238. int name[CTL_MAXNAME];
  2239. int i;
  2240. /* Read in the sysctl name for better debug message logging */
  2241. if (copy_from_user(&tmp, args, sizeof(tmp)))
  2242. return -EFAULT;
  2243. if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
  2244. return -ENOTDIR;
  2245. for (i = 0; i < tmp.nlen; i++)
  2246. if (get_user(name[i], tmp.name + i))
  2247. return -EFAULT;
  2248. /* Ignore accesses to kernel.version */
  2249. if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
  2250. goto out;
  2251. if (msg_count < 5) {
  2252. msg_count++;
  2253. printk(KERN_INFO
  2254. "warning: process `%s' used the removed sysctl "
  2255. "system call with ", current->comm);
  2256. for (i = 0; i < tmp.nlen; i++)
  2257. printk("%d.", name[i]);
  2258. printk("\n");
  2259. }
  2260. out:
  2261. return -ENOSYS;
  2262. }
  2263. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2264. void __user *oldval, size_t __user *oldlenp,
  2265. void __user *newval, size_t newlen)
  2266. {
  2267. return -ENOSYS;
  2268. }
  2269. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2270. void __user *oldval, size_t __user *oldlenp,
  2271. void __user *newval, size_t newlen)
  2272. {
  2273. return -ENOSYS;
  2274. }
  2275. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2276. void __user *oldval, size_t __user *oldlenp,
  2277. void __user *newval, size_t newlen)
  2278. {
  2279. return -ENOSYS;
  2280. }
  2281. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2282. void __user *oldval, size_t __user *oldlenp,
  2283. void __user *newval, size_t newlen)
  2284. {
  2285. return -ENOSYS;
  2286. }
  2287. #endif /* CONFIG_SYSCTL_SYSCALL */
  2288. /*
  2289. * No sense putting this after each symbol definition, twice,
  2290. * exception granted :-)
  2291. */
  2292. EXPORT_SYMBOL(proc_dointvec);
  2293. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2294. EXPORT_SYMBOL(proc_dointvec_minmax);
  2295. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2296. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2297. EXPORT_SYMBOL(proc_dostring);
  2298. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2299. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2300. EXPORT_SYMBOL(register_sysctl_table);
  2301. EXPORT_SYMBOL(sysctl_intvec);
  2302. EXPORT_SYMBOL(sysctl_jiffies);
  2303. EXPORT_SYMBOL(sysctl_ms_jiffies);
  2304. EXPORT_SYMBOL(sysctl_string);
  2305. EXPORT_SYMBOL(unregister_sysctl_table);