sysctl.c 55 KB

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