sysctl.c 64 KB

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