sysctl.c 64 KB

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