sysctl.c 59 KB

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