sysctl.c 60 KB

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