sysctl.c 59 KB

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