sysctl.c 63 KB

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