sysctl.c 57 KB

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