sysctl.c 65 KB

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