sysctl.c 64 KB

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