sysctl.c 58 KB

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