sysctl.c 55 KB

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