sysctl.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805
  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. static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
  134. void __user *buffer, size_t *lenp, loff_t *ppos);
  135. #endif
  136. static ctl_table root_table[];
  137. static struct ctl_table_header root_table_header =
  138. { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
  139. static ctl_table kern_table[];
  140. static ctl_table vm_table[];
  141. static ctl_table fs_table[];
  142. static ctl_table debug_table[];
  143. static ctl_table dev_table[];
  144. extern ctl_table random_table[];
  145. #ifdef CONFIG_UNIX98_PTYS
  146. extern ctl_table pty_table[];
  147. #endif
  148. #ifdef CONFIG_INOTIFY_USER
  149. extern ctl_table inotify_table[];
  150. #endif
  151. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  152. int sysctl_legacy_va_layout;
  153. #endif
  154. static void *get_uts(ctl_table *table, int write)
  155. {
  156. char *which = table->data;
  157. #ifdef CONFIG_UTS_NS
  158. struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
  159. which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
  160. #endif
  161. if (!write)
  162. down_read(&uts_sem);
  163. else
  164. down_write(&uts_sem);
  165. return which;
  166. }
  167. static void put_uts(ctl_table *table, int write, void *which)
  168. {
  169. if (!write)
  170. up_read(&uts_sem);
  171. else
  172. up_write(&uts_sem);
  173. }
  174. #ifdef CONFIG_SYSVIPC
  175. static void *get_ipc(ctl_table *table, int write)
  176. {
  177. char *which = table->data;
  178. struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
  179. which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
  180. return which;
  181. }
  182. #else
  183. #define get_ipc(T,W) ((T)->data)
  184. #endif
  185. /* /proc declarations: */
  186. #ifdef CONFIG_PROC_SYSCTL
  187. static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
  188. static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
  189. static int proc_opensys(struct inode *, struct file *);
  190. const struct file_operations proc_sys_file_operations = {
  191. .open = proc_opensys,
  192. .read = proc_readsys,
  193. .write = proc_writesys,
  194. };
  195. extern struct proc_dir_entry *proc_sys_root;
  196. static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
  197. static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
  198. #endif
  199. /* The default sysctl tables: */
  200. static ctl_table root_table[] = {
  201. {
  202. .ctl_name = CTL_KERN,
  203. .procname = "kernel",
  204. .mode = 0555,
  205. .child = kern_table,
  206. },
  207. {
  208. .ctl_name = CTL_VM,
  209. .procname = "vm",
  210. .mode = 0555,
  211. .child = vm_table,
  212. },
  213. #ifdef CONFIG_NET
  214. {
  215. .ctl_name = CTL_NET,
  216. .procname = "net",
  217. .mode = 0555,
  218. .child = net_table,
  219. },
  220. #endif
  221. {
  222. .ctl_name = CTL_FS,
  223. .procname = "fs",
  224. .mode = 0555,
  225. .child = fs_table,
  226. },
  227. {
  228. .ctl_name = CTL_DEBUG,
  229. .procname = "debug",
  230. .mode = 0555,
  231. .child = debug_table,
  232. },
  233. {
  234. .ctl_name = CTL_DEV,
  235. .procname = "dev",
  236. .mode = 0555,
  237. .child = dev_table,
  238. },
  239. { .ctl_name = 0 }
  240. };
  241. static ctl_table kern_table[] = {
  242. {
  243. .ctl_name = KERN_OSTYPE,
  244. .procname = "ostype",
  245. .data = init_uts_ns.name.sysname,
  246. .maxlen = sizeof(init_uts_ns.name.sysname),
  247. .mode = 0444,
  248. .proc_handler = &proc_do_uts_string,
  249. .strategy = &sysctl_uts_string,
  250. },
  251. {
  252. .ctl_name = KERN_OSRELEASE,
  253. .procname = "osrelease",
  254. .data = init_uts_ns.name.release,
  255. .maxlen = sizeof(init_uts_ns.name.release),
  256. .mode = 0444,
  257. .proc_handler = &proc_do_uts_string,
  258. .strategy = &sysctl_uts_string,
  259. },
  260. {
  261. .ctl_name = KERN_VERSION,
  262. .procname = "version",
  263. .data = init_uts_ns.name.version,
  264. .maxlen = sizeof(init_uts_ns.name.version),
  265. .mode = 0444,
  266. .proc_handler = &proc_do_uts_string,
  267. .strategy = &sysctl_uts_string,
  268. },
  269. {
  270. .ctl_name = KERN_NODENAME,
  271. .procname = "hostname",
  272. .data = init_uts_ns.name.nodename,
  273. .maxlen = sizeof(init_uts_ns.name.nodename),
  274. .mode = 0644,
  275. .proc_handler = &proc_do_uts_string,
  276. .strategy = &sysctl_uts_string,
  277. },
  278. {
  279. .ctl_name = KERN_DOMAINNAME,
  280. .procname = "domainname",
  281. .data = init_uts_ns.name.domainname,
  282. .maxlen = sizeof(init_uts_ns.name.domainname),
  283. .mode = 0644,
  284. .proc_handler = &proc_do_uts_string,
  285. .strategy = &sysctl_uts_string,
  286. },
  287. {
  288. .ctl_name = KERN_PANIC,
  289. .procname = "panic",
  290. .data = &panic_timeout,
  291. .maxlen = sizeof(int),
  292. .mode = 0644,
  293. .proc_handler = &proc_dointvec,
  294. },
  295. {
  296. .ctl_name = KERN_CORE_USES_PID,
  297. .procname = "core_uses_pid",
  298. .data = &core_uses_pid,
  299. .maxlen = sizeof(int),
  300. .mode = 0644,
  301. .proc_handler = &proc_dointvec,
  302. },
  303. {
  304. .ctl_name = KERN_CORE_PATTERN,
  305. .procname = "core_pattern",
  306. .data = core_pattern,
  307. .maxlen = 128,
  308. .mode = 0644,
  309. .proc_handler = &proc_dostring,
  310. .strategy = &sysctl_string,
  311. },
  312. #ifdef CONFIG_PROC_SYSCTL
  313. {
  314. .ctl_name = KERN_TAINTED,
  315. .procname = "tainted",
  316. .data = &tainted,
  317. .maxlen = sizeof(int),
  318. .mode = 0644,
  319. .proc_handler = &proc_dointvec_taint,
  320. },
  321. #endif
  322. {
  323. .ctl_name = KERN_CAP_BSET,
  324. .procname = "cap-bound",
  325. .data = &cap_bset,
  326. .maxlen = sizeof(kernel_cap_t),
  327. .mode = 0600,
  328. .proc_handler = &proc_dointvec_bset,
  329. },
  330. #ifdef CONFIG_BLK_DEV_INITRD
  331. {
  332. .ctl_name = KERN_REALROOTDEV,
  333. .procname = "real-root-dev",
  334. .data = &real_root_dev,
  335. .maxlen = sizeof(int),
  336. .mode = 0644,
  337. .proc_handler = &proc_dointvec,
  338. },
  339. #endif
  340. #ifdef __sparc__
  341. {
  342. .ctl_name = KERN_SPARC_REBOOT,
  343. .procname = "reboot-cmd",
  344. .data = reboot_command,
  345. .maxlen = 256,
  346. .mode = 0644,
  347. .proc_handler = &proc_dostring,
  348. .strategy = &sysctl_string,
  349. },
  350. {
  351. .ctl_name = KERN_SPARC_STOP_A,
  352. .procname = "stop-a",
  353. .data = &stop_a_enabled,
  354. .maxlen = sizeof (int),
  355. .mode = 0644,
  356. .proc_handler = &proc_dointvec,
  357. },
  358. {
  359. .ctl_name = KERN_SPARC_SCONS_PWROFF,
  360. .procname = "scons-poweroff",
  361. .data = &scons_pwroff,
  362. .maxlen = sizeof (int),
  363. .mode = 0644,
  364. .proc_handler = &proc_dointvec,
  365. },
  366. #endif
  367. #ifdef __hppa__
  368. {
  369. .ctl_name = KERN_HPPA_PWRSW,
  370. .procname = "soft-power",
  371. .data = &pwrsw_enabled,
  372. .maxlen = sizeof (int),
  373. .mode = 0644,
  374. .proc_handler = &proc_dointvec,
  375. },
  376. {
  377. .ctl_name = KERN_HPPA_UNALIGNED,
  378. .procname = "unaligned-trap",
  379. .data = &unaligned_enabled,
  380. .maxlen = sizeof (int),
  381. .mode = 0644,
  382. .proc_handler = &proc_dointvec,
  383. },
  384. #endif
  385. {
  386. .ctl_name = KERN_CTLALTDEL,
  387. .procname = "ctrl-alt-del",
  388. .data = &C_A_D,
  389. .maxlen = sizeof(int),
  390. .mode = 0644,
  391. .proc_handler = &proc_dointvec,
  392. },
  393. {
  394. .ctl_name = KERN_PRINTK,
  395. .procname = "printk",
  396. .data = &console_loglevel,
  397. .maxlen = 4*sizeof(int),
  398. .mode = 0644,
  399. .proc_handler = &proc_dointvec,
  400. },
  401. #ifdef CONFIG_KMOD
  402. {
  403. .ctl_name = KERN_MODPROBE,
  404. .procname = "modprobe",
  405. .data = &modprobe_path,
  406. .maxlen = KMOD_PATH_LEN,
  407. .mode = 0644,
  408. .proc_handler = &proc_dostring,
  409. .strategy = &sysctl_string,
  410. },
  411. #endif
  412. #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
  413. {
  414. .ctl_name = KERN_HOTPLUG,
  415. .procname = "hotplug",
  416. .data = &uevent_helper,
  417. .maxlen = UEVENT_HELPER_PATH_LEN,
  418. .mode = 0644,
  419. .proc_handler = &proc_dostring,
  420. .strategy = &sysctl_string,
  421. },
  422. #endif
  423. #ifdef CONFIG_CHR_DEV_SG
  424. {
  425. .ctl_name = KERN_SG_BIG_BUFF,
  426. .procname = "sg-big-buff",
  427. .data = &sg_big_buff,
  428. .maxlen = sizeof (int),
  429. .mode = 0444,
  430. .proc_handler = &proc_dointvec,
  431. },
  432. #endif
  433. #ifdef CONFIG_BSD_PROCESS_ACCT
  434. {
  435. .ctl_name = KERN_ACCT,
  436. .procname = "acct",
  437. .data = &acct_parm,
  438. .maxlen = 3*sizeof(int),
  439. .mode = 0644,
  440. .proc_handler = &proc_dointvec,
  441. },
  442. #endif
  443. #ifdef CONFIG_SYSVIPC
  444. {
  445. .ctl_name = KERN_SHMMAX,
  446. .procname = "shmmax",
  447. .data = &init_ipc_ns.shm_ctlmax,
  448. .maxlen = sizeof (init_ipc_ns.shm_ctlmax),
  449. .mode = 0644,
  450. .proc_handler = &proc_ipc_doulongvec_minmax,
  451. .strategy = sysctl_ipc_data,
  452. },
  453. {
  454. .ctl_name = KERN_SHMALL,
  455. .procname = "shmall",
  456. .data = &init_ipc_ns.shm_ctlall,
  457. .maxlen = sizeof (init_ipc_ns.shm_ctlall),
  458. .mode = 0644,
  459. .proc_handler = &proc_ipc_doulongvec_minmax,
  460. .strategy = sysctl_ipc_data,
  461. },
  462. {
  463. .ctl_name = KERN_SHMMNI,
  464. .procname = "shmmni",
  465. .data = &init_ipc_ns.shm_ctlmni,
  466. .maxlen = sizeof (init_ipc_ns.shm_ctlmni),
  467. .mode = 0644,
  468. .proc_handler = &proc_ipc_dointvec,
  469. .strategy = sysctl_ipc_data,
  470. },
  471. {
  472. .ctl_name = KERN_MSGMAX,
  473. .procname = "msgmax",
  474. .data = &init_ipc_ns.msg_ctlmax,
  475. .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
  476. .mode = 0644,
  477. .proc_handler = &proc_ipc_dointvec,
  478. .strategy = sysctl_ipc_data,
  479. },
  480. {
  481. .ctl_name = KERN_MSGMNI,
  482. .procname = "msgmni",
  483. .data = &init_ipc_ns.msg_ctlmni,
  484. .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
  485. .mode = 0644,
  486. .proc_handler = &proc_ipc_dointvec,
  487. .strategy = sysctl_ipc_data,
  488. },
  489. {
  490. .ctl_name = KERN_MSGMNB,
  491. .procname = "msgmnb",
  492. .data = &init_ipc_ns.msg_ctlmnb,
  493. .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
  494. .mode = 0644,
  495. .proc_handler = &proc_ipc_dointvec,
  496. .strategy = sysctl_ipc_data,
  497. },
  498. {
  499. .ctl_name = KERN_SEM,
  500. .procname = "sem",
  501. .data = &init_ipc_ns.sem_ctls,
  502. .maxlen = 4*sizeof (int),
  503. .mode = 0644,
  504. .proc_handler = &proc_ipc_dointvec,
  505. .strategy = sysctl_ipc_data,
  506. },
  507. #endif
  508. #ifdef CONFIG_MAGIC_SYSRQ
  509. {
  510. .ctl_name = KERN_SYSRQ,
  511. .procname = "sysrq",
  512. .data = &__sysrq_enabled,
  513. .maxlen = sizeof (int),
  514. .mode = 0644,
  515. .proc_handler = &proc_dointvec,
  516. },
  517. #endif
  518. #ifdef CONFIG_PROC_SYSCTL
  519. {
  520. .ctl_name = KERN_CADPID,
  521. .procname = "cad_pid",
  522. .data = NULL,
  523. .maxlen = sizeof (int),
  524. .mode = 0600,
  525. .proc_handler = &proc_do_cad_pid,
  526. },
  527. #endif
  528. {
  529. .ctl_name = KERN_MAX_THREADS,
  530. .procname = "threads-max",
  531. .data = &max_threads,
  532. .maxlen = sizeof(int),
  533. .mode = 0644,
  534. .proc_handler = &proc_dointvec,
  535. },
  536. {
  537. .ctl_name = KERN_RANDOM,
  538. .procname = "random",
  539. .mode = 0555,
  540. .child = random_table,
  541. },
  542. #ifdef CONFIG_UNIX98_PTYS
  543. {
  544. .ctl_name = KERN_PTY,
  545. .procname = "pty",
  546. .mode = 0555,
  547. .child = pty_table,
  548. },
  549. #endif
  550. {
  551. .ctl_name = KERN_OVERFLOWUID,
  552. .procname = "overflowuid",
  553. .data = &overflowuid,
  554. .maxlen = sizeof(int),
  555. .mode = 0644,
  556. .proc_handler = &proc_dointvec_minmax,
  557. .strategy = &sysctl_intvec,
  558. .extra1 = &minolduid,
  559. .extra2 = &maxolduid,
  560. },
  561. {
  562. .ctl_name = KERN_OVERFLOWGID,
  563. .procname = "overflowgid",
  564. .data = &overflowgid,
  565. .maxlen = sizeof(int),
  566. .mode = 0644,
  567. .proc_handler = &proc_dointvec_minmax,
  568. .strategy = &sysctl_intvec,
  569. .extra1 = &minolduid,
  570. .extra2 = &maxolduid,
  571. },
  572. #ifdef CONFIG_S390
  573. #ifdef CONFIG_MATHEMU
  574. {
  575. .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
  576. .procname = "ieee_emulation_warnings",
  577. .data = &sysctl_ieee_emulation_warnings,
  578. .maxlen = sizeof(int),
  579. .mode = 0644,
  580. .proc_handler = &proc_dointvec,
  581. },
  582. #endif
  583. #ifdef CONFIG_NO_IDLE_HZ
  584. {
  585. .ctl_name = KERN_HZ_TIMER,
  586. .procname = "hz_timer",
  587. .data = &sysctl_hz_timer,
  588. .maxlen = sizeof(int),
  589. .mode = 0644,
  590. .proc_handler = &proc_dointvec,
  591. },
  592. #endif
  593. {
  594. .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
  595. .procname = "userprocess_debug",
  596. .data = &sysctl_userprocess_debug,
  597. .maxlen = sizeof(int),
  598. .mode = 0644,
  599. .proc_handler = &proc_dointvec,
  600. },
  601. #endif
  602. {
  603. .ctl_name = KERN_PIDMAX,
  604. .procname = "pid_max",
  605. .data = &pid_max,
  606. .maxlen = sizeof (int),
  607. .mode = 0644,
  608. .proc_handler = &proc_dointvec_minmax,
  609. .strategy = sysctl_intvec,
  610. .extra1 = &pid_max_min,
  611. .extra2 = &pid_max_max,
  612. },
  613. {
  614. .ctl_name = KERN_PANIC_ON_OOPS,
  615. .procname = "panic_on_oops",
  616. .data = &panic_on_oops,
  617. .maxlen = sizeof(int),
  618. .mode = 0644,
  619. .proc_handler = &proc_dointvec,
  620. },
  621. {
  622. .ctl_name = KERN_PRINTK_RATELIMIT,
  623. .procname = "printk_ratelimit",
  624. .data = &printk_ratelimit_jiffies,
  625. .maxlen = sizeof(int),
  626. .mode = 0644,
  627. .proc_handler = &proc_dointvec_jiffies,
  628. .strategy = &sysctl_jiffies,
  629. },
  630. {
  631. .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
  632. .procname = "printk_ratelimit_burst",
  633. .data = &printk_ratelimit_burst,
  634. .maxlen = sizeof(int),
  635. .mode = 0644,
  636. .proc_handler = &proc_dointvec,
  637. },
  638. {
  639. .ctl_name = KERN_NGROUPS_MAX,
  640. .procname = "ngroups_max",
  641. .data = &ngroups_max,
  642. .maxlen = sizeof (int),
  643. .mode = 0444,
  644. .proc_handler = &proc_dointvec,
  645. },
  646. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
  647. {
  648. .ctl_name = KERN_UNKNOWN_NMI_PANIC,
  649. .procname = "unknown_nmi_panic",
  650. .data = &unknown_nmi_panic,
  651. .maxlen = sizeof (int),
  652. .mode = 0644,
  653. .proc_handler = &proc_dointvec,
  654. },
  655. {
  656. .ctl_name = KERN_NMI_WATCHDOG,
  657. .procname = "nmi_watchdog",
  658. .data = &nmi_watchdog_enabled,
  659. .maxlen = sizeof (int),
  660. .mode = 0644,
  661. .proc_handler = &proc_nmi_enabled,
  662. },
  663. #endif
  664. #if defined(CONFIG_X86)
  665. {
  666. .ctl_name = KERN_PANIC_ON_NMI,
  667. .procname = "panic_on_unrecovered_nmi",
  668. .data = &panic_on_unrecovered_nmi,
  669. .maxlen = sizeof(int),
  670. .mode = 0644,
  671. .proc_handler = &proc_dointvec,
  672. },
  673. {
  674. .ctl_name = KERN_BOOTLOADER_TYPE,
  675. .procname = "bootloader_type",
  676. .data = &bootloader_type,
  677. .maxlen = sizeof (int),
  678. .mode = 0444,
  679. .proc_handler = &proc_dointvec,
  680. },
  681. {
  682. .ctl_name = CTL_UNNUMBERED,
  683. .procname = "kstack_depth_to_print",
  684. .data = &kstack_depth_to_print,
  685. .maxlen = sizeof(int),
  686. .mode = 0644,
  687. .proc_handler = &proc_dointvec,
  688. },
  689. #endif
  690. #if defined(CONFIG_MMU)
  691. {
  692. .ctl_name = KERN_RANDOMIZE,
  693. .procname = "randomize_va_space",
  694. .data = &randomize_va_space,
  695. .maxlen = sizeof(int),
  696. .mode = 0644,
  697. .proc_handler = &proc_dointvec,
  698. },
  699. #endif
  700. #if defined(CONFIG_S390) && defined(CONFIG_SMP)
  701. {
  702. .ctl_name = KERN_SPIN_RETRY,
  703. .procname = "spin_retry",
  704. .data = &spin_retry,
  705. .maxlen = sizeof (int),
  706. .mode = 0644,
  707. .proc_handler = &proc_dointvec,
  708. },
  709. #endif
  710. #ifdef CONFIG_ACPI_SLEEP
  711. {
  712. .ctl_name = KERN_ACPI_VIDEO_FLAGS,
  713. .procname = "acpi_video_flags",
  714. .data = &acpi_video_flags,
  715. .maxlen = sizeof (unsigned long),
  716. .mode = 0644,
  717. .proc_handler = &proc_doulongvec_minmax,
  718. },
  719. #endif
  720. #ifdef CONFIG_IA64
  721. {
  722. .ctl_name = KERN_IA64_UNALIGNED,
  723. .procname = "ignore-unaligned-usertrap",
  724. .data = &no_unaligned_warning,
  725. .maxlen = sizeof (int),
  726. .mode = 0644,
  727. .proc_handler = &proc_dointvec,
  728. },
  729. #endif
  730. #ifdef CONFIG_COMPAT
  731. {
  732. .ctl_name = KERN_COMPAT_LOG,
  733. .procname = "compat-log",
  734. .data = &compat_log,
  735. .maxlen = sizeof (int),
  736. .mode = 0644,
  737. .proc_handler = &proc_dointvec,
  738. },
  739. #endif
  740. #ifdef CONFIG_RT_MUTEXES
  741. {
  742. .ctl_name = KERN_MAX_LOCK_DEPTH,
  743. .procname = "max_lock_depth",
  744. .data = &max_lock_depth,
  745. .maxlen = sizeof(int),
  746. .mode = 0644,
  747. .proc_handler = &proc_dointvec,
  748. },
  749. #endif
  750. { .ctl_name = 0 }
  751. };
  752. /* Constants for minimum and maximum testing in vm_table.
  753. We use these as one-element integer vectors. */
  754. static int zero;
  755. static int one_hundred = 100;
  756. static ctl_table vm_table[] = {
  757. {
  758. .ctl_name = VM_OVERCOMMIT_MEMORY,
  759. .procname = "overcommit_memory",
  760. .data = &sysctl_overcommit_memory,
  761. .maxlen = sizeof(sysctl_overcommit_memory),
  762. .mode = 0644,
  763. .proc_handler = &proc_dointvec,
  764. },
  765. {
  766. .ctl_name = VM_PANIC_ON_OOM,
  767. .procname = "panic_on_oom",
  768. .data = &sysctl_panic_on_oom,
  769. .maxlen = sizeof(sysctl_panic_on_oom),
  770. .mode = 0644,
  771. .proc_handler = &proc_dointvec,
  772. },
  773. {
  774. .ctl_name = VM_OVERCOMMIT_RATIO,
  775. .procname = "overcommit_ratio",
  776. .data = &sysctl_overcommit_ratio,
  777. .maxlen = sizeof(sysctl_overcommit_ratio),
  778. .mode = 0644,
  779. .proc_handler = &proc_dointvec,
  780. },
  781. {
  782. .ctl_name = VM_PAGE_CLUSTER,
  783. .procname = "page-cluster",
  784. .data = &page_cluster,
  785. .maxlen = sizeof(int),
  786. .mode = 0644,
  787. .proc_handler = &proc_dointvec,
  788. },
  789. {
  790. .ctl_name = VM_DIRTY_BACKGROUND,
  791. .procname = "dirty_background_ratio",
  792. .data = &dirty_background_ratio,
  793. .maxlen = sizeof(dirty_background_ratio),
  794. .mode = 0644,
  795. .proc_handler = &proc_dointvec_minmax,
  796. .strategy = &sysctl_intvec,
  797. .extra1 = &zero,
  798. .extra2 = &one_hundred,
  799. },
  800. {
  801. .ctl_name = VM_DIRTY_RATIO,
  802. .procname = "dirty_ratio",
  803. .data = &vm_dirty_ratio,
  804. .maxlen = sizeof(vm_dirty_ratio),
  805. .mode = 0644,
  806. .proc_handler = &proc_dointvec_minmax,
  807. .strategy = &sysctl_intvec,
  808. .extra1 = &zero,
  809. .extra2 = &one_hundred,
  810. },
  811. {
  812. .ctl_name = VM_DIRTY_WB_CS,
  813. .procname = "dirty_writeback_centisecs",
  814. .data = &dirty_writeback_interval,
  815. .maxlen = sizeof(dirty_writeback_interval),
  816. .mode = 0644,
  817. .proc_handler = &dirty_writeback_centisecs_handler,
  818. },
  819. {
  820. .ctl_name = VM_DIRTY_EXPIRE_CS,
  821. .procname = "dirty_expire_centisecs",
  822. .data = &dirty_expire_interval,
  823. .maxlen = sizeof(dirty_expire_interval),
  824. .mode = 0644,
  825. .proc_handler = &proc_dointvec_userhz_jiffies,
  826. },
  827. {
  828. .ctl_name = VM_NR_PDFLUSH_THREADS,
  829. .procname = "nr_pdflush_threads",
  830. .data = &nr_pdflush_threads,
  831. .maxlen = sizeof nr_pdflush_threads,
  832. .mode = 0444 /* read-only*/,
  833. .proc_handler = &proc_dointvec,
  834. },
  835. {
  836. .ctl_name = VM_SWAPPINESS,
  837. .procname = "swappiness",
  838. .data = &vm_swappiness,
  839. .maxlen = sizeof(vm_swappiness),
  840. .mode = 0644,
  841. .proc_handler = &proc_dointvec_minmax,
  842. .strategy = &sysctl_intvec,
  843. .extra1 = &zero,
  844. .extra2 = &one_hundred,
  845. },
  846. #ifdef CONFIG_HUGETLB_PAGE
  847. {
  848. .ctl_name = VM_HUGETLB_PAGES,
  849. .procname = "nr_hugepages",
  850. .data = &max_huge_pages,
  851. .maxlen = sizeof(unsigned long),
  852. .mode = 0644,
  853. .proc_handler = &hugetlb_sysctl_handler,
  854. .extra1 = (void *)&hugetlb_zero,
  855. .extra2 = (void *)&hugetlb_infinity,
  856. },
  857. {
  858. .ctl_name = VM_HUGETLB_GROUP,
  859. .procname = "hugetlb_shm_group",
  860. .data = &sysctl_hugetlb_shm_group,
  861. .maxlen = sizeof(gid_t),
  862. .mode = 0644,
  863. .proc_handler = &proc_dointvec,
  864. },
  865. #endif
  866. {
  867. .ctl_name = VM_LOWMEM_RESERVE_RATIO,
  868. .procname = "lowmem_reserve_ratio",
  869. .data = &sysctl_lowmem_reserve_ratio,
  870. .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
  871. .mode = 0644,
  872. .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
  873. .strategy = &sysctl_intvec,
  874. },
  875. {
  876. .ctl_name = VM_DROP_PAGECACHE,
  877. .procname = "drop_caches",
  878. .data = &sysctl_drop_caches,
  879. .maxlen = sizeof(int),
  880. .mode = 0644,
  881. .proc_handler = drop_caches_sysctl_handler,
  882. .strategy = &sysctl_intvec,
  883. },
  884. {
  885. .ctl_name = VM_MIN_FREE_KBYTES,
  886. .procname = "min_free_kbytes",
  887. .data = &min_free_kbytes,
  888. .maxlen = sizeof(min_free_kbytes),
  889. .mode = 0644,
  890. .proc_handler = &min_free_kbytes_sysctl_handler,
  891. .strategy = &sysctl_intvec,
  892. .extra1 = &zero,
  893. },
  894. {
  895. .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
  896. .procname = "percpu_pagelist_fraction",
  897. .data = &percpu_pagelist_fraction,
  898. .maxlen = sizeof(percpu_pagelist_fraction),
  899. .mode = 0644,
  900. .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
  901. .strategy = &sysctl_intvec,
  902. .extra1 = &min_percpu_pagelist_fract,
  903. },
  904. #ifdef CONFIG_MMU
  905. {
  906. .ctl_name = VM_MAX_MAP_COUNT,
  907. .procname = "max_map_count",
  908. .data = &sysctl_max_map_count,
  909. .maxlen = sizeof(sysctl_max_map_count),
  910. .mode = 0644,
  911. .proc_handler = &proc_dointvec
  912. },
  913. #endif
  914. {
  915. .ctl_name = VM_LAPTOP_MODE,
  916. .procname = "laptop_mode",
  917. .data = &laptop_mode,
  918. .maxlen = sizeof(laptop_mode),
  919. .mode = 0644,
  920. .proc_handler = &proc_dointvec_jiffies,
  921. .strategy = &sysctl_jiffies,
  922. },
  923. {
  924. .ctl_name = VM_BLOCK_DUMP,
  925. .procname = "block_dump",
  926. .data = &block_dump,
  927. .maxlen = sizeof(block_dump),
  928. .mode = 0644,
  929. .proc_handler = &proc_dointvec,
  930. .strategy = &sysctl_intvec,
  931. .extra1 = &zero,
  932. },
  933. {
  934. .ctl_name = VM_VFS_CACHE_PRESSURE,
  935. .procname = "vfs_cache_pressure",
  936. .data = &sysctl_vfs_cache_pressure,
  937. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  938. .mode = 0644,
  939. .proc_handler = &proc_dointvec,
  940. .strategy = &sysctl_intvec,
  941. .extra1 = &zero,
  942. },
  943. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  944. {
  945. .ctl_name = VM_LEGACY_VA_LAYOUT,
  946. .procname = "legacy_va_layout",
  947. .data = &sysctl_legacy_va_layout,
  948. .maxlen = sizeof(sysctl_legacy_va_layout),
  949. .mode = 0644,
  950. .proc_handler = &proc_dointvec,
  951. .strategy = &sysctl_intvec,
  952. .extra1 = &zero,
  953. },
  954. #endif
  955. #ifdef CONFIG_NUMA
  956. {
  957. .ctl_name = VM_ZONE_RECLAIM_MODE,
  958. .procname = "zone_reclaim_mode",
  959. .data = &zone_reclaim_mode,
  960. .maxlen = sizeof(zone_reclaim_mode),
  961. .mode = 0644,
  962. .proc_handler = &proc_dointvec,
  963. .strategy = &sysctl_intvec,
  964. .extra1 = &zero,
  965. },
  966. {
  967. .ctl_name = VM_MIN_UNMAPPED,
  968. .procname = "min_unmapped_ratio",
  969. .data = &sysctl_min_unmapped_ratio,
  970. .maxlen = sizeof(sysctl_min_unmapped_ratio),
  971. .mode = 0644,
  972. .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
  973. .strategy = &sysctl_intvec,
  974. .extra1 = &zero,
  975. .extra2 = &one_hundred,
  976. },
  977. {
  978. .ctl_name = VM_MIN_SLAB,
  979. .procname = "min_slab_ratio",
  980. .data = &sysctl_min_slab_ratio,
  981. .maxlen = sizeof(sysctl_min_slab_ratio),
  982. .mode = 0644,
  983. .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
  984. .strategy = &sysctl_intvec,
  985. .extra1 = &zero,
  986. .extra2 = &one_hundred,
  987. },
  988. #endif
  989. #ifdef CONFIG_X86_32
  990. {
  991. .ctl_name = VM_VDSO_ENABLED,
  992. .procname = "vdso_enabled",
  993. .data = &vdso_enabled,
  994. .maxlen = sizeof(vdso_enabled),
  995. .mode = 0644,
  996. .proc_handler = &proc_dointvec,
  997. .strategy = &sysctl_intvec,
  998. .extra1 = &zero,
  999. },
  1000. #endif
  1001. { .ctl_name = 0 }
  1002. };
  1003. static ctl_table fs_table[] = {
  1004. {
  1005. .ctl_name = FS_NRINODE,
  1006. .procname = "inode-nr",
  1007. .data = &inodes_stat,
  1008. .maxlen = 2*sizeof(int),
  1009. .mode = 0444,
  1010. .proc_handler = &proc_dointvec,
  1011. },
  1012. {
  1013. .ctl_name = FS_STATINODE,
  1014. .procname = "inode-state",
  1015. .data = &inodes_stat,
  1016. .maxlen = 7*sizeof(int),
  1017. .mode = 0444,
  1018. .proc_handler = &proc_dointvec,
  1019. },
  1020. {
  1021. .ctl_name = FS_NRFILE,
  1022. .procname = "file-nr",
  1023. .data = &files_stat,
  1024. .maxlen = 3*sizeof(int),
  1025. .mode = 0444,
  1026. .proc_handler = &proc_nr_files,
  1027. },
  1028. {
  1029. .ctl_name = FS_MAXFILE,
  1030. .procname = "file-max",
  1031. .data = &files_stat.max_files,
  1032. .maxlen = sizeof(int),
  1033. .mode = 0644,
  1034. .proc_handler = &proc_dointvec,
  1035. },
  1036. {
  1037. .ctl_name = FS_DENTRY,
  1038. .procname = "dentry-state",
  1039. .data = &dentry_stat,
  1040. .maxlen = 6*sizeof(int),
  1041. .mode = 0444,
  1042. .proc_handler = &proc_dointvec,
  1043. },
  1044. {
  1045. .ctl_name = FS_OVERFLOWUID,
  1046. .procname = "overflowuid",
  1047. .data = &fs_overflowuid,
  1048. .maxlen = sizeof(int),
  1049. .mode = 0644,
  1050. .proc_handler = &proc_dointvec_minmax,
  1051. .strategy = &sysctl_intvec,
  1052. .extra1 = &minolduid,
  1053. .extra2 = &maxolduid,
  1054. },
  1055. {
  1056. .ctl_name = FS_OVERFLOWGID,
  1057. .procname = "overflowgid",
  1058. .data = &fs_overflowgid,
  1059. .maxlen = sizeof(int),
  1060. .mode = 0644,
  1061. .proc_handler = &proc_dointvec_minmax,
  1062. .strategy = &sysctl_intvec,
  1063. .extra1 = &minolduid,
  1064. .extra2 = &maxolduid,
  1065. },
  1066. {
  1067. .ctl_name = FS_LEASES,
  1068. .procname = "leases-enable",
  1069. .data = &leases_enable,
  1070. .maxlen = sizeof(int),
  1071. .mode = 0644,
  1072. .proc_handler = &proc_dointvec,
  1073. },
  1074. #ifdef CONFIG_DNOTIFY
  1075. {
  1076. .ctl_name = FS_DIR_NOTIFY,
  1077. .procname = "dir-notify-enable",
  1078. .data = &dir_notify_enable,
  1079. .maxlen = sizeof(int),
  1080. .mode = 0644,
  1081. .proc_handler = &proc_dointvec,
  1082. },
  1083. #endif
  1084. #ifdef CONFIG_MMU
  1085. {
  1086. .ctl_name = FS_LEASE_TIME,
  1087. .procname = "lease-break-time",
  1088. .data = &lease_break_time,
  1089. .maxlen = sizeof(int),
  1090. .mode = 0644,
  1091. .proc_handler = &proc_dointvec,
  1092. },
  1093. {
  1094. .ctl_name = FS_AIO_NR,
  1095. .procname = "aio-nr",
  1096. .data = &aio_nr,
  1097. .maxlen = sizeof(aio_nr),
  1098. .mode = 0444,
  1099. .proc_handler = &proc_doulongvec_minmax,
  1100. },
  1101. {
  1102. .ctl_name = FS_AIO_MAX_NR,
  1103. .procname = "aio-max-nr",
  1104. .data = &aio_max_nr,
  1105. .maxlen = sizeof(aio_max_nr),
  1106. .mode = 0644,
  1107. .proc_handler = &proc_doulongvec_minmax,
  1108. },
  1109. #ifdef CONFIG_INOTIFY_USER
  1110. {
  1111. .ctl_name = FS_INOTIFY,
  1112. .procname = "inotify",
  1113. .mode = 0555,
  1114. .child = inotify_table,
  1115. },
  1116. #endif
  1117. #endif
  1118. {
  1119. .ctl_name = KERN_SETUID_DUMPABLE,
  1120. .procname = "suid_dumpable",
  1121. .data = &suid_dumpable,
  1122. .maxlen = sizeof(int),
  1123. .mode = 0644,
  1124. .proc_handler = &proc_dointvec,
  1125. },
  1126. { .ctl_name = 0 }
  1127. };
  1128. static ctl_table debug_table[] = {
  1129. { .ctl_name = 0 }
  1130. };
  1131. static ctl_table dev_table[] = {
  1132. { .ctl_name = 0 }
  1133. };
  1134. extern void init_irq_proc (void);
  1135. static DEFINE_SPINLOCK(sysctl_lock);
  1136. /* called under sysctl_lock */
  1137. static int use_table(struct ctl_table_header *p)
  1138. {
  1139. if (unlikely(p->unregistering))
  1140. return 0;
  1141. p->used++;
  1142. return 1;
  1143. }
  1144. /* called under sysctl_lock */
  1145. static void unuse_table(struct ctl_table_header *p)
  1146. {
  1147. if (!--p->used)
  1148. if (unlikely(p->unregistering))
  1149. complete(p->unregistering);
  1150. }
  1151. /* called under sysctl_lock, will reacquire if has to wait */
  1152. static void start_unregistering(struct ctl_table_header *p)
  1153. {
  1154. /*
  1155. * if p->used is 0, nobody will ever touch that entry again;
  1156. * we'll eliminate all paths to it before dropping sysctl_lock
  1157. */
  1158. if (unlikely(p->used)) {
  1159. struct completion wait;
  1160. init_completion(&wait);
  1161. p->unregistering = &wait;
  1162. spin_unlock(&sysctl_lock);
  1163. wait_for_completion(&wait);
  1164. spin_lock(&sysctl_lock);
  1165. }
  1166. /*
  1167. * do not remove from the list until nobody holds it; walking the
  1168. * list in do_sysctl() relies on that.
  1169. */
  1170. list_del_init(&p->ctl_entry);
  1171. }
  1172. void __init sysctl_init(void)
  1173. {
  1174. #ifdef CONFIG_PROC_SYSCTL
  1175. register_proc_table(root_table, proc_sys_root, &root_table_header);
  1176. init_irq_proc();
  1177. #endif
  1178. }
  1179. #ifdef CONFIG_SYSCTL_SYSCALL
  1180. int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
  1181. void __user *newval, size_t newlen)
  1182. {
  1183. struct list_head *tmp;
  1184. int error = -ENOTDIR;
  1185. if (nlen <= 0 || nlen >= CTL_MAXNAME)
  1186. return -ENOTDIR;
  1187. if (oldval) {
  1188. int old_len;
  1189. if (!oldlenp || get_user(old_len, oldlenp))
  1190. return -EFAULT;
  1191. }
  1192. spin_lock(&sysctl_lock);
  1193. tmp = &root_table_header.ctl_entry;
  1194. do {
  1195. struct ctl_table_header *head =
  1196. list_entry(tmp, struct ctl_table_header, ctl_entry);
  1197. if (!use_table(head))
  1198. continue;
  1199. spin_unlock(&sysctl_lock);
  1200. error = parse_table(name, nlen, oldval, oldlenp,
  1201. newval, newlen, head->ctl_table);
  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)
  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);
  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);
  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)
  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);
  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. *lenp = 0;
  1598. return 0;
  1599. }
  1600. if (write) {
  1601. len = 0;
  1602. p = buffer;
  1603. while (len < *lenp) {
  1604. if (get_user(c, p++))
  1605. return -EFAULT;
  1606. if (c == 0 || c == '\n')
  1607. break;
  1608. len++;
  1609. }
  1610. if (len >= maxlen)
  1611. len = maxlen-1;
  1612. if(copy_from_user(data, buffer, len))
  1613. return -EFAULT;
  1614. ((char *) data)[len] = 0;
  1615. *ppos += *lenp;
  1616. } else {
  1617. len = strlen(data);
  1618. if (len > maxlen)
  1619. len = maxlen;
  1620. if (*ppos > len) {
  1621. *lenp = 0;
  1622. return 0;
  1623. }
  1624. data += *ppos;
  1625. len -= *ppos;
  1626. if (len > *lenp)
  1627. len = *lenp;
  1628. if (len)
  1629. if(copy_to_user(buffer, data, len))
  1630. return -EFAULT;
  1631. if (len < *lenp) {
  1632. if(put_user('\n', ((char __user *) buffer) + len))
  1633. return -EFAULT;
  1634. len++;
  1635. }
  1636. *lenp = len;
  1637. *ppos += len;
  1638. }
  1639. return 0;
  1640. }
  1641. /**
  1642. * proc_dostring - read a string sysctl
  1643. * @table: the sysctl table
  1644. * @write: %TRUE if this is a write to the sysctl file
  1645. * @filp: the file structure
  1646. * @buffer: the user buffer
  1647. * @lenp: the size of the user buffer
  1648. * @ppos: file position
  1649. *
  1650. * Reads/writes a string from/to the user buffer. If the kernel
  1651. * buffer provided is not large enough to hold the string, the
  1652. * string is truncated. The copied string is %NULL-terminated.
  1653. * If the string is being read by the user process, it is copied
  1654. * and a newline '\n' is added. It is truncated if the buffer is
  1655. * not large enough.
  1656. *
  1657. * Returns 0 on success.
  1658. */
  1659. int proc_dostring(ctl_table *table, int write, struct file *filp,
  1660. void __user *buffer, size_t *lenp, loff_t *ppos)
  1661. {
  1662. return _proc_do_string(table->data, table->maxlen, write, filp,
  1663. buffer, lenp, ppos);
  1664. }
  1665. /*
  1666. * Special case of dostring for the UTS structure. This has locks
  1667. * to observe. Should this be in kernel/sys.c ????
  1668. */
  1669. static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
  1670. void __user *buffer, size_t *lenp, loff_t *ppos)
  1671. {
  1672. int r;
  1673. void *which;
  1674. which = get_uts(table, write);
  1675. r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
  1676. put_uts(table, write, which);
  1677. return r;
  1678. }
  1679. static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
  1680. int *valp,
  1681. int write, void *data)
  1682. {
  1683. if (write) {
  1684. *valp = *negp ? -*lvalp : *lvalp;
  1685. } else {
  1686. int val = *valp;
  1687. if (val < 0) {
  1688. *negp = -1;
  1689. *lvalp = (unsigned long)-val;
  1690. } else {
  1691. *negp = 0;
  1692. *lvalp = (unsigned long)val;
  1693. }
  1694. }
  1695. return 0;
  1696. }
  1697. static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
  1698. int write, struct file *filp, void __user *buffer,
  1699. size_t *lenp, loff_t *ppos,
  1700. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1701. int write, void *data),
  1702. void *data)
  1703. {
  1704. #define TMPBUFLEN 21
  1705. int *i, vleft, first=1, neg, val;
  1706. unsigned long lval;
  1707. size_t left, len;
  1708. char buf[TMPBUFLEN], *p;
  1709. char __user *s = buffer;
  1710. if (!tbl_data || !table->maxlen || !*lenp ||
  1711. (*ppos && !write)) {
  1712. *lenp = 0;
  1713. return 0;
  1714. }
  1715. i = (int *) tbl_data;
  1716. vleft = table->maxlen / sizeof(*i);
  1717. left = *lenp;
  1718. if (!conv)
  1719. conv = do_proc_dointvec_conv;
  1720. for (; left && vleft--; i++, first=0) {
  1721. if (write) {
  1722. while (left) {
  1723. char c;
  1724. if (get_user(c, s))
  1725. return -EFAULT;
  1726. if (!isspace(c))
  1727. break;
  1728. left--;
  1729. s++;
  1730. }
  1731. if (!left)
  1732. break;
  1733. neg = 0;
  1734. len = left;
  1735. if (len > sizeof(buf) - 1)
  1736. len = sizeof(buf) - 1;
  1737. if (copy_from_user(buf, s, len))
  1738. return -EFAULT;
  1739. buf[len] = 0;
  1740. p = buf;
  1741. if (*p == '-' && left > 1) {
  1742. neg = 1;
  1743. p++;
  1744. }
  1745. if (*p < '0' || *p > '9')
  1746. break;
  1747. lval = simple_strtoul(p, &p, 0);
  1748. len = p-buf;
  1749. if ((len < left) && *p && !isspace(*p))
  1750. break;
  1751. if (neg)
  1752. val = -val;
  1753. s += len;
  1754. left -= len;
  1755. if (conv(&neg, &lval, i, 1, data))
  1756. break;
  1757. } else {
  1758. p = buf;
  1759. if (!first)
  1760. *p++ = '\t';
  1761. if (conv(&neg, &lval, i, 0, data))
  1762. break;
  1763. sprintf(p, "%s%lu", neg ? "-" : "", lval);
  1764. len = strlen(buf);
  1765. if (len > left)
  1766. len = left;
  1767. if(copy_to_user(s, buf, len))
  1768. return -EFAULT;
  1769. left -= len;
  1770. s += len;
  1771. }
  1772. }
  1773. if (!write && !first && left) {
  1774. if(put_user('\n', s))
  1775. return -EFAULT;
  1776. left--, s++;
  1777. }
  1778. if (write) {
  1779. while (left) {
  1780. char c;
  1781. if (get_user(c, s++))
  1782. return -EFAULT;
  1783. if (!isspace(c))
  1784. break;
  1785. left--;
  1786. }
  1787. }
  1788. if (write && first)
  1789. return -EINVAL;
  1790. *lenp -= left;
  1791. *ppos += *lenp;
  1792. return 0;
  1793. #undef TMPBUFLEN
  1794. }
  1795. static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
  1796. void __user *buffer, size_t *lenp, loff_t *ppos,
  1797. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1798. int write, void *data),
  1799. void *data)
  1800. {
  1801. return __do_proc_dointvec(table->data, table, write, filp,
  1802. buffer, lenp, ppos, conv, data);
  1803. }
  1804. /**
  1805. * proc_dointvec - read a vector of integers
  1806. * @table: the sysctl table
  1807. * @write: %TRUE if this is a write to the sysctl file
  1808. * @filp: the file structure
  1809. * @buffer: the user buffer
  1810. * @lenp: the size of the user buffer
  1811. * @ppos: file position
  1812. *
  1813. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1814. * values from/to the user buffer, treated as an ASCII string.
  1815. *
  1816. * Returns 0 on success.
  1817. */
  1818. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  1819. void __user *buffer, size_t *lenp, loff_t *ppos)
  1820. {
  1821. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1822. NULL,NULL);
  1823. }
  1824. #define OP_SET 0
  1825. #define OP_AND 1
  1826. #define OP_OR 2
  1827. static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
  1828. int *valp,
  1829. int write, void *data)
  1830. {
  1831. int op = *(int *)data;
  1832. if (write) {
  1833. int val = *negp ? -*lvalp : *lvalp;
  1834. switch(op) {
  1835. case OP_SET: *valp = val; break;
  1836. case OP_AND: *valp &= val; break;
  1837. case OP_OR: *valp |= val; break;
  1838. }
  1839. } else {
  1840. int val = *valp;
  1841. if (val < 0) {
  1842. *negp = -1;
  1843. *lvalp = (unsigned long)-val;
  1844. } else {
  1845. *negp = 0;
  1846. *lvalp = (unsigned long)val;
  1847. }
  1848. }
  1849. return 0;
  1850. }
  1851. /*
  1852. * init may raise the set.
  1853. */
  1854. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  1855. void __user *buffer, size_t *lenp, loff_t *ppos)
  1856. {
  1857. int op;
  1858. if (write && !capable(CAP_SYS_MODULE)) {
  1859. return -EPERM;
  1860. }
  1861. op = is_init(current) ? OP_SET : OP_AND;
  1862. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1863. do_proc_dointvec_bset_conv,&op);
  1864. }
  1865. /*
  1866. * Taint values can only be increased
  1867. */
  1868. static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
  1869. void __user *buffer, size_t *lenp, loff_t *ppos)
  1870. {
  1871. int op;
  1872. if (!capable(CAP_SYS_ADMIN))
  1873. return -EPERM;
  1874. op = OP_OR;
  1875. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1876. do_proc_dointvec_bset_conv,&op);
  1877. }
  1878. struct do_proc_dointvec_minmax_conv_param {
  1879. int *min;
  1880. int *max;
  1881. };
  1882. static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
  1883. int *valp,
  1884. int write, void *data)
  1885. {
  1886. struct do_proc_dointvec_minmax_conv_param *param = data;
  1887. if (write) {
  1888. int val = *negp ? -*lvalp : *lvalp;
  1889. if ((param->min && *param->min > val) ||
  1890. (param->max && *param->max < val))
  1891. return -EINVAL;
  1892. *valp = val;
  1893. } else {
  1894. int val = *valp;
  1895. if (val < 0) {
  1896. *negp = -1;
  1897. *lvalp = (unsigned long)-val;
  1898. } else {
  1899. *negp = 0;
  1900. *lvalp = (unsigned long)val;
  1901. }
  1902. }
  1903. return 0;
  1904. }
  1905. /**
  1906. * proc_dointvec_minmax - read a vector of integers with min/max values
  1907. * @table: the sysctl table
  1908. * @write: %TRUE if this is a write to the sysctl file
  1909. * @filp: the file structure
  1910. * @buffer: the user buffer
  1911. * @lenp: the size of the user buffer
  1912. * @ppos: file position
  1913. *
  1914. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1915. * values from/to the user buffer, treated as an ASCII string.
  1916. *
  1917. * This routine will ensure the values are within the range specified by
  1918. * table->extra1 (min) and table->extra2 (max).
  1919. *
  1920. * Returns 0 on success.
  1921. */
  1922. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  1923. void __user *buffer, size_t *lenp, loff_t *ppos)
  1924. {
  1925. struct do_proc_dointvec_minmax_conv_param param = {
  1926. .min = (int *) table->extra1,
  1927. .max = (int *) table->extra2,
  1928. };
  1929. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  1930. do_proc_dointvec_minmax_conv, &param);
  1931. }
  1932. static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
  1933. struct file *filp,
  1934. void __user *buffer,
  1935. size_t *lenp, loff_t *ppos,
  1936. unsigned long convmul,
  1937. unsigned long convdiv)
  1938. {
  1939. #define TMPBUFLEN 21
  1940. unsigned long *i, *min, *max, val;
  1941. int vleft, first=1, neg;
  1942. size_t len, left;
  1943. char buf[TMPBUFLEN], *p;
  1944. char __user *s = buffer;
  1945. if (!data || !table->maxlen || !*lenp ||
  1946. (*ppos && !write)) {
  1947. *lenp = 0;
  1948. return 0;
  1949. }
  1950. i = (unsigned long *) data;
  1951. min = (unsigned long *) table->extra1;
  1952. max = (unsigned long *) table->extra2;
  1953. vleft = table->maxlen / sizeof(unsigned long);
  1954. left = *lenp;
  1955. for (; left && vleft--; i++, min++, max++, first=0) {
  1956. if (write) {
  1957. while (left) {
  1958. char c;
  1959. if (get_user(c, s))
  1960. return -EFAULT;
  1961. if (!isspace(c))
  1962. break;
  1963. left--;
  1964. s++;
  1965. }
  1966. if (!left)
  1967. break;
  1968. neg = 0;
  1969. len = left;
  1970. if (len > TMPBUFLEN-1)
  1971. len = TMPBUFLEN-1;
  1972. if (copy_from_user(buf, s, len))
  1973. return -EFAULT;
  1974. buf[len] = 0;
  1975. p = buf;
  1976. if (*p == '-' && left > 1) {
  1977. neg = 1;
  1978. p++;
  1979. }
  1980. if (*p < '0' || *p > '9')
  1981. break;
  1982. val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
  1983. len = p-buf;
  1984. if ((len < left) && *p && !isspace(*p))
  1985. break;
  1986. if (neg)
  1987. val = -val;
  1988. s += len;
  1989. left -= len;
  1990. if(neg)
  1991. continue;
  1992. if ((min && val < *min) || (max && val > *max))
  1993. continue;
  1994. *i = val;
  1995. } else {
  1996. p = buf;
  1997. if (!first)
  1998. *p++ = '\t';
  1999. sprintf(p, "%lu", convdiv * (*i) / convmul);
  2000. len = strlen(buf);
  2001. if (len > left)
  2002. len = left;
  2003. if(copy_to_user(s, buf, len))
  2004. return -EFAULT;
  2005. left -= len;
  2006. s += len;
  2007. }
  2008. }
  2009. if (!write && !first && left) {
  2010. if(put_user('\n', s))
  2011. return -EFAULT;
  2012. left--, s++;
  2013. }
  2014. if (write) {
  2015. while (left) {
  2016. char c;
  2017. if (get_user(c, s++))
  2018. return -EFAULT;
  2019. if (!isspace(c))
  2020. break;
  2021. left--;
  2022. }
  2023. }
  2024. if (write && first)
  2025. return -EINVAL;
  2026. *lenp -= left;
  2027. *ppos += *lenp;
  2028. return 0;
  2029. #undef TMPBUFLEN
  2030. }
  2031. static int do_proc_doulongvec_minmax(ctl_table *table, int write,
  2032. struct file *filp,
  2033. void __user *buffer,
  2034. size_t *lenp, loff_t *ppos,
  2035. unsigned long convmul,
  2036. unsigned long convdiv)
  2037. {
  2038. return __do_proc_doulongvec_minmax(table->data, table, write,
  2039. filp, buffer, lenp, ppos, convmul, convdiv);
  2040. }
  2041. /**
  2042. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  2043. * @table: the sysctl table
  2044. * @write: %TRUE if this is a write to the sysctl file
  2045. * @filp: the file structure
  2046. * @buffer: the user buffer
  2047. * @lenp: the size of the user buffer
  2048. * @ppos: file position
  2049. *
  2050. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2051. * values from/to the user buffer, treated as an ASCII string.
  2052. *
  2053. * This routine will ensure the values are within the range specified by
  2054. * table->extra1 (min) and table->extra2 (max).
  2055. *
  2056. * Returns 0 on success.
  2057. */
  2058. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2059. void __user *buffer, size_t *lenp, loff_t *ppos)
  2060. {
  2061. return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
  2062. }
  2063. /**
  2064. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  2065. * @table: the sysctl table
  2066. * @write: %TRUE if this is a write to the sysctl file
  2067. * @filp: the file structure
  2068. * @buffer: the user buffer
  2069. * @lenp: the size of the user buffer
  2070. * @ppos: file position
  2071. *
  2072. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2073. * values from/to the user buffer, treated as an ASCII string. The values
  2074. * are treated as milliseconds, and converted to jiffies when they are stored.
  2075. *
  2076. * This routine will ensure the values are within the range specified by
  2077. * table->extra1 (min) and table->extra2 (max).
  2078. *
  2079. * Returns 0 on success.
  2080. */
  2081. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2082. struct file *filp,
  2083. void __user *buffer,
  2084. size_t *lenp, loff_t *ppos)
  2085. {
  2086. return do_proc_doulongvec_minmax(table, write, filp, buffer,
  2087. lenp, ppos, HZ, 1000l);
  2088. }
  2089. static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
  2090. int *valp,
  2091. int write, void *data)
  2092. {
  2093. if (write) {
  2094. if (*lvalp > LONG_MAX / HZ)
  2095. return 1;
  2096. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  2097. } else {
  2098. int val = *valp;
  2099. unsigned long lval;
  2100. if (val < 0) {
  2101. *negp = -1;
  2102. lval = (unsigned long)-val;
  2103. } else {
  2104. *negp = 0;
  2105. lval = (unsigned long)val;
  2106. }
  2107. *lvalp = lval / HZ;
  2108. }
  2109. return 0;
  2110. }
  2111. static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
  2112. int *valp,
  2113. int write, void *data)
  2114. {
  2115. if (write) {
  2116. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  2117. return 1;
  2118. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  2119. } else {
  2120. int val = *valp;
  2121. unsigned long lval;
  2122. if (val < 0) {
  2123. *negp = -1;
  2124. lval = (unsigned long)-val;
  2125. } else {
  2126. *negp = 0;
  2127. lval = (unsigned long)val;
  2128. }
  2129. *lvalp = jiffies_to_clock_t(lval);
  2130. }
  2131. return 0;
  2132. }
  2133. static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
  2134. int *valp,
  2135. int write, void *data)
  2136. {
  2137. if (write) {
  2138. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  2139. } else {
  2140. int val = *valp;
  2141. unsigned long lval;
  2142. if (val < 0) {
  2143. *negp = -1;
  2144. lval = (unsigned long)-val;
  2145. } else {
  2146. *negp = 0;
  2147. lval = (unsigned long)val;
  2148. }
  2149. *lvalp = jiffies_to_msecs(lval);
  2150. }
  2151. return 0;
  2152. }
  2153. /**
  2154. * proc_dointvec_jiffies - read a vector of integers as seconds
  2155. * @table: the sysctl table
  2156. * @write: %TRUE if this is a write to the sysctl file
  2157. * @filp: the file structure
  2158. * @buffer: the user buffer
  2159. * @lenp: the size of the user buffer
  2160. * @ppos: file position
  2161. *
  2162. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2163. * values from/to the user buffer, treated as an ASCII string.
  2164. * The values read are assumed to be in seconds, and are converted into
  2165. * jiffies.
  2166. *
  2167. * Returns 0 on success.
  2168. */
  2169. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2170. void __user *buffer, size_t *lenp, loff_t *ppos)
  2171. {
  2172. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2173. do_proc_dointvec_jiffies_conv,NULL);
  2174. }
  2175. /**
  2176. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  2177. * @table: the sysctl table
  2178. * @write: %TRUE if this is a write to the sysctl file
  2179. * @filp: the file structure
  2180. * @buffer: the user buffer
  2181. * @lenp: the size of the user buffer
  2182. * @ppos: pointer to the file position
  2183. *
  2184. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2185. * values from/to the user buffer, treated as an ASCII string.
  2186. * The values read are assumed to be in 1/USER_HZ seconds, and
  2187. * are converted into jiffies.
  2188. *
  2189. * Returns 0 on success.
  2190. */
  2191. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2192. void __user *buffer, size_t *lenp, loff_t *ppos)
  2193. {
  2194. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2195. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2196. }
  2197. /**
  2198. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2199. * @table: the sysctl table
  2200. * @write: %TRUE if this is a write to the sysctl file
  2201. * @filp: the file structure
  2202. * @buffer: the user buffer
  2203. * @lenp: the size of the user buffer
  2204. * @ppos: file position
  2205. * @ppos: the current position in the file
  2206. *
  2207. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2208. * values from/to the user buffer, treated as an ASCII string.
  2209. * The values read are assumed to be in 1/1000 seconds, and
  2210. * are converted into jiffies.
  2211. *
  2212. * Returns 0 on success.
  2213. */
  2214. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2215. void __user *buffer, size_t *lenp, loff_t *ppos)
  2216. {
  2217. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  2218. do_proc_dointvec_ms_jiffies_conv, NULL);
  2219. }
  2220. #ifdef CONFIG_SYSVIPC
  2221. static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
  2222. void __user *buffer, size_t *lenp, loff_t *ppos)
  2223. {
  2224. void *which;
  2225. which = get_ipc(table, write);
  2226. return __do_proc_dointvec(which, table, write, filp, buffer,
  2227. lenp, ppos, NULL, NULL);
  2228. }
  2229. static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
  2230. struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
  2231. {
  2232. void *which;
  2233. which = get_ipc(table, write);
  2234. return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
  2235. lenp, ppos, 1l, 1l);
  2236. }
  2237. #endif
  2238. static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
  2239. void __user *buffer, size_t *lenp, loff_t *ppos)
  2240. {
  2241. struct pid *new_pid;
  2242. pid_t tmp;
  2243. int r;
  2244. tmp = pid_nr(cad_pid);
  2245. r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
  2246. lenp, ppos, NULL, NULL);
  2247. if (r || !write)
  2248. return r;
  2249. new_pid = find_get_pid(tmp);
  2250. if (!new_pid)
  2251. return -ESRCH;
  2252. put_pid(xchg(&cad_pid, new_pid));
  2253. return 0;
  2254. }
  2255. #else /* CONFIG_PROC_FS */
  2256. int proc_dostring(ctl_table *table, int write, struct file *filp,
  2257. void __user *buffer, size_t *lenp, loff_t *ppos)
  2258. {
  2259. return -ENOSYS;
  2260. }
  2261. static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
  2262. void __user *buffer, size_t *lenp, loff_t *ppos)
  2263. {
  2264. return -ENOSYS;
  2265. }
  2266. #ifdef CONFIG_SYSVIPC
  2267. static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
  2268. void __user *buffer, size_t *lenp, loff_t *ppos)
  2269. {
  2270. return -ENOSYS;
  2271. }
  2272. static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
  2273. void __user *buffer, size_t *lenp, loff_t *ppos)
  2274. {
  2275. return -ENOSYS;
  2276. }
  2277. static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
  2278. struct file *filp, void __user *buffer,
  2279. size_t *lenp, loff_t *ppos)
  2280. {
  2281. return -ENOSYS;
  2282. }
  2283. #endif
  2284. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2285. void __user *buffer, size_t *lenp, loff_t *ppos)
  2286. {
  2287. return -ENOSYS;
  2288. }
  2289. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2290. void __user *buffer, size_t *lenp, loff_t *ppos)
  2291. {
  2292. return -ENOSYS;
  2293. }
  2294. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2295. void __user *buffer, size_t *lenp, loff_t *ppos)
  2296. {
  2297. return -ENOSYS;
  2298. }
  2299. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2300. void __user *buffer, size_t *lenp, loff_t *ppos)
  2301. {
  2302. return -ENOSYS;
  2303. }
  2304. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2305. void __user *buffer, size_t *lenp, loff_t *ppos)
  2306. {
  2307. return -ENOSYS;
  2308. }
  2309. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2310. void __user *buffer, size_t *lenp, loff_t *ppos)
  2311. {
  2312. return -ENOSYS;
  2313. }
  2314. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2315. void __user *buffer, size_t *lenp, loff_t *ppos)
  2316. {
  2317. return -ENOSYS;
  2318. }
  2319. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2320. struct file *filp,
  2321. void __user *buffer,
  2322. size_t *lenp, loff_t *ppos)
  2323. {
  2324. return -ENOSYS;
  2325. }
  2326. #endif /* CONFIG_PROC_FS */
  2327. #ifdef CONFIG_SYSCTL_SYSCALL
  2328. /*
  2329. * General sysctl support routines
  2330. */
  2331. /* The generic string strategy routine: */
  2332. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2333. void __user *oldval, size_t __user *oldlenp,
  2334. void __user *newval, size_t newlen)
  2335. {
  2336. if (!table->data || !table->maxlen)
  2337. return -ENOTDIR;
  2338. if (oldval && oldlenp) {
  2339. size_t bufsize;
  2340. if (get_user(bufsize, oldlenp))
  2341. return -EFAULT;
  2342. if (bufsize) {
  2343. size_t len = strlen(table->data), copied;
  2344. /* This shouldn't trigger for a well-formed sysctl */
  2345. if (len > table->maxlen)
  2346. len = table->maxlen;
  2347. /* Copy up to a max of bufsize-1 bytes of the string */
  2348. copied = (len >= bufsize) ? bufsize - 1 : len;
  2349. if (copy_to_user(oldval, table->data, copied) ||
  2350. put_user(0, (char __user *)(oldval + copied)))
  2351. return -EFAULT;
  2352. if (put_user(len, oldlenp))
  2353. return -EFAULT;
  2354. }
  2355. }
  2356. if (newval && newlen) {
  2357. size_t len = newlen;
  2358. if (len > table->maxlen)
  2359. len = table->maxlen;
  2360. if(copy_from_user(table->data, newval, len))
  2361. return -EFAULT;
  2362. if (len == table->maxlen)
  2363. len--;
  2364. ((char *) table->data)[len] = 0;
  2365. }
  2366. return 1;
  2367. }
  2368. /*
  2369. * This function makes sure that all of the integers in the vector
  2370. * are between the minimum and maximum values given in the arrays
  2371. * table->extra1 and table->extra2, respectively.
  2372. */
  2373. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2374. void __user *oldval, size_t __user *oldlenp,
  2375. void __user *newval, size_t newlen)
  2376. {
  2377. if (newval && newlen) {
  2378. int __user *vec = (int __user *) newval;
  2379. int *min = (int *) table->extra1;
  2380. int *max = (int *) table->extra2;
  2381. size_t length;
  2382. int i;
  2383. if (newlen % sizeof(int) != 0)
  2384. return -EINVAL;
  2385. if (!table->extra1 && !table->extra2)
  2386. return 0;
  2387. if (newlen > table->maxlen)
  2388. newlen = table->maxlen;
  2389. length = newlen / sizeof(int);
  2390. for (i = 0; i < length; i++) {
  2391. int value;
  2392. if (get_user(value, vec + i))
  2393. return -EFAULT;
  2394. if (min && value < min[i])
  2395. return -EINVAL;
  2396. if (max && value > max[i])
  2397. return -EINVAL;
  2398. }
  2399. }
  2400. return 0;
  2401. }
  2402. /* Strategy function to convert jiffies to seconds */
  2403. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2404. void __user *oldval, size_t __user *oldlenp,
  2405. void __user *newval, size_t newlen)
  2406. {
  2407. if (oldval && oldlenp) {
  2408. size_t olen;
  2409. if (get_user(olen, oldlenp))
  2410. return -EFAULT;
  2411. if (olen) {
  2412. int val;
  2413. if (olen < sizeof(int))
  2414. return -EINVAL;
  2415. val = *(int *)(table->data) / HZ;
  2416. if (put_user(val, (int __user *)oldval))
  2417. return -EFAULT;
  2418. if (put_user(sizeof(int), oldlenp))
  2419. return -EFAULT;
  2420. }
  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) = new*HZ;
  2429. }
  2430. return 1;
  2431. }
  2432. /* Strategy function to convert jiffies to seconds */
  2433. int sysctl_ms_jiffies(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. if (oldval && oldlenp) {
  2438. size_t olen;
  2439. if (get_user(olen, oldlenp))
  2440. return -EFAULT;
  2441. if (olen) {
  2442. int val;
  2443. if (olen < sizeof(int))
  2444. return -EINVAL;
  2445. val = jiffies_to_msecs(*(int *)(table->data));
  2446. if (put_user(val, (int __user *)oldval))
  2447. return -EFAULT;
  2448. if (put_user(sizeof(int), oldlenp))
  2449. return -EFAULT;
  2450. }
  2451. }
  2452. if (newval && newlen) {
  2453. int new;
  2454. if (newlen != sizeof(int))
  2455. return -EINVAL;
  2456. if (get_user(new, (int __user *)newval))
  2457. return -EFAULT;
  2458. *(int *)(table->data) = msecs_to_jiffies(new);
  2459. }
  2460. return 1;
  2461. }
  2462. /* The generic string strategy routine: */
  2463. static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
  2464. void __user *oldval, size_t __user *oldlenp,
  2465. void __user *newval, size_t newlen)
  2466. {
  2467. struct ctl_table uts_table;
  2468. int r, write;
  2469. write = newval && newlen;
  2470. memcpy(&uts_table, table, sizeof(uts_table));
  2471. uts_table.data = get_uts(table, write);
  2472. r = sysctl_string(&uts_table, name, nlen,
  2473. oldval, oldlenp, newval, newlen);
  2474. put_uts(table, write, uts_table.data);
  2475. return r;
  2476. }
  2477. #ifdef CONFIG_SYSVIPC
  2478. /* The generic sysctl ipc data routine. */
  2479. static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
  2480. void __user *oldval, size_t __user *oldlenp,
  2481. void __user *newval, size_t newlen)
  2482. {
  2483. size_t len;
  2484. void *data;
  2485. /* Get out of I don't have a variable */
  2486. if (!table->data || !table->maxlen)
  2487. return -ENOTDIR;
  2488. data = get_ipc(table, 1);
  2489. if (!data)
  2490. return -ENOTDIR;
  2491. if (oldval && oldlenp) {
  2492. if (get_user(len, oldlenp))
  2493. return -EFAULT;
  2494. if (len) {
  2495. if (len > table->maxlen)
  2496. len = table->maxlen;
  2497. if (copy_to_user(oldval, data, len))
  2498. return -EFAULT;
  2499. if (put_user(len, oldlenp))
  2500. return -EFAULT;
  2501. }
  2502. }
  2503. if (newval && newlen) {
  2504. if (newlen > table->maxlen)
  2505. newlen = table->maxlen;
  2506. if (copy_from_user(data, newval, newlen))
  2507. return -EFAULT;
  2508. }
  2509. return 1;
  2510. }
  2511. #endif
  2512. #else /* CONFIG_SYSCTL_SYSCALL */
  2513. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  2514. {
  2515. static int msg_count;
  2516. struct __sysctl_args tmp;
  2517. int name[CTL_MAXNAME];
  2518. int i;
  2519. /* Read in the sysctl name for better debug message logging */
  2520. if (copy_from_user(&tmp, args, sizeof(tmp)))
  2521. return -EFAULT;
  2522. if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
  2523. return -ENOTDIR;
  2524. for (i = 0; i < tmp.nlen; i++)
  2525. if (get_user(name[i], tmp.name + i))
  2526. return -EFAULT;
  2527. /* Ignore accesses to kernel.version */
  2528. if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
  2529. goto out;
  2530. if (msg_count < 5) {
  2531. msg_count++;
  2532. printk(KERN_INFO
  2533. "warning: process `%s' used the removed sysctl "
  2534. "system call with ", current->comm);
  2535. for (i = 0; i < tmp.nlen; i++)
  2536. printk("%d.", name[i]);
  2537. printk("\n");
  2538. }
  2539. out:
  2540. return -ENOSYS;
  2541. }
  2542. int sysctl_string(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. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2549. void __user *oldval, size_t __user *oldlenp,
  2550. void __user *newval, size_t newlen)
  2551. {
  2552. return -ENOSYS;
  2553. }
  2554. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2555. void __user *oldval, size_t __user *oldlenp,
  2556. void __user *newval, size_t newlen)
  2557. {
  2558. return -ENOSYS;
  2559. }
  2560. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2561. void __user *oldval, size_t __user *oldlenp,
  2562. void __user *newval, size_t newlen)
  2563. {
  2564. return -ENOSYS;
  2565. }
  2566. static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
  2567. void __user *oldval, size_t __user *oldlenp,
  2568. void __user *newval, size_t newlen)
  2569. {
  2570. return -ENOSYS;
  2571. }
  2572. #ifdef CONFIG_SYSVIPC
  2573. static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
  2574. void __user *oldval, size_t __user *oldlenp,
  2575. void __user *newval, size_t newlen)
  2576. {
  2577. return -ENOSYS;
  2578. }
  2579. #endif
  2580. #endif /* CONFIG_SYSCTL_SYSCALL */
  2581. /*
  2582. * No sense putting this after each symbol definition, twice,
  2583. * exception granted :-)
  2584. */
  2585. EXPORT_SYMBOL(proc_dointvec);
  2586. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2587. EXPORT_SYMBOL(proc_dointvec_minmax);
  2588. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2589. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2590. EXPORT_SYMBOL(proc_dostring);
  2591. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2592. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2593. EXPORT_SYMBOL(register_sysctl_table);
  2594. EXPORT_SYMBOL(sysctl_intvec);
  2595. EXPORT_SYMBOL(sysctl_jiffies);
  2596. EXPORT_SYMBOL(sysctl_ms_jiffies);
  2597. EXPORT_SYMBOL(sysctl_string);
  2598. EXPORT_SYMBOL(unregister_sysctl_table);