sysctl.c 62 KB

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