sysctl.c 65 KB

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