sysctl.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802
  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. static DEFINE_SPINLOCK(sysctl_lock);
  1135. /* called under sysctl_lock */
  1136. static int use_table(struct ctl_table_header *p)
  1137. {
  1138. if (unlikely(p->unregistering))
  1139. return 0;
  1140. p->used++;
  1141. return 1;
  1142. }
  1143. /* called under sysctl_lock */
  1144. static void unuse_table(struct ctl_table_header *p)
  1145. {
  1146. if (!--p->used)
  1147. if (unlikely(p->unregistering))
  1148. complete(p->unregistering);
  1149. }
  1150. /* called under sysctl_lock, will reacquire if has to wait */
  1151. static void start_unregistering(struct ctl_table_header *p)
  1152. {
  1153. /*
  1154. * if p->used is 0, nobody will ever touch that entry again;
  1155. * we'll eliminate all paths to it before dropping sysctl_lock
  1156. */
  1157. if (unlikely(p->used)) {
  1158. struct completion wait;
  1159. init_completion(&wait);
  1160. p->unregistering = &wait;
  1161. spin_unlock(&sysctl_lock);
  1162. wait_for_completion(&wait);
  1163. spin_lock(&sysctl_lock);
  1164. }
  1165. /*
  1166. * do not remove from the list until nobody holds it; walking the
  1167. * list in do_sysctl() relies on that.
  1168. */
  1169. list_del_init(&p->ctl_entry);
  1170. }
  1171. void __init sysctl_init(void)
  1172. {
  1173. #ifdef CONFIG_PROC_SYSCTL
  1174. register_proc_table(root_table, proc_sys_root, &root_table_header);
  1175. #endif
  1176. }
  1177. #ifdef CONFIG_SYSCTL_SYSCALL
  1178. int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
  1179. void __user *newval, size_t newlen)
  1180. {
  1181. struct list_head *tmp;
  1182. int error = -ENOTDIR;
  1183. if (nlen <= 0 || nlen >= CTL_MAXNAME)
  1184. return -ENOTDIR;
  1185. if (oldval) {
  1186. int old_len;
  1187. if (!oldlenp || get_user(old_len, oldlenp))
  1188. return -EFAULT;
  1189. }
  1190. spin_lock(&sysctl_lock);
  1191. tmp = &root_table_header.ctl_entry;
  1192. do {
  1193. struct ctl_table_header *head =
  1194. list_entry(tmp, struct ctl_table_header, ctl_entry);
  1195. if (!use_table(head))
  1196. continue;
  1197. spin_unlock(&sysctl_lock);
  1198. error = parse_table(name, nlen, oldval, oldlenp,
  1199. newval, newlen, head->ctl_table);
  1200. spin_lock(&sysctl_lock);
  1201. unuse_table(head);
  1202. if (error != -ENOTDIR)
  1203. break;
  1204. } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
  1205. spin_unlock(&sysctl_lock);
  1206. return error;
  1207. }
  1208. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  1209. {
  1210. struct __sysctl_args tmp;
  1211. int error;
  1212. if (copy_from_user(&tmp, args, sizeof(tmp)))
  1213. return -EFAULT;
  1214. lock_kernel();
  1215. error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
  1216. tmp.newval, tmp.newlen);
  1217. unlock_kernel();
  1218. return error;
  1219. }
  1220. #endif /* CONFIG_SYSCTL_SYSCALL */
  1221. /*
  1222. * ctl_perm does NOT grant the superuser all rights automatically, because
  1223. * some sysctl variables are readonly even to root.
  1224. */
  1225. static int test_perm(int mode, int op)
  1226. {
  1227. if (!current->euid)
  1228. mode >>= 6;
  1229. else if (in_egroup_p(0))
  1230. mode >>= 3;
  1231. if ((mode & op & 0007) == op)
  1232. return 0;
  1233. return -EACCES;
  1234. }
  1235. static inline int ctl_perm(ctl_table *table, int op)
  1236. {
  1237. int error;
  1238. error = security_sysctl(table, op);
  1239. if (error)
  1240. return error;
  1241. return test_perm(table->mode, op);
  1242. }
  1243. #ifdef CONFIG_SYSCTL_SYSCALL
  1244. static int parse_table(int __user *name, int nlen,
  1245. void __user *oldval, size_t __user *oldlenp,
  1246. void __user *newval, size_t newlen,
  1247. ctl_table *table)
  1248. {
  1249. int n;
  1250. repeat:
  1251. if (!nlen)
  1252. return -ENOTDIR;
  1253. if (get_user(n, name))
  1254. return -EFAULT;
  1255. for ( ; table->ctl_name || table->procname; table++) {
  1256. if (!table->ctl_name)
  1257. continue;
  1258. if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
  1259. int error;
  1260. if (table->child) {
  1261. if (ctl_perm(table, 001))
  1262. return -EPERM;
  1263. if (table->strategy) {
  1264. error = table->strategy(
  1265. table, name, nlen,
  1266. oldval, oldlenp,
  1267. newval, newlen);
  1268. if (error)
  1269. return error;
  1270. }
  1271. name++;
  1272. nlen--;
  1273. table = table->child;
  1274. goto repeat;
  1275. }
  1276. error = do_sysctl_strategy(table, name, nlen,
  1277. oldval, oldlenp,
  1278. newval, newlen);
  1279. return error;
  1280. }
  1281. }
  1282. return -ENOTDIR;
  1283. }
  1284. /* Perform the actual read/write of a sysctl table entry. */
  1285. int do_sysctl_strategy (ctl_table *table,
  1286. int __user *name, int nlen,
  1287. void __user *oldval, size_t __user *oldlenp,
  1288. void __user *newval, size_t newlen)
  1289. {
  1290. int op = 0, rc;
  1291. size_t len;
  1292. if (oldval)
  1293. op |= 004;
  1294. if (newval)
  1295. op |= 002;
  1296. if (ctl_perm(table, op))
  1297. return -EPERM;
  1298. if (table->strategy) {
  1299. rc = table->strategy(table, name, nlen, oldval, oldlenp,
  1300. newval, newlen);
  1301. if (rc < 0)
  1302. return rc;
  1303. if (rc > 0)
  1304. return 0;
  1305. }
  1306. /* If there is no strategy routine, or if the strategy returns
  1307. * zero, proceed with automatic r/w */
  1308. if (table->data && table->maxlen) {
  1309. if (oldval && oldlenp) {
  1310. if (get_user(len, oldlenp))
  1311. return -EFAULT;
  1312. if (len) {
  1313. if (len > table->maxlen)
  1314. len = table->maxlen;
  1315. if(copy_to_user(oldval, table->data, len))
  1316. return -EFAULT;
  1317. if(put_user(len, oldlenp))
  1318. return -EFAULT;
  1319. }
  1320. }
  1321. if (newval && newlen) {
  1322. len = newlen;
  1323. if (len > table->maxlen)
  1324. len = table->maxlen;
  1325. if(copy_from_user(table->data, newval, len))
  1326. return -EFAULT;
  1327. }
  1328. }
  1329. return 0;
  1330. }
  1331. #endif /* CONFIG_SYSCTL_SYSCALL */
  1332. /**
  1333. * register_sysctl_table - register a sysctl hierarchy
  1334. * @table: the top-level table structure
  1335. * @insert_at_head: whether the entry should be inserted in front or at the end
  1336. *
  1337. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1338. * array. An entry with a ctl_name of 0 terminates the table.
  1339. *
  1340. * The members of the &ctl_table structure are used as follows:
  1341. *
  1342. * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
  1343. * must be unique within that level of sysctl
  1344. *
  1345. * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
  1346. * enter a sysctl file
  1347. *
  1348. * data - a pointer to data for use by proc_handler
  1349. *
  1350. * maxlen - the maximum size in bytes of the data
  1351. *
  1352. * mode - the file permissions for the /proc/sys file, and for sysctl(2)
  1353. *
  1354. * child - a pointer to the child sysctl table if this entry is a directory, or
  1355. * %NULL.
  1356. *
  1357. * proc_handler - the text handler routine (described below)
  1358. *
  1359. * strategy - the strategy routine (described below)
  1360. *
  1361. * de - for internal use by the sysctl routines
  1362. *
  1363. * extra1, extra2 - extra pointers usable by the proc handler routines
  1364. *
  1365. * Leaf nodes in the sysctl tree will be represented by a single file
  1366. * under /proc; non-leaf nodes will be represented by directories.
  1367. *
  1368. * sysctl(2) can automatically manage read and write requests through
  1369. * the sysctl table. The data and maxlen fields of the ctl_table
  1370. * struct enable minimal validation of the values being written to be
  1371. * performed, and the mode field allows minimal authentication.
  1372. *
  1373. * More sophisticated management can be enabled by the provision of a
  1374. * strategy routine with the table entry. This will be called before
  1375. * any automatic read or write of the data is performed.
  1376. *
  1377. * The strategy routine may return
  1378. *
  1379. * < 0 - Error occurred (error is passed to user process)
  1380. *
  1381. * 0 - OK - proceed with automatic read or write.
  1382. *
  1383. * > 0 - OK - read or write has been done by the strategy routine, so
  1384. * return immediately.
  1385. *
  1386. * There must be a proc_handler routine for any terminal nodes
  1387. * mirrored under /proc/sys (non-terminals are handled by a built-in
  1388. * directory handler). Several default handlers are available to
  1389. * cover common cases -
  1390. *
  1391. * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
  1392. * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
  1393. * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
  1394. *
  1395. * It is the handler's job to read the input buffer from user memory
  1396. * and process it. The handler should return 0 on success.
  1397. *
  1398. * This routine returns %NULL on a failure to register, and a pointer
  1399. * to the table header on success.
  1400. */
  1401. struct ctl_table_header *register_sysctl_table(ctl_table * table,
  1402. int insert_at_head)
  1403. {
  1404. struct ctl_table_header *tmp;
  1405. tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
  1406. if (!tmp)
  1407. return NULL;
  1408. tmp->ctl_table = table;
  1409. INIT_LIST_HEAD(&tmp->ctl_entry);
  1410. tmp->used = 0;
  1411. tmp->unregistering = NULL;
  1412. spin_lock(&sysctl_lock);
  1413. if (insert_at_head)
  1414. list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1415. else
  1416. list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1417. spin_unlock(&sysctl_lock);
  1418. #ifdef CONFIG_PROC_SYSCTL
  1419. register_proc_table(table, proc_sys_root, tmp);
  1420. #endif
  1421. return tmp;
  1422. }
  1423. /**
  1424. * unregister_sysctl_table - unregister a sysctl table hierarchy
  1425. * @header: the header returned from register_sysctl_table
  1426. *
  1427. * Unregisters the sysctl table and all children. proc entries may not
  1428. * actually be removed until they are no longer used by anyone.
  1429. */
  1430. void unregister_sysctl_table(struct ctl_table_header * header)
  1431. {
  1432. might_sleep();
  1433. spin_lock(&sysctl_lock);
  1434. start_unregistering(header);
  1435. #ifdef CONFIG_PROC_SYSCTL
  1436. unregister_proc_table(header->ctl_table, proc_sys_root);
  1437. #endif
  1438. spin_unlock(&sysctl_lock);
  1439. kfree(header);
  1440. }
  1441. #else /* !CONFIG_SYSCTL */
  1442. struct ctl_table_header * register_sysctl_table(ctl_table * table,
  1443. int insert_at_head)
  1444. {
  1445. return NULL;
  1446. }
  1447. void unregister_sysctl_table(struct ctl_table_header * table)
  1448. {
  1449. }
  1450. #endif /* CONFIG_SYSCTL */
  1451. /*
  1452. * /proc/sys support
  1453. */
  1454. #ifdef CONFIG_PROC_SYSCTL
  1455. /* Scan the sysctl entries in table and add them all into /proc */
  1456. static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
  1457. {
  1458. struct proc_dir_entry *de;
  1459. int len;
  1460. mode_t mode;
  1461. for (; table->ctl_name || table->procname; table++) {
  1462. /* Can't do anything without a proc name. */
  1463. if (!table->procname)
  1464. continue;
  1465. /* Maybe we can't do anything with it... */
  1466. if (!table->proc_handler && !table->child) {
  1467. printk(KERN_WARNING "SYSCTL: Can't register %s\n",
  1468. table->procname);
  1469. continue;
  1470. }
  1471. len = strlen(table->procname);
  1472. mode = table->mode;
  1473. de = NULL;
  1474. if (table->proc_handler)
  1475. mode |= S_IFREG;
  1476. else {
  1477. mode |= S_IFDIR;
  1478. for (de = root->subdir; de; de = de->next) {
  1479. if (proc_match(len, table->procname, de))
  1480. break;
  1481. }
  1482. /* If the subdir exists already, de is non-NULL */
  1483. }
  1484. if (!de) {
  1485. de = create_proc_entry(table->procname, mode, root);
  1486. if (!de)
  1487. continue;
  1488. de->set = set;
  1489. de->data = (void *) table;
  1490. if (table->proc_handler)
  1491. de->proc_fops = &proc_sys_file_operations;
  1492. }
  1493. table->de = de;
  1494. if (de->mode & S_IFDIR)
  1495. register_proc_table(table->child, de, set);
  1496. }
  1497. }
  1498. /*
  1499. * Unregister a /proc sysctl table and any subdirectories.
  1500. */
  1501. static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
  1502. {
  1503. struct proc_dir_entry *de;
  1504. for (; table->ctl_name || table->procname; table++) {
  1505. if (!(de = table->de))
  1506. continue;
  1507. if (de->mode & S_IFDIR) {
  1508. if (!table->child) {
  1509. printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
  1510. continue;
  1511. }
  1512. unregister_proc_table(table->child, de);
  1513. /* Don't unregister directories which still have entries.. */
  1514. if (de->subdir)
  1515. continue;
  1516. }
  1517. /*
  1518. * In any case, mark the entry as goner; we'll keep it
  1519. * around if it's busy, but we'll know to do nothing with
  1520. * its fields. We are under sysctl_lock here.
  1521. */
  1522. de->data = NULL;
  1523. /* Don't unregister proc entries that are still being used.. */
  1524. if (atomic_read(&de->count))
  1525. continue;
  1526. table->de = NULL;
  1527. remove_proc_entry(table->procname, root);
  1528. }
  1529. }
  1530. static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
  1531. size_t count, loff_t *ppos)
  1532. {
  1533. int op;
  1534. struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
  1535. struct ctl_table *table;
  1536. size_t res;
  1537. ssize_t error = -ENOTDIR;
  1538. spin_lock(&sysctl_lock);
  1539. if (de && de->data && use_table(de->set)) {
  1540. /*
  1541. * at that point we know that sysctl was not unregistered
  1542. * and won't be until we finish
  1543. */
  1544. spin_unlock(&sysctl_lock);
  1545. table = (struct ctl_table *) de->data;
  1546. if (!table || !table->proc_handler)
  1547. goto out;
  1548. error = -EPERM;
  1549. op = (write ? 002 : 004);
  1550. if (ctl_perm(table, op))
  1551. goto out;
  1552. /* careful: calling conventions are nasty here */
  1553. res = count;
  1554. error = (*table->proc_handler)(table, write, file,
  1555. buf, &res, ppos);
  1556. if (!error)
  1557. error = res;
  1558. out:
  1559. spin_lock(&sysctl_lock);
  1560. unuse_table(de->set);
  1561. }
  1562. spin_unlock(&sysctl_lock);
  1563. return error;
  1564. }
  1565. static int proc_opensys(struct inode *inode, struct file *file)
  1566. {
  1567. if (file->f_mode & FMODE_WRITE) {
  1568. /*
  1569. * sysctl entries that are not writable,
  1570. * are _NOT_ writable, capabilities or not.
  1571. */
  1572. if (!(inode->i_mode & S_IWUSR))
  1573. return -EPERM;
  1574. }
  1575. return 0;
  1576. }
  1577. static ssize_t proc_readsys(struct file * file, char __user * buf,
  1578. size_t count, loff_t *ppos)
  1579. {
  1580. return do_rw_proc(0, file, buf, count, ppos);
  1581. }
  1582. static ssize_t proc_writesys(struct file * file, const char __user * buf,
  1583. size_t count, loff_t *ppos)
  1584. {
  1585. return do_rw_proc(1, file, (char __user *) buf, count, ppos);
  1586. }
  1587. static int _proc_do_string(void* data, int maxlen, int write,
  1588. struct file *filp, void __user *buffer,
  1589. size_t *lenp, loff_t *ppos)
  1590. {
  1591. size_t len;
  1592. char __user *p;
  1593. char c;
  1594. if (!data || !maxlen || !*lenp) {
  1595. *lenp = 0;
  1596. return 0;
  1597. }
  1598. if (write) {
  1599. len = 0;
  1600. p = buffer;
  1601. while (len < *lenp) {
  1602. if (get_user(c, p++))
  1603. return -EFAULT;
  1604. if (c == 0 || c == '\n')
  1605. break;
  1606. len++;
  1607. }
  1608. if (len >= maxlen)
  1609. len = maxlen-1;
  1610. if(copy_from_user(data, buffer, len))
  1611. return -EFAULT;
  1612. ((char *) data)[len] = 0;
  1613. *ppos += *lenp;
  1614. } else {
  1615. len = strlen(data);
  1616. if (len > maxlen)
  1617. len = maxlen;
  1618. if (*ppos > len) {
  1619. *lenp = 0;
  1620. return 0;
  1621. }
  1622. data += *ppos;
  1623. len -= *ppos;
  1624. if (len > *lenp)
  1625. len = *lenp;
  1626. if (len)
  1627. if(copy_to_user(buffer, data, len))
  1628. return -EFAULT;
  1629. if (len < *lenp) {
  1630. if(put_user('\n', ((char __user *) buffer) + len))
  1631. return -EFAULT;
  1632. len++;
  1633. }
  1634. *lenp = len;
  1635. *ppos += len;
  1636. }
  1637. return 0;
  1638. }
  1639. /**
  1640. * proc_dostring - read a string sysctl
  1641. * @table: the sysctl table
  1642. * @write: %TRUE if this is a write to the sysctl file
  1643. * @filp: the file structure
  1644. * @buffer: the user buffer
  1645. * @lenp: the size of the user buffer
  1646. * @ppos: file position
  1647. *
  1648. * Reads/writes a string from/to the user buffer. If the kernel
  1649. * buffer provided is not large enough to hold the string, the
  1650. * string is truncated. The copied string is %NULL-terminated.
  1651. * If the string is being read by the user process, it is copied
  1652. * and a newline '\n' is added. It is truncated if the buffer is
  1653. * not large enough.
  1654. *
  1655. * Returns 0 on success.
  1656. */
  1657. int proc_dostring(ctl_table *table, int write, struct file *filp,
  1658. void __user *buffer, size_t *lenp, loff_t *ppos)
  1659. {
  1660. return _proc_do_string(table->data, table->maxlen, write, filp,
  1661. buffer, lenp, ppos);
  1662. }
  1663. /*
  1664. * Special case of dostring for the UTS structure. This has locks
  1665. * to observe. Should this be in kernel/sys.c ????
  1666. */
  1667. static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
  1668. void __user *buffer, size_t *lenp, loff_t *ppos)
  1669. {
  1670. int r;
  1671. void *which;
  1672. which = get_uts(table, write);
  1673. r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
  1674. put_uts(table, write, which);
  1675. return r;
  1676. }
  1677. static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
  1678. int *valp,
  1679. int write, void *data)
  1680. {
  1681. if (write) {
  1682. *valp = *negp ? -*lvalp : *lvalp;
  1683. } else {
  1684. int val = *valp;
  1685. if (val < 0) {
  1686. *negp = -1;
  1687. *lvalp = (unsigned long)-val;
  1688. } else {
  1689. *negp = 0;
  1690. *lvalp = (unsigned long)val;
  1691. }
  1692. }
  1693. return 0;
  1694. }
  1695. static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
  1696. int write, struct file *filp, void __user *buffer,
  1697. size_t *lenp, loff_t *ppos,
  1698. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1699. int write, void *data),
  1700. void *data)
  1701. {
  1702. #define TMPBUFLEN 21
  1703. int *i, vleft, first=1, neg, val;
  1704. unsigned long lval;
  1705. size_t left, len;
  1706. char buf[TMPBUFLEN], *p;
  1707. char __user *s = buffer;
  1708. if (!tbl_data || !table->maxlen || !*lenp ||
  1709. (*ppos && !write)) {
  1710. *lenp = 0;
  1711. return 0;
  1712. }
  1713. i = (int *) tbl_data;
  1714. vleft = table->maxlen / sizeof(*i);
  1715. left = *lenp;
  1716. if (!conv)
  1717. conv = do_proc_dointvec_conv;
  1718. for (; left && vleft--; i++, first=0) {
  1719. if (write) {
  1720. while (left) {
  1721. char c;
  1722. if (get_user(c, s))
  1723. return -EFAULT;
  1724. if (!isspace(c))
  1725. break;
  1726. left--;
  1727. s++;
  1728. }
  1729. if (!left)
  1730. break;
  1731. neg = 0;
  1732. len = left;
  1733. if (len > sizeof(buf) - 1)
  1734. len = sizeof(buf) - 1;
  1735. if (copy_from_user(buf, s, len))
  1736. return -EFAULT;
  1737. buf[len] = 0;
  1738. p = buf;
  1739. if (*p == '-' && left > 1) {
  1740. neg = 1;
  1741. p++;
  1742. }
  1743. if (*p < '0' || *p > '9')
  1744. break;
  1745. lval = simple_strtoul(p, &p, 0);
  1746. len = p-buf;
  1747. if ((len < left) && *p && !isspace(*p))
  1748. break;
  1749. if (neg)
  1750. val = -val;
  1751. s += len;
  1752. left -= len;
  1753. if (conv(&neg, &lval, i, 1, data))
  1754. break;
  1755. } else {
  1756. p = buf;
  1757. if (!first)
  1758. *p++ = '\t';
  1759. if (conv(&neg, &lval, i, 0, data))
  1760. break;
  1761. sprintf(p, "%s%lu", neg ? "-" : "", lval);
  1762. len = strlen(buf);
  1763. if (len > left)
  1764. len = left;
  1765. if(copy_to_user(s, buf, len))
  1766. return -EFAULT;
  1767. left -= len;
  1768. s += len;
  1769. }
  1770. }
  1771. if (!write && !first && left) {
  1772. if(put_user('\n', s))
  1773. return -EFAULT;
  1774. left--, s++;
  1775. }
  1776. if (write) {
  1777. while (left) {
  1778. char c;
  1779. if (get_user(c, s++))
  1780. return -EFAULT;
  1781. if (!isspace(c))
  1782. break;
  1783. left--;
  1784. }
  1785. }
  1786. if (write && first)
  1787. return -EINVAL;
  1788. *lenp -= left;
  1789. *ppos += *lenp;
  1790. return 0;
  1791. #undef TMPBUFLEN
  1792. }
  1793. static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
  1794. void __user *buffer, size_t *lenp, loff_t *ppos,
  1795. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1796. int write, void *data),
  1797. void *data)
  1798. {
  1799. return __do_proc_dointvec(table->data, table, write, filp,
  1800. buffer, lenp, ppos, conv, data);
  1801. }
  1802. /**
  1803. * proc_dointvec - read a vector of integers
  1804. * @table: the sysctl table
  1805. * @write: %TRUE if this is a write to the sysctl file
  1806. * @filp: the file structure
  1807. * @buffer: the user buffer
  1808. * @lenp: the size of the user buffer
  1809. * @ppos: file position
  1810. *
  1811. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1812. * values from/to the user buffer, treated as an ASCII string.
  1813. *
  1814. * Returns 0 on success.
  1815. */
  1816. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  1817. void __user *buffer, size_t *lenp, loff_t *ppos)
  1818. {
  1819. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1820. NULL,NULL);
  1821. }
  1822. #define OP_SET 0
  1823. #define OP_AND 1
  1824. #define OP_OR 2
  1825. static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
  1826. int *valp,
  1827. int write, void *data)
  1828. {
  1829. int op = *(int *)data;
  1830. if (write) {
  1831. int val = *negp ? -*lvalp : *lvalp;
  1832. switch(op) {
  1833. case OP_SET: *valp = val; break;
  1834. case OP_AND: *valp &= val; break;
  1835. case OP_OR: *valp |= val; break;
  1836. }
  1837. } else {
  1838. int val = *valp;
  1839. if (val < 0) {
  1840. *negp = -1;
  1841. *lvalp = (unsigned long)-val;
  1842. } else {
  1843. *negp = 0;
  1844. *lvalp = (unsigned long)val;
  1845. }
  1846. }
  1847. return 0;
  1848. }
  1849. /*
  1850. * init may raise the set.
  1851. */
  1852. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  1853. void __user *buffer, size_t *lenp, loff_t *ppos)
  1854. {
  1855. int op;
  1856. if (write && !capable(CAP_SYS_MODULE)) {
  1857. return -EPERM;
  1858. }
  1859. op = is_init(current) ? OP_SET : OP_AND;
  1860. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1861. do_proc_dointvec_bset_conv,&op);
  1862. }
  1863. /*
  1864. * Taint values can only be increased
  1865. */
  1866. static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
  1867. void __user *buffer, size_t *lenp, loff_t *ppos)
  1868. {
  1869. int op;
  1870. if (!capable(CAP_SYS_ADMIN))
  1871. return -EPERM;
  1872. op = OP_OR;
  1873. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1874. do_proc_dointvec_bset_conv,&op);
  1875. }
  1876. struct do_proc_dointvec_minmax_conv_param {
  1877. int *min;
  1878. int *max;
  1879. };
  1880. static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
  1881. int *valp,
  1882. int write, void *data)
  1883. {
  1884. struct do_proc_dointvec_minmax_conv_param *param = data;
  1885. if (write) {
  1886. int val = *negp ? -*lvalp : *lvalp;
  1887. if ((param->min && *param->min > val) ||
  1888. (param->max && *param->max < val))
  1889. return -EINVAL;
  1890. *valp = val;
  1891. } else {
  1892. int val = *valp;
  1893. if (val < 0) {
  1894. *negp = -1;
  1895. *lvalp = (unsigned long)-val;
  1896. } else {
  1897. *negp = 0;
  1898. *lvalp = (unsigned long)val;
  1899. }
  1900. }
  1901. return 0;
  1902. }
  1903. /**
  1904. * proc_dointvec_minmax - read a vector of integers with min/max values
  1905. * @table: the sysctl table
  1906. * @write: %TRUE if this is a write to the sysctl file
  1907. * @filp: the file structure
  1908. * @buffer: the user buffer
  1909. * @lenp: the size of the user buffer
  1910. * @ppos: file position
  1911. *
  1912. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1913. * values from/to the user buffer, treated as an ASCII string.
  1914. *
  1915. * This routine will ensure the values are within the range specified by
  1916. * table->extra1 (min) and table->extra2 (max).
  1917. *
  1918. * Returns 0 on success.
  1919. */
  1920. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  1921. void __user *buffer, size_t *lenp, loff_t *ppos)
  1922. {
  1923. struct do_proc_dointvec_minmax_conv_param param = {
  1924. .min = (int *) table->extra1,
  1925. .max = (int *) table->extra2,
  1926. };
  1927. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  1928. do_proc_dointvec_minmax_conv, &param);
  1929. }
  1930. static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
  1931. struct file *filp,
  1932. void __user *buffer,
  1933. size_t *lenp, loff_t *ppos,
  1934. unsigned long convmul,
  1935. unsigned long convdiv)
  1936. {
  1937. #define TMPBUFLEN 21
  1938. unsigned long *i, *min, *max, val;
  1939. int vleft, first=1, neg;
  1940. size_t len, left;
  1941. char buf[TMPBUFLEN], *p;
  1942. char __user *s = buffer;
  1943. if (!data || !table->maxlen || !*lenp ||
  1944. (*ppos && !write)) {
  1945. *lenp = 0;
  1946. return 0;
  1947. }
  1948. i = (unsigned long *) data;
  1949. min = (unsigned long *) table->extra1;
  1950. max = (unsigned long *) table->extra2;
  1951. vleft = table->maxlen / sizeof(unsigned long);
  1952. left = *lenp;
  1953. for (; left && vleft--; i++, min++, max++, first=0) {
  1954. if (write) {
  1955. while (left) {
  1956. char c;
  1957. if (get_user(c, s))
  1958. return -EFAULT;
  1959. if (!isspace(c))
  1960. break;
  1961. left--;
  1962. s++;
  1963. }
  1964. if (!left)
  1965. break;
  1966. neg = 0;
  1967. len = left;
  1968. if (len > TMPBUFLEN-1)
  1969. len = TMPBUFLEN-1;
  1970. if (copy_from_user(buf, s, len))
  1971. return -EFAULT;
  1972. buf[len] = 0;
  1973. p = buf;
  1974. if (*p == '-' && left > 1) {
  1975. neg = 1;
  1976. p++;
  1977. }
  1978. if (*p < '0' || *p > '9')
  1979. break;
  1980. val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
  1981. len = p-buf;
  1982. if ((len < left) && *p && !isspace(*p))
  1983. break;
  1984. if (neg)
  1985. val = -val;
  1986. s += len;
  1987. left -= len;
  1988. if(neg)
  1989. continue;
  1990. if ((min && val < *min) || (max && val > *max))
  1991. continue;
  1992. *i = val;
  1993. } else {
  1994. p = buf;
  1995. if (!first)
  1996. *p++ = '\t';
  1997. sprintf(p, "%lu", convdiv * (*i) / convmul);
  1998. len = strlen(buf);
  1999. if (len > left)
  2000. len = left;
  2001. if(copy_to_user(s, buf, len))
  2002. return -EFAULT;
  2003. left -= len;
  2004. s += len;
  2005. }
  2006. }
  2007. if (!write && !first && left) {
  2008. if(put_user('\n', s))
  2009. return -EFAULT;
  2010. left--, s++;
  2011. }
  2012. if (write) {
  2013. while (left) {
  2014. char c;
  2015. if (get_user(c, s++))
  2016. return -EFAULT;
  2017. if (!isspace(c))
  2018. break;
  2019. left--;
  2020. }
  2021. }
  2022. if (write && first)
  2023. return -EINVAL;
  2024. *lenp -= left;
  2025. *ppos += *lenp;
  2026. return 0;
  2027. #undef TMPBUFLEN
  2028. }
  2029. static int do_proc_doulongvec_minmax(ctl_table *table, int write,
  2030. struct file *filp,
  2031. void __user *buffer,
  2032. size_t *lenp, loff_t *ppos,
  2033. unsigned long convmul,
  2034. unsigned long convdiv)
  2035. {
  2036. return __do_proc_doulongvec_minmax(table->data, table, write,
  2037. filp, buffer, lenp, ppos, convmul, convdiv);
  2038. }
  2039. /**
  2040. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  2041. * @table: the sysctl table
  2042. * @write: %TRUE if this is a write to the sysctl file
  2043. * @filp: the file structure
  2044. * @buffer: the user buffer
  2045. * @lenp: the size of the user buffer
  2046. * @ppos: file position
  2047. *
  2048. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2049. * values from/to the user buffer, treated as an ASCII string.
  2050. *
  2051. * This routine will ensure the values are within the range specified by
  2052. * table->extra1 (min) and table->extra2 (max).
  2053. *
  2054. * Returns 0 on success.
  2055. */
  2056. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2057. void __user *buffer, size_t *lenp, loff_t *ppos)
  2058. {
  2059. return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
  2060. }
  2061. /**
  2062. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  2063. * @table: the sysctl table
  2064. * @write: %TRUE if this is a write to the sysctl file
  2065. * @filp: the file structure
  2066. * @buffer: the user buffer
  2067. * @lenp: the size of the user buffer
  2068. * @ppos: file position
  2069. *
  2070. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2071. * values from/to the user buffer, treated as an ASCII string. The values
  2072. * are treated as milliseconds, and converted to jiffies when they are stored.
  2073. *
  2074. * This routine will ensure the values are within the range specified by
  2075. * table->extra1 (min) and table->extra2 (max).
  2076. *
  2077. * Returns 0 on success.
  2078. */
  2079. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2080. struct file *filp,
  2081. void __user *buffer,
  2082. size_t *lenp, loff_t *ppos)
  2083. {
  2084. return do_proc_doulongvec_minmax(table, write, filp, buffer,
  2085. lenp, ppos, HZ, 1000l);
  2086. }
  2087. static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
  2088. int *valp,
  2089. int write, void *data)
  2090. {
  2091. if (write) {
  2092. if (*lvalp > LONG_MAX / HZ)
  2093. return 1;
  2094. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  2095. } else {
  2096. int val = *valp;
  2097. unsigned long lval;
  2098. if (val < 0) {
  2099. *negp = -1;
  2100. lval = (unsigned long)-val;
  2101. } else {
  2102. *negp = 0;
  2103. lval = (unsigned long)val;
  2104. }
  2105. *lvalp = lval / HZ;
  2106. }
  2107. return 0;
  2108. }
  2109. static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
  2110. int *valp,
  2111. int write, void *data)
  2112. {
  2113. if (write) {
  2114. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  2115. return 1;
  2116. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  2117. } else {
  2118. int val = *valp;
  2119. unsigned long lval;
  2120. if (val < 0) {
  2121. *negp = -1;
  2122. lval = (unsigned long)-val;
  2123. } else {
  2124. *negp = 0;
  2125. lval = (unsigned long)val;
  2126. }
  2127. *lvalp = jiffies_to_clock_t(lval);
  2128. }
  2129. return 0;
  2130. }
  2131. static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
  2132. int *valp,
  2133. int write, void *data)
  2134. {
  2135. if (write) {
  2136. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  2137. } else {
  2138. int val = *valp;
  2139. unsigned long lval;
  2140. if (val < 0) {
  2141. *negp = -1;
  2142. lval = (unsigned long)-val;
  2143. } else {
  2144. *negp = 0;
  2145. lval = (unsigned long)val;
  2146. }
  2147. *lvalp = jiffies_to_msecs(lval);
  2148. }
  2149. return 0;
  2150. }
  2151. /**
  2152. * proc_dointvec_jiffies - read a vector of integers as seconds
  2153. * @table: the sysctl table
  2154. * @write: %TRUE if this is a write to the sysctl file
  2155. * @filp: the file structure
  2156. * @buffer: the user buffer
  2157. * @lenp: the size of the user buffer
  2158. * @ppos: file position
  2159. *
  2160. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2161. * values from/to the user buffer, treated as an ASCII string.
  2162. * The values read are assumed to be in seconds, and are converted into
  2163. * jiffies.
  2164. *
  2165. * Returns 0 on success.
  2166. */
  2167. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2168. void __user *buffer, size_t *lenp, loff_t *ppos)
  2169. {
  2170. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2171. do_proc_dointvec_jiffies_conv,NULL);
  2172. }
  2173. /**
  2174. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  2175. * @table: the sysctl table
  2176. * @write: %TRUE if this is a write to the sysctl file
  2177. * @filp: the file structure
  2178. * @buffer: the user buffer
  2179. * @lenp: the size of the user buffer
  2180. * @ppos: pointer to the file position
  2181. *
  2182. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2183. * values from/to the user buffer, treated as an ASCII string.
  2184. * The values read are assumed to be in 1/USER_HZ seconds, and
  2185. * are converted into jiffies.
  2186. *
  2187. * Returns 0 on success.
  2188. */
  2189. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2190. void __user *buffer, size_t *lenp, loff_t *ppos)
  2191. {
  2192. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2193. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2194. }
  2195. /**
  2196. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2197. * @table: the sysctl table
  2198. * @write: %TRUE if this is a write to the sysctl file
  2199. * @filp: the file structure
  2200. * @buffer: the user buffer
  2201. * @lenp: the size of the user buffer
  2202. * @ppos: file position
  2203. * @ppos: the current position in the file
  2204. *
  2205. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2206. * values from/to the user buffer, treated as an ASCII string.
  2207. * The values read are assumed to be in 1/1000 seconds, and
  2208. * are converted into jiffies.
  2209. *
  2210. * Returns 0 on success.
  2211. */
  2212. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2213. void __user *buffer, size_t *lenp, loff_t *ppos)
  2214. {
  2215. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  2216. do_proc_dointvec_ms_jiffies_conv, NULL);
  2217. }
  2218. #ifdef CONFIG_SYSVIPC
  2219. static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
  2220. void __user *buffer, size_t *lenp, loff_t *ppos)
  2221. {
  2222. void *which;
  2223. which = get_ipc(table, write);
  2224. return __do_proc_dointvec(which, table, write, filp, buffer,
  2225. lenp, ppos, NULL, NULL);
  2226. }
  2227. static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
  2228. struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
  2229. {
  2230. void *which;
  2231. which = get_ipc(table, write);
  2232. return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
  2233. lenp, ppos, 1l, 1l);
  2234. }
  2235. #endif
  2236. static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
  2237. void __user *buffer, size_t *lenp, loff_t *ppos)
  2238. {
  2239. struct pid *new_pid;
  2240. pid_t tmp;
  2241. int r;
  2242. tmp = pid_nr(cad_pid);
  2243. r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
  2244. lenp, ppos, NULL, NULL);
  2245. if (r || !write)
  2246. return r;
  2247. new_pid = find_get_pid(tmp);
  2248. if (!new_pid)
  2249. return -ESRCH;
  2250. put_pid(xchg(&cad_pid, new_pid));
  2251. return 0;
  2252. }
  2253. #else /* CONFIG_PROC_FS */
  2254. int proc_dostring(ctl_table *table, int write, struct file *filp,
  2255. void __user *buffer, size_t *lenp, loff_t *ppos)
  2256. {
  2257. return -ENOSYS;
  2258. }
  2259. static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
  2260. void __user *buffer, size_t *lenp, loff_t *ppos)
  2261. {
  2262. return -ENOSYS;
  2263. }
  2264. #ifdef CONFIG_SYSVIPC
  2265. static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
  2266. void __user *buffer, size_t *lenp, loff_t *ppos)
  2267. {
  2268. return -ENOSYS;
  2269. }
  2270. static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
  2271. void __user *buffer, size_t *lenp, loff_t *ppos)
  2272. {
  2273. return -ENOSYS;
  2274. }
  2275. static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
  2276. struct file *filp, void __user *buffer,
  2277. size_t *lenp, loff_t *ppos)
  2278. {
  2279. return -ENOSYS;
  2280. }
  2281. #endif
  2282. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2283. void __user *buffer, size_t *lenp, loff_t *ppos)
  2284. {
  2285. return -ENOSYS;
  2286. }
  2287. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2288. void __user *buffer, size_t *lenp, loff_t *ppos)
  2289. {
  2290. return -ENOSYS;
  2291. }
  2292. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2293. void __user *buffer, size_t *lenp, loff_t *ppos)
  2294. {
  2295. return -ENOSYS;
  2296. }
  2297. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2298. void __user *buffer, size_t *lenp, loff_t *ppos)
  2299. {
  2300. return -ENOSYS;
  2301. }
  2302. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2303. void __user *buffer, size_t *lenp, loff_t *ppos)
  2304. {
  2305. return -ENOSYS;
  2306. }
  2307. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2308. void __user *buffer, size_t *lenp, loff_t *ppos)
  2309. {
  2310. return -ENOSYS;
  2311. }
  2312. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2313. void __user *buffer, size_t *lenp, loff_t *ppos)
  2314. {
  2315. return -ENOSYS;
  2316. }
  2317. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2318. struct file *filp,
  2319. void __user *buffer,
  2320. size_t *lenp, loff_t *ppos)
  2321. {
  2322. return -ENOSYS;
  2323. }
  2324. #endif /* CONFIG_PROC_FS */
  2325. #ifdef CONFIG_SYSCTL_SYSCALL
  2326. /*
  2327. * General sysctl support routines
  2328. */
  2329. /* The generic string strategy routine: */
  2330. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2331. void __user *oldval, size_t __user *oldlenp,
  2332. void __user *newval, size_t newlen)
  2333. {
  2334. if (!table->data || !table->maxlen)
  2335. return -ENOTDIR;
  2336. if (oldval && oldlenp) {
  2337. size_t bufsize;
  2338. if (get_user(bufsize, oldlenp))
  2339. return -EFAULT;
  2340. if (bufsize) {
  2341. size_t len = strlen(table->data), copied;
  2342. /* This shouldn't trigger for a well-formed sysctl */
  2343. if (len > table->maxlen)
  2344. len = table->maxlen;
  2345. /* Copy up to a max of bufsize-1 bytes of the string */
  2346. copied = (len >= bufsize) ? bufsize - 1 : len;
  2347. if (copy_to_user(oldval, table->data, copied) ||
  2348. put_user(0, (char __user *)(oldval + copied)))
  2349. return -EFAULT;
  2350. if (put_user(len, oldlenp))
  2351. return -EFAULT;
  2352. }
  2353. }
  2354. if (newval && newlen) {
  2355. size_t len = newlen;
  2356. if (len > table->maxlen)
  2357. len = table->maxlen;
  2358. if(copy_from_user(table->data, newval, len))
  2359. return -EFAULT;
  2360. if (len == table->maxlen)
  2361. len--;
  2362. ((char *) table->data)[len] = 0;
  2363. }
  2364. return 1;
  2365. }
  2366. /*
  2367. * This function makes sure that all of the integers in the vector
  2368. * are between the minimum and maximum values given in the arrays
  2369. * table->extra1 and table->extra2, respectively.
  2370. */
  2371. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2372. void __user *oldval, size_t __user *oldlenp,
  2373. void __user *newval, size_t newlen)
  2374. {
  2375. if (newval && newlen) {
  2376. int __user *vec = (int __user *) newval;
  2377. int *min = (int *) table->extra1;
  2378. int *max = (int *) table->extra2;
  2379. size_t length;
  2380. int i;
  2381. if (newlen % sizeof(int) != 0)
  2382. return -EINVAL;
  2383. if (!table->extra1 && !table->extra2)
  2384. return 0;
  2385. if (newlen > table->maxlen)
  2386. newlen = table->maxlen;
  2387. length = newlen / sizeof(int);
  2388. for (i = 0; i < length; i++) {
  2389. int value;
  2390. if (get_user(value, vec + i))
  2391. return -EFAULT;
  2392. if (min && value < min[i])
  2393. return -EINVAL;
  2394. if (max && value > max[i])
  2395. return -EINVAL;
  2396. }
  2397. }
  2398. return 0;
  2399. }
  2400. /* Strategy function to convert jiffies to seconds */
  2401. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2402. void __user *oldval, size_t __user *oldlenp,
  2403. void __user *newval, size_t newlen)
  2404. {
  2405. if (oldval && oldlenp) {
  2406. size_t olen;
  2407. if (get_user(olen, oldlenp))
  2408. return -EFAULT;
  2409. if (olen) {
  2410. int val;
  2411. if (olen < sizeof(int))
  2412. return -EINVAL;
  2413. val = *(int *)(table->data) / HZ;
  2414. if (put_user(val, (int __user *)oldval))
  2415. return -EFAULT;
  2416. if (put_user(sizeof(int), oldlenp))
  2417. return -EFAULT;
  2418. }
  2419. }
  2420. if (newval && newlen) {
  2421. int new;
  2422. if (newlen != sizeof(int))
  2423. return -EINVAL;
  2424. if (get_user(new, (int __user *)newval))
  2425. return -EFAULT;
  2426. *(int *)(table->data) = new*HZ;
  2427. }
  2428. return 1;
  2429. }
  2430. /* Strategy function to convert jiffies to seconds */
  2431. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2432. void __user *oldval, size_t __user *oldlenp,
  2433. void __user *newval, size_t newlen)
  2434. {
  2435. if (oldval && oldlenp) {
  2436. size_t olen;
  2437. if (get_user(olen, oldlenp))
  2438. return -EFAULT;
  2439. if (olen) {
  2440. int val;
  2441. if (olen < sizeof(int))
  2442. return -EINVAL;
  2443. val = jiffies_to_msecs(*(int *)(table->data));
  2444. if (put_user(val, (int __user *)oldval))
  2445. return -EFAULT;
  2446. if (put_user(sizeof(int), oldlenp))
  2447. return -EFAULT;
  2448. }
  2449. }
  2450. if (newval && newlen) {
  2451. int new;
  2452. if (newlen != sizeof(int))
  2453. return -EINVAL;
  2454. if (get_user(new, (int __user *)newval))
  2455. return -EFAULT;
  2456. *(int *)(table->data) = msecs_to_jiffies(new);
  2457. }
  2458. return 1;
  2459. }
  2460. /* The generic string strategy routine: */
  2461. static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
  2462. void __user *oldval, size_t __user *oldlenp,
  2463. void __user *newval, size_t newlen)
  2464. {
  2465. struct ctl_table uts_table;
  2466. int r, write;
  2467. write = newval && newlen;
  2468. memcpy(&uts_table, table, sizeof(uts_table));
  2469. uts_table.data = get_uts(table, write);
  2470. r = sysctl_string(&uts_table, name, nlen,
  2471. oldval, oldlenp, newval, newlen);
  2472. put_uts(table, write, uts_table.data);
  2473. return r;
  2474. }
  2475. #ifdef CONFIG_SYSVIPC
  2476. /* The generic sysctl ipc data routine. */
  2477. static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
  2478. void __user *oldval, size_t __user *oldlenp,
  2479. void __user *newval, size_t newlen)
  2480. {
  2481. size_t len;
  2482. void *data;
  2483. /* Get out of I don't have a variable */
  2484. if (!table->data || !table->maxlen)
  2485. return -ENOTDIR;
  2486. data = get_ipc(table, 1);
  2487. if (!data)
  2488. return -ENOTDIR;
  2489. if (oldval && oldlenp) {
  2490. if (get_user(len, oldlenp))
  2491. return -EFAULT;
  2492. if (len) {
  2493. if (len > table->maxlen)
  2494. len = table->maxlen;
  2495. if (copy_to_user(oldval, data, len))
  2496. return -EFAULT;
  2497. if (put_user(len, oldlenp))
  2498. return -EFAULT;
  2499. }
  2500. }
  2501. if (newval && newlen) {
  2502. if (newlen > table->maxlen)
  2503. newlen = table->maxlen;
  2504. if (copy_from_user(data, newval, newlen))
  2505. return -EFAULT;
  2506. }
  2507. return 1;
  2508. }
  2509. #endif
  2510. #else /* CONFIG_SYSCTL_SYSCALL */
  2511. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  2512. {
  2513. static int msg_count;
  2514. struct __sysctl_args tmp;
  2515. int name[CTL_MAXNAME];
  2516. int i;
  2517. /* Read in the sysctl name for better debug message logging */
  2518. if (copy_from_user(&tmp, args, sizeof(tmp)))
  2519. return -EFAULT;
  2520. if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
  2521. return -ENOTDIR;
  2522. for (i = 0; i < tmp.nlen; i++)
  2523. if (get_user(name[i], tmp.name + i))
  2524. return -EFAULT;
  2525. /* Ignore accesses to kernel.version */
  2526. if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
  2527. goto out;
  2528. if (msg_count < 5) {
  2529. msg_count++;
  2530. printk(KERN_INFO
  2531. "warning: process `%s' used the removed sysctl "
  2532. "system call with ", current->comm);
  2533. for (i = 0; i < tmp.nlen; i++)
  2534. printk("%d.", name[i]);
  2535. printk("\n");
  2536. }
  2537. out:
  2538. return -ENOSYS;
  2539. }
  2540. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2541. void __user *oldval, size_t __user *oldlenp,
  2542. void __user *newval, size_t newlen)
  2543. {
  2544. return -ENOSYS;
  2545. }
  2546. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2547. void __user *oldval, size_t __user *oldlenp,
  2548. void __user *newval, size_t newlen)
  2549. {
  2550. return -ENOSYS;
  2551. }
  2552. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2553. void __user *oldval, size_t __user *oldlenp,
  2554. void __user *newval, size_t newlen)
  2555. {
  2556. return -ENOSYS;
  2557. }
  2558. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2559. void __user *oldval, size_t __user *oldlenp,
  2560. void __user *newval, size_t newlen)
  2561. {
  2562. return -ENOSYS;
  2563. }
  2564. static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
  2565. void __user *oldval, size_t __user *oldlenp,
  2566. void __user *newval, size_t newlen)
  2567. {
  2568. return -ENOSYS;
  2569. }
  2570. #ifdef CONFIG_SYSVIPC
  2571. static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
  2572. void __user *oldval, size_t __user *oldlenp,
  2573. void __user *newval, size_t newlen)
  2574. {
  2575. return -ENOSYS;
  2576. }
  2577. #endif
  2578. #endif /* CONFIG_SYSCTL_SYSCALL */
  2579. /*
  2580. * No sense putting this after each symbol definition, twice,
  2581. * exception granted :-)
  2582. */
  2583. EXPORT_SYMBOL(proc_dointvec);
  2584. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2585. EXPORT_SYMBOL(proc_dointvec_minmax);
  2586. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2587. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2588. EXPORT_SYMBOL(proc_dostring);
  2589. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2590. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2591. EXPORT_SYMBOL(register_sysctl_table);
  2592. EXPORT_SYMBOL(sysctl_intvec);
  2593. EXPORT_SYMBOL(sysctl_jiffies);
  2594. EXPORT_SYMBOL(sysctl_ms_jiffies);
  2595. EXPORT_SYMBOL(sysctl_string);
  2596. EXPORT_SYMBOL(unregister_sysctl_table);