sysctl.c 63 KB

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