sysctl.c 59 KB

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