sysctl.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800
  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/aio.h>
  22. #include <linux/mm.h>
  23. #include <linux/swap.h>
  24. #include <linux/slab.h>
  25. #include <linux/sysctl.h>
  26. #include <linux/bitmap.h>
  27. #include <linux/signal.h>
  28. #include <linux/printk.h>
  29. #include <linux/proc_fs.h>
  30. #include <linux/security.h>
  31. #include <linux/ctype.h>
  32. #include <linux/kmemcheck.h>
  33. #include <linux/kmemleak.h>
  34. #include <linux/fs.h>
  35. #include <linux/init.h>
  36. #include <linux/kernel.h>
  37. #include <linux/kobject.h>
  38. #include <linux/net.h>
  39. #include <linux/sysrq.h>
  40. #include <linux/highuid.h>
  41. #include <linux/writeback.h>
  42. #include <linux/ratelimit.h>
  43. #include <linux/compaction.h>
  44. #include <linux/hugetlb.h>
  45. #include <linux/initrd.h>
  46. #include <linux/key.h>
  47. #include <linux/times.h>
  48. #include <linux/limits.h>
  49. #include <linux/dcache.h>
  50. #include <linux/dnotify.h>
  51. #include <linux/syscalls.h>
  52. #include <linux/vmstat.h>
  53. #include <linux/nfs_fs.h>
  54. #include <linux/acpi.h>
  55. #include <linux/reboot.h>
  56. #include <linux/ftrace.h>
  57. #include <linux/perf_event.h>
  58. #include <linux/kprobes.h>
  59. #include <linux/pipe_fs_i.h>
  60. #include <linux/oom.h>
  61. #include <linux/kmod.h>
  62. #include <linux/capability.h>
  63. #include <linux/binfmts.h>
  64. #include <linux/sched/sysctl.h>
  65. #include <linux/kexec.h>
  66. #include <asm/uaccess.h>
  67. #include <asm/processor.h>
  68. #ifdef CONFIG_X86
  69. #include <asm/nmi.h>
  70. #include <asm/stacktrace.h>
  71. #include <asm/io.h>
  72. #endif
  73. #ifdef CONFIG_SPARC
  74. #include <asm/setup.h>
  75. #endif
  76. #ifdef CONFIG_BSD_PROCESS_ACCT
  77. #include <linux/acct.h>
  78. #endif
  79. #ifdef CONFIG_RT_MUTEXES
  80. #include <linux/rtmutex.h>
  81. #endif
  82. #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
  83. #include <linux/lockdep.h>
  84. #endif
  85. #ifdef CONFIG_CHR_DEV_SG
  86. #include <scsi/sg.h>
  87. #endif
  88. #ifdef CONFIG_LOCKUP_DETECTOR
  89. #include <linux/nmi.h>
  90. #endif
  91. #if defined(CONFIG_SYSCTL)
  92. /* External variables not in a header file. */
  93. extern int suid_dumpable;
  94. #ifdef CONFIG_COREDUMP
  95. extern int core_uses_pid;
  96. extern char core_pattern[];
  97. extern unsigned int core_pipe_limit;
  98. #endif
  99. extern int pid_max;
  100. extern int pid_max_min, pid_max_max;
  101. extern int percpu_pagelist_fraction;
  102. extern int compat_log;
  103. extern int latencytop_enabled;
  104. extern int sysctl_nr_open_min, sysctl_nr_open_max;
  105. #ifndef CONFIG_MMU
  106. extern int sysctl_nr_trim_pages;
  107. #endif
  108. /* Constants used for minimum and maximum */
  109. #ifdef CONFIG_LOCKUP_DETECTOR
  110. static int sixty = 60;
  111. #endif
  112. static int __maybe_unused neg_one = -1;
  113. static int zero;
  114. static int __maybe_unused one = 1;
  115. static int __maybe_unused two = 2;
  116. static int __maybe_unused four = 4;
  117. static unsigned long one_ul = 1;
  118. static int one_hundred = 100;
  119. #ifdef CONFIG_PRINTK
  120. static int ten_thousand = 10000;
  121. #endif
  122. /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
  123. static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
  124. /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
  125. static int maxolduid = 65535;
  126. static int minolduid;
  127. static int ngroups_max = NGROUPS_MAX;
  128. static const int cap_last_cap = CAP_LAST_CAP;
  129. /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
  130. #ifdef CONFIG_DETECT_HUNG_TASK
  131. static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
  132. #endif
  133. #ifdef CONFIG_INOTIFY_USER
  134. #include <linux/inotify.h>
  135. #endif
  136. #ifdef CONFIG_SPARC
  137. #endif
  138. #ifdef __hppa__
  139. extern int pwrsw_enabled;
  140. #endif
  141. #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
  142. extern int unaligned_enabled;
  143. #endif
  144. #ifdef CONFIG_IA64
  145. extern int unaligned_dump_stack;
  146. #endif
  147. #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
  148. extern int no_unaligned_warning;
  149. #endif
  150. #ifdef CONFIG_PROC_SYSCTL
  151. #define SYSCTL_WRITES_LEGACY -1
  152. #define SYSCTL_WRITES_WARN 0
  153. #define SYSCTL_WRITES_STRICT 1
  154. static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
  155. static int proc_do_cad_pid(struct ctl_table *table, int write,
  156. void __user *buffer, size_t *lenp, loff_t *ppos);
  157. static int proc_taint(struct ctl_table *table, int write,
  158. void __user *buffer, size_t *lenp, loff_t *ppos);
  159. #endif
  160. #ifdef CONFIG_PRINTK
  161. static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  162. void __user *buffer, size_t *lenp, loff_t *ppos);
  163. #endif
  164. static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
  165. void __user *buffer, size_t *lenp, loff_t *ppos);
  166. #ifdef CONFIG_COREDUMP
  167. static int proc_dostring_coredump(struct ctl_table *table, int write,
  168. void __user *buffer, size_t *lenp, loff_t *ppos);
  169. #endif
  170. #ifdef CONFIG_MAGIC_SYSRQ
  171. /* Note: sysrq code uses it's own private copy */
  172. static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
  173. static int sysrq_sysctl_handler(struct ctl_table *table, int write,
  174. void __user *buffer, size_t *lenp,
  175. loff_t *ppos)
  176. {
  177. int error;
  178. error = proc_dointvec(table, write, buffer, lenp, ppos);
  179. if (error)
  180. return error;
  181. if (write)
  182. sysrq_toggle_support(__sysrq_enabled);
  183. return 0;
  184. }
  185. #endif
  186. static struct ctl_table kern_table[];
  187. static struct ctl_table vm_table[];
  188. static struct ctl_table fs_table[];
  189. static struct ctl_table debug_table[];
  190. static struct ctl_table dev_table[];
  191. extern struct ctl_table random_table[];
  192. #ifdef CONFIG_EPOLL
  193. extern struct ctl_table epoll_table[];
  194. #endif
  195. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  196. int sysctl_legacy_va_layout;
  197. #endif
  198. /* The default sysctl tables: */
  199. static struct ctl_table sysctl_base_table[] = {
  200. {
  201. .procname = "kernel",
  202. .mode = 0555,
  203. .child = kern_table,
  204. },
  205. {
  206. .procname = "vm",
  207. .mode = 0555,
  208. .child = vm_table,
  209. },
  210. {
  211. .procname = "fs",
  212. .mode = 0555,
  213. .child = fs_table,
  214. },
  215. {
  216. .procname = "debug",
  217. .mode = 0555,
  218. .child = debug_table,
  219. },
  220. {
  221. .procname = "dev",
  222. .mode = 0555,
  223. .child = dev_table,
  224. },
  225. { }
  226. };
  227. #ifdef CONFIG_SCHED_DEBUG
  228. static int min_sched_granularity_ns = 100000; /* 100 usecs */
  229. static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
  230. static int min_wakeup_granularity_ns; /* 0 usecs */
  231. static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
  232. #ifdef CONFIG_SMP
  233. static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
  234. static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
  235. #endif /* CONFIG_SMP */
  236. #endif /* CONFIG_SCHED_DEBUG */
  237. #ifdef CONFIG_COMPACTION
  238. static int min_extfrag_threshold;
  239. static int max_extfrag_threshold = 1000;
  240. #endif
  241. static struct ctl_table kern_table[] = {
  242. {
  243. .procname = "sched_child_runs_first",
  244. .data = &sysctl_sched_child_runs_first,
  245. .maxlen = sizeof(unsigned int),
  246. .mode = 0644,
  247. .proc_handler = proc_dointvec,
  248. },
  249. #ifdef CONFIG_SCHED_DEBUG
  250. {
  251. .procname = "sched_min_granularity_ns",
  252. .data = &sysctl_sched_min_granularity,
  253. .maxlen = sizeof(unsigned int),
  254. .mode = 0644,
  255. .proc_handler = sched_proc_update_handler,
  256. .extra1 = &min_sched_granularity_ns,
  257. .extra2 = &max_sched_granularity_ns,
  258. },
  259. {
  260. .procname = "sched_latency_ns",
  261. .data = &sysctl_sched_latency,
  262. .maxlen = sizeof(unsigned int),
  263. .mode = 0644,
  264. .proc_handler = sched_proc_update_handler,
  265. .extra1 = &min_sched_granularity_ns,
  266. .extra2 = &max_sched_granularity_ns,
  267. },
  268. {
  269. .procname = "sched_wakeup_granularity_ns",
  270. .data = &sysctl_sched_wakeup_granularity,
  271. .maxlen = sizeof(unsigned int),
  272. .mode = 0644,
  273. .proc_handler = sched_proc_update_handler,
  274. .extra1 = &min_wakeup_granularity_ns,
  275. .extra2 = &max_wakeup_granularity_ns,
  276. },
  277. #ifdef CONFIG_SMP
  278. {
  279. .procname = "sched_tunable_scaling",
  280. .data = &sysctl_sched_tunable_scaling,
  281. .maxlen = sizeof(enum sched_tunable_scaling),
  282. .mode = 0644,
  283. .proc_handler = sched_proc_update_handler,
  284. .extra1 = &min_sched_tunable_scaling,
  285. .extra2 = &max_sched_tunable_scaling,
  286. },
  287. {
  288. .procname = "sched_migration_cost_ns",
  289. .data = &sysctl_sched_migration_cost,
  290. .maxlen = sizeof(unsigned int),
  291. .mode = 0644,
  292. .proc_handler = proc_dointvec,
  293. },
  294. {
  295. .procname = "sched_nr_migrate",
  296. .data = &sysctl_sched_nr_migrate,
  297. .maxlen = sizeof(unsigned int),
  298. .mode = 0644,
  299. .proc_handler = proc_dointvec,
  300. },
  301. {
  302. .procname = "sched_time_avg_ms",
  303. .data = &sysctl_sched_time_avg,
  304. .maxlen = sizeof(unsigned int),
  305. .mode = 0644,
  306. .proc_handler = proc_dointvec,
  307. },
  308. {
  309. .procname = "sched_shares_window_ns",
  310. .data = &sysctl_sched_shares_window,
  311. .maxlen = sizeof(unsigned int),
  312. .mode = 0644,
  313. .proc_handler = proc_dointvec,
  314. },
  315. #endif /* CONFIG_SMP */
  316. #ifdef CONFIG_NUMA_BALANCING
  317. {
  318. .procname = "numa_balancing_scan_delay_ms",
  319. .data = &sysctl_numa_balancing_scan_delay,
  320. .maxlen = sizeof(unsigned int),
  321. .mode = 0644,
  322. .proc_handler = proc_dointvec,
  323. },
  324. {
  325. .procname = "numa_balancing_scan_period_min_ms",
  326. .data = &sysctl_numa_balancing_scan_period_min,
  327. .maxlen = sizeof(unsigned int),
  328. .mode = 0644,
  329. .proc_handler = proc_dointvec,
  330. },
  331. {
  332. .procname = "numa_balancing_scan_period_max_ms",
  333. .data = &sysctl_numa_balancing_scan_period_max,
  334. .maxlen = sizeof(unsigned int),
  335. .mode = 0644,
  336. .proc_handler = proc_dointvec,
  337. },
  338. {
  339. .procname = "numa_balancing_scan_size_mb",
  340. .data = &sysctl_numa_balancing_scan_size,
  341. .maxlen = sizeof(unsigned int),
  342. .mode = 0644,
  343. .proc_handler = proc_dointvec_minmax,
  344. .extra1 = &one,
  345. },
  346. {
  347. .procname = "numa_balancing",
  348. .data = NULL, /* filled in by handler */
  349. .maxlen = sizeof(unsigned int),
  350. .mode = 0644,
  351. .proc_handler = sysctl_numa_balancing,
  352. .extra1 = &zero,
  353. .extra2 = &one,
  354. },
  355. #endif /* CONFIG_NUMA_BALANCING */
  356. #endif /* CONFIG_SCHED_DEBUG */
  357. {
  358. .procname = "sched_rt_period_us",
  359. .data = &sysctl_sched_rt_period,
  360. .maxlen = sizeof(unsigned int),
  361. .mode = 0644,
  362. .proc_handler = sched_rt_handler,
  363. },
  364. {
  365. .procname = "sched_rt_runtime_us",
  366. .data = &sysctl_sched_rt_runtime,
  367. .maxlen = sizeof(int),
  368. .mode = 0644,
  369. .proc_handler = sched_rt_handler,
  370. },
  371. {
  372. .procname = "sched_rr_timeslice_ms",
  373. .data = &sched_rr_timeslice,
  374. .maxlen = sizeof(int),
  375. .mode = 0644,
  376. .proc_handler = sched_rr_handler,
  377. },
  378. #ifdef CONFIG_SCHED_AUTOGROUP
  379. {
  380. .procname = "sched_autogroup_enabled",
  381. .data = &sysctl_sched_autogroup_enabled,
  382. .maxlen = sizeof(unsigned int),
  383. .mode = 0644,
  384. .proc_handler = proc_dointvec_minmax,
  385. .extra1 = &zero,
  386. .extra2 = &one,
  387. },
  388. #endif
  389. #ifdef CONFIG_CFS_BANDWIDTH
  390. {
  391. .procname = "sched_cfs_bandwidth_slice_us",
  392. .data = &sysctl_sched_cfs_bandwidth_slice,
  393. .maxlen = sizeof(unsigned int),
  394. .mode = 0644,
  395. .proc_handler = proc_dointvec_minmax,
  396. .extra1 = &one,
  397. },
  398. #endif
  399. #ifdef CONFIG_PROVE_LOCKING
  400. {
  401. .procname = "prove_locking",
  402. .data = &prove_locking,
  403. .maxlen = sizeof(int),
  404. .mode = 0644,
  405. .proc_handler = proc_dointvec,
  406. },
  407. #endif
  408. #ifdef CONFIG_LOCK_STAT
  409. {
  410. .procname = "lock_stat",
  411. .data = &lock_stat,
  412. .maxlen = sizeof(int),
  413. .mode = 0644,
  414. .proc_handler = proc_dointvec,
  415. },
  416. #endif
  417. {
  418. .procname = "panic",
  419. .data = &panic_timeout,
  420. .maxlen = sizeof(int),
  421. .mode = 0644,
  422. .proc_handler = proc_dointvec,
  423. },
  424. #ifdef CONFIG_COREDUMP
  425. {
  426. .procname = "core_uses_pid",
  427. .data = &core_uses_pid,
  428. .maxlen = sizeof(int),
  429. .mode = 0644,
  430. .proc_handler = proc_dointvec,
  431. },
  432. {
  433. .procname = "core_pattern",
  434. .data = core_pattern,
  435. .maxlen = CORENAME_MAX_SIZE,
  436. .mode = 0644,
  437. .proc_handler = proc_dostring_coredump,
  438. },
  439. {
  440. .procname = "core_pipe_limit",
  441. .data = &core_pipe_limit,
  442. .maxlen = sizeof(unsigned int),
  443. .mode = 0644,
  444. .proc_handler = proc_dointvec,
  445. },
  446. #endif
  447. #ifdef CONFIG_PROC_SYSCTL
  448. {
  449. .procname = "tainted",
  450. .maxlen = sizeof(long),
  451. .mode = 0644,
  452. .proc_handler = proc_taint,
  453. },
  454. {
  455. .procname = "sysctl_writes_strict",
  456. .data = &sysctl_writes_strict,
  457. .maxlen = sizeof(int),
  458. .mode = 0644,
  459. .proc_handler = proc_dointvec_minmax,
  460. .extra1 = &neg_one,
  461. .extra2 = &one,
  462. },
  463. #endif
  464. #ifdef CONFIG_LATENCYTOP
  465. {
  466. .procname = "latencytop",
  467. .data = &latencytop_enabled,
  468. .maxlen = sizeof(int),
  469. .mode = 0644,
  470. .proc_handler = proc_dointvec,
  471. },
  472. #endif
  473. #ifdef CONFIG_BLK_DEV_INITRD
  474. {
  475. .procname = "real-root-dev",
  476. .data = &real_root_dev,
  477. .maxlen = sizeof(int),
  478. .mode = 0644,
  479. .proc_handler = proc_dointvec,
  480. },
  481. #endif
  482. {
  483. .procname = "print-fatal-signals",
  484. .data = &print_fatal_signals,
  485. .maxlen = sizeof(int),
  486. .mode = 0644,
  487. .proc_handler = proc_dointvec,
  488. },
  489. #ifdef CONFIG_SPARC
  490. {
  491. .procname = "reboot-cmd",
  492. .data = reboot_command,
  493. .maxlen = 256,
  494. .mode = 0644,
  495. .proc_handler = proc_dostring,
  496. },
  497. {
  498. .procname = "stop-a",
  499. .data = &stop_a_enabled,
  500. .maxlen = sizeof (int),
  501. .mode = 0644,
  502. .proc_handler = proc_dointvec,
  503. },
  504. {
  505. .procname = "scons-poweroff",
  506. .data = &scons_pwroff,
  507. .maxlen = sizeof (int),
  508. .mode = 0644,
  509. .proc_handler = proc_dointvec,
  510. },
  511. #endif
  512. #ifdef CONFIG_SPARC64
  513. {
  514. .procname = "tsb-ratio",
  515. .data = &sysctl_tsb_ratio,
  516. .maxlen = sizeof (int),
  517. .mode = 0644,
  518. .proc_handler = proc_dointvec,
  519. },
  520. #endif
  521. #ifdef __hppa__
  522. {
  523. .procname = "soft-power",
  524. .data = &pwrsw_enabled,
  525. .maxlen = sizeof (int),
  526. .mode = 0644,
  527. .proc_handler = proc_dointvec,
  528. },
  529. #endif
  530. #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
  531. {
  532. .procname = "unaligned-trap",
  533. .data = &unaligned_enabled,
  534. .maxlen = sizeof (int),
  535. .mode = 0644,
  536. .proc_handler = proc_dointvec,
  537. },
  538. #endif
  539. {
  540. .procname = "ctrl-alt-del",
  541. .data = &C_A_D,
  542. .maxlen = sizeof(int),
  543. .mode = 0644,
  544. .proc_handler = proc_dointvec,
  545. },
  546. #ifdef CONFIG_FUNCTION_TRACER
  547. {
  548. .procname = "ftrace_enabled",
  549. .data = &ftrace_enabled,
  550. .maxlen = sizeof(int),
  551. .mode = 0644,
  552. .proc_handler = ftrace_enable_sysctl,
  553. },
  554. #endif
  555. #ifdef CONFIG_STACK_TRACER
  556. {
  557. .procname = "stack_tracer_enabled",
  558. .data = &stack_tracer_enabled,
  559. .maxlen = sizeof(int),
  560. .mode = 0644,
  561. .proc_handler = stack_trace_sysctl,
  562. },
  563. #endif
  564. #ifdef CONFIG_TRACING
  565. {
  566. .procname = "ftrace_dump_on_oops",
  567. .data = &ftrace_dump_on_oops,
  568. .maxlen = sizeof(int),
  569. .mode = 0644,
  570. .proc_handler = proc_dointvec,
  571. },
  572. {
  573. .procname = "traceoff_on_warning",
  574. .data = &__disable_trace_on_warning,
  575. .maxlen = sizeof(__disable_trace_on_warning),
  576. .mode = 0644,
  577. .proc_handler = proc_dointvec,
  578. },
  579. {
  580. .procname = "tracepoint_printk",
  581. .data = &tracepoint_printk,
  582. .maxlen = sizeof(tracepoint_printk),
  583. .mode = 0644,
  584. .proc_handler = proc_dointvec,
  585. },
  586. #endif
  587. #ifdef CONFIG_KEXEC
  588. {
  589. .procname = "kexec_load_disabled",
  590. .data = &kexec_load_disabled,
  591. .maxlen = sizeof(int),
  592. .mode = 0644,
  593. /* only handle a transition from default "0" to "1" */
  594. .proc_handler = proc_dointvec_minmax,
  595. .extra1 = &one,
  596. .extra2 = &one,
  597. },
  598. #endif
  599. #ifdef CONFIG_MODULES
  600. {
  601. .procname = "modprobe",
  602. .data = &modprobe_path,
  603. .maxlen = KMOD_PATH_LEN,
  604. .mode = 0644,
  605. .proc_handler = proc_dostring,
  606. },
  607. {
  608. .procname = "modules_disabled",
  609. .data = &modules_disabled,
  610. .maxlen = sizeof(int),
  611. .mode = 0644,
  612. /* only handle a transition from default "0" to "1" */
  613. .proc_handler = proc_dointvec_minmax,
  614. .extra1 = &one,
  615. .extra2 = &one,
  616. },
  617. #endif
  618. #ifdef CONFIG_UEVENT_HELPER
  619. {
  620. .procname = "hotplug",
  621. .data = &uevent_helper,
  622. .maxlen = UEVENT_HELPER_PATH_LEN,
  623. .mode = 0644,
  624. .proc_handler = proc_dostring,
  625. },
  626. #endif
  627. #ifdef CONFIG_CHR_DEV_SG
  628. {
  629. .procname = "sg-big-buff",
  630. .data = &sg_big_buff,
  631. .maxlen = sizeof (int),
  632. .mode = 0444,
  633. .proc_handler = proc_dointvec,
  634. },
  635. #endif
  636. #ifdef CONFIG_BSD_PROCESS_ACCT
  637. {
  638. .procname = "acct",
  639. .data = &acct_parm,
  640. .maxlen = 3*sizeof(int),
  641. .mode = 0644,
  642. .proc_handler = proc_dointvec,
  643. },
  644. #endif
  645. #ifdef CONFIG_MAGIC_SYSRQ
  646. {
  647. .procname = "sysrq",
  648. .data = &__sysrq_enabled,
  649. .maxlen = sizeof (int),
  650. .mode = 0644,
  651. .proc_handler = sysrq_sysctl_handler,
  652. },
  653. #endif
  654. #ifdef CONFIG_PROC_SYSCTL
  655. {
  656. .procname = "cad_pid",
  657. .data = NULL,
  658. .maxlen = sizeof (int),
  659. .mode = 0600,
  660. .proc_handler = proc_do_cad_pid,
  661. },
  662. #endif
  663. {
  664. .procname = "threads-max",
  665. .data = NULL,
  666. .maxlen = sizeof(int),
  667. .mode = 0644,
  668. .proc_handler = sysctl_max_threads,
  669. },
  670. {
  671. .procname = "random",
  672. .mode = 0555,
  673. .child = random_table,
  674. },
  675. {
  676. .procname = "usermodehelper",
  677. .mode = 0555,
  678. .child = usermodehelper_table,
  679. },
  680. {
  681. .procname = "overflowuid",
  682. .data = &overflowuid,
  683. .maxlen = sizeof(int),
  684. .mode = 0644,
  685. .proc_handler = proc_dointvec_minmax,
  686. .extra1 = &minolduid,
  687. .extra2 = &maxolduid,
  688. },
  689. {
  690. .procname = "overflowgid",
  691. .data = &overflowgid,
  692. .maxlen = sizeof(int),
  693. .mode = 0644,
  694. .proc_handler = proc_dointvec_minmax,
  695. .extra1 = &minolduid,
  696. .extra2 = &maxolduid,
  697. },
  698. #ifdef CONFIG_S390
  699. #ifdef CONFIG_MATHEMU
  700. {
  701. .procname = "ieee_emulation_warnings",
  702. .data = &sysctl_ieee_emulation_warnings,
  703. .maxlen = sizeof(int),
  704. .mode = 0644,
  705. .proc_handler = proc_dointvec,
  706. },
  707. #endif
  708. {
  709. .procname = "userprocess_debug",
  710. .data = &show_unhandled_signals,
  711. .maxlen = sizeof(int),
  712. .mode = 0644,
  713. .proc_handler = proc_dointvec,
  714. },
  715. #endif
  716. {
  717. .procname = "pid_max",
  718. .data = &pid_max,
  719. .maxlen = sizeof (int),
  720. .mode = 0644,
  721. .proc_handler = proc_dointvec_minmax,
  722. .extra1 = &pid_max_min,
  723. .extra2 = &pid_max_max,
  724. },
  725. {
  726. .procname = "panic_on_oops",
  727. .data = &panic_on_oops,
  728. .maxlen = sizeof(int),
  729. .mode = 0644,
  730. .proc_handler = proc_dointvec,
  731. },
  732. #if defined CONFIG_PRINTK
  733. {
  734. .procname = "printk",
  735. .data = &console_loglevel,
  736. .maxlen = 4*sizeof(int),
  737. .mode = 0644,
  738. .proc_handler = proc_dointvec,
  739. },
  740. {
  741. .procname = "printk_ratelimit",
  742. .data = &printk_ratelimit_state.interval,
  743. .maxlen = sizeof(int),
  744. .mode = 0644,
  745. .proc_handler = proc_dointvec_jiffies,
  746. },
  747. {
  748. .procname = "printk_ratelimit_burst",
  749. .data = &printk_ratelimit_state.burst,
  750. .maxlen = sizeof(int),
  751. .mode = 0644,
  752. .proc_handler = proc_dointvec,
  753. },
  754. {
  755. .procname = "printk_delay",
  756. .data = &printk_delay_msec,
  757. .maxlen = sizeof(int),
  758. .mode = 0644,
  759. .proc_handler = proc_dointvec_minmax,
  760. .extra1 = &zero,
  761. .extra2 = &ten_thousand,
  762. },
  763. {
  764. .procname = "dmesg_restrict",
  765. .data = &dmesg_restrict,
  766. .maxlen = sizeof(int),
  767. .mode = 0644,
  768. .proc_handler = proc_dointvec_minmax_sysadmin,
  769. .extra1 = &zero,
  770. .extra2 = &one,
  771. },
  772. {
  773. .procname = "kptr_restrict",
  774. .data = &kptr_restrict,
  775. .maxlen = sizeof(int),
  776. .mode = 0644,
  777. .proc_handler = proc_dointvec_minmax_sysadmin,
  778. .extra1 = &zero,
  779. .extra2 = &two,
  780. },
  781. #endif
  782. {
  783. .procname = "ngroups_max",
  784. .data = &ngroups_max,
  785. .maxlen = sizeof (int),
  786. .mode = 0444,
  787. .proc_handler = proc_dointvec,
  788. },
  789. {
  790. .procname = "cap_last_cap",
  791. .data = (void *)&cap_last_cap,
  792. .maxlen = sizeof(int),
  793. .mode = 0444,
  794. .proc_handler = proc_dointvec,
  795. },
  796. #if defined(CONFIG_LOCKUP_DETECTOR)
  797. {
  798. .procname = "watchdog",
  799. .data = &watchdog_user_enabled,
  800. .maxlen = sizeof (int),
  801. .mode = 0644,
  802. .proc_handler = proc_watchdog,
  803. .extra1 = &zero,
  804. .extra2 = &one,
  805. },
  806. {
  807. .procname = "watchdog_thresh",
  808. .data = &watchdog_thresh,
  809. .maxlen = sizeof(int),
  810. .mode = 0644,
  811. .proc_handler = proc_watchdog_thresh,
  812. .extra1 = &zero,
  813. .extra2 = &sixty,
  814. },
  815. {
  816. .procname = "nmi_watchdog",
  817. .data = &nmi_watchdog_enabled,
  818. .maxlen = sizeof (int),
  819. .mode = 0644,
  820. .proc_handler = proc_nmi_watchdog,
  821. .extra1 = &zero,
  822. #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
  823. .extra2 = &one,
  824. #else
  825. .extra2 = &zero,
  826. #endif
  827. },
  828. {
  829. .procname = "soft_watchdog",
  830. .data = &soft_watchdog_enabled,
  831. .maxlen = sizeof (int),
  832. .mode = 0644,
  833. .proc_handler = proc_soft_watchdog,
  834. .extra1 = &zero,
  835. .extra2 = &one,
  836. },
  837. {
  838. .procname = "watchdog_cpumask",
  839. .data = &watchdog_cpumask_bits,
  840. .maxlen = NR_CPUS,
  841. .mode = 0644,
  842. .proc_handler = proc_watchdog_cpumask,
  843. },
  844. {
  845. .procname = "softlockup_panic",
  846. .data = &softlockup_panic,
  847. .maxlen = sizeof(int),
  848. .mode = 0644,
  849. .proc_handler = proc_dointvec_minmax,
  850. .extra1 = &zero,
  851. .extra2 = &one,
  852. },
  853. #ifdef CONFIG_SMP
  854. {
  855. .procname = "softlockup_all_cpu_backtrace",
  856. .data = &sysctl_softlockup_all_cpu_backtrace,
  857. .maxlen = sizeof(int),
  858. .mode = 0644,
  859. .proc_handler = proc_dointvec_minmax,
  860. .extra1 = &zero,
  861. .extra2 = &one,
  862. },
  863. #endif /* CONFIG_SMP */
  864. #endif
  865. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
  866. {
  867. .procname = "unknown_nmi_panic",
  868. .data = &unknown_nmi_panic,
  869. .maxlen = sizeof (int),
  870. .mode = 0644,
  871. .proc_handler = proc_dointvec,
  872. },
  873. #endif
  874. #if defined(CONFIG_X86)
  875. {
  876. .procname = "panic_on_unrecovered_nmi",
  877. .data = &panic_on_unrecovered_nmi,
  878. .maxlen = sizeof(int),
  879. .mode = 0644,
  880. .proc_handler = proc_dointvec,
  881. },
  882. {
  883. .procname = "panic_on_io_nmi",
  884. .data = &panic_on_io_nmi,
  885. .maxlen = sizeof(int),
  886. .mode = 0644,
  887. .proc_handler = proc_dointvec,
  888. },
  889. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  890. {
  891. .procname = "panic_on_stackoverflow",
  892. .data = &sysctl_panic_on_stackoverflow,
  893. .maxlen = sizeof(int),
  894. .mode = 0644,
  895. .proc_handler = proc_dointvec,
  896. },
  897. #endif
  898. {
  899. .procname = "bootloader_type",
  900. .data = &bootloader_type,
  901. .maxlen = sizeof (int),
  902. .mode = 0444,
  903. .proc_handler = proc_dointvec,
  904. },
  905. {
  906. .procname = "bootloader_version",
  907. .data = &bootloader_version,
  908. .maxlen = sizeof (int),
  909. .mode = 0444,
  910. .proc_handler = proc_dointvec,
  911. },
  912. {
  913. .procname = "kstack_depth_to_print",
  914. .data = &kstack_depth_to_print,
  915. .maxlen = sizeof(int),
  916. .mode = 0644,
  917. .proc_handler = proc_dointvec,
  918. },
  919. {
  920. .procname = "io_delay_type",
  921. .data = &io_delay_type,
  922. .maxlen = sizeof(int),
  923. .mode = 0644,
  924. .proc_handler = proc_dointvec,
  925. },
  926. #endif
  927. #if defined(CONFIG_MMU)
  928. {
  929. .procname = "randomize_va_space",
  930. .data = &randomize_va_space,
  931. .maxlen = sizeof(int),
  932. .mode = 0644,
  933. .proc_handler = proc_dointvec,
  934. },
  935. #endif
  936. #if defined(CONFIG_S390) && defined(CONFIG_SMP)
  937. {
  938. .procname = "spin_retry",
  939. .data = &spin_retry,
  940. .maxlen = sizeof (int),
  941. .mode = 0644,
  942. .proc_handler = proc_dointvec,
  943. },
  944. #endif
  945. #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
  946. {
  947. .procname = "acpi_video_flags",
  948. .data = &acpi_realmode_flags,
  949. .maxlen = sizeof (unsigned long),
  950. .mode = 0644,
  951. .proc_handler = proc_doulongvec_minmax,
  952. },
  953. #endif
  954. #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
  955. {
  956. .procname = "ignore-unaligned-usertrap",
  957. .data = &no_unaligned_warning,
  958. .maxlen = sizeof (int),
  959. .mode = 0644,
  960. .proc_handler = proc_dointvec,
  961. },
  962. #endif
  963. #ifdef CONFIG_IA64
  964. {
  965. .procname = "unaligned-dump-stack",
  966. .data = &unaligned_dump_stack,
  967. .maxlen = sizeof (int),
  968. .mode = 0644,
  969. .proc_handler = proc_dointvec,
  970. },
  971. #endif
  972. #ifdef CONFIG_DETECT_HUNG_TASK
  973. {
  974. .procname = "hung_task_panic",
  975. .data = &sysctl_hung_task_panic,
  976. .maxlen = sizeof(int),
  977. .mode = 0644,
  978. .proc_handler = proc_dointvec_minmax,
  979. .extra1 = &zero,
  980. .extra2 = &one,
  981. },
  982. {
  983. .procname = "hung_task_check_count",
  984. .data = &sysctl_hung_task_check_count,
  985. .maxlen = sizeof(int),
  986. .mode = 0644,
  987. .proc_handler = proc_dointvec_minmax,
  988. .extra1 = &zero,
  989. },
  990. {
  991. .procname = "hung_task_timeout_secs",
  992. .data = &sysctl_hung_task_timeout_secs,
  993. .maxlen = sizeof(unsigned long),
  994. .mode = 0644,
  995. .proc_handler = proc_dohung_task_timeout_secs,
  996. .extra2 = &hung_task_timeout_max,
  997. },
  998. {
  999. .procname = "hung_task_warnings",
  1000. .data = &sysctl_hung_task_warnings,
  1001. .maxlen = sizeof(int),
  1002. .mode = 0644,
  1003. .proc_handler = proc_dointvec_minmax,
  1004. .extra1 = &neg_one,
  1005. },
  1006. #endif
  1007. #ifdef CONFIG_COMPAT
  1008. {
  1009. .procname = "compat-log",
  1010. .data = &compat_log,
  1011. .maxlen = sizeof (int),
  1012. .mode = 0644,
  1013. .proc_handler = proc_dointvec,
  1014. },
  1015. #endif
  1016. #ifdef CONFIG_RT_MUTEXES
  1017. {
  1018. .procname = "max_lock_depth",
  1019. .data = &max_lock_depth,
  1020. .maxlen = sizeof(int),
  1021. .mode = 0644,
  1022. .proc_handler = proc_dointvec,
  1023. },
  1024. #endif
  1025. {
  1026. .procname = "poweroff_cmd",
  1027. .data = &poweroff_cmd,
  1028. .maxlen = POWEROFF_CMD_PATH_LEN,
  1029. .mode = 0644,
  1030. .proc_handler = proc_dostring,
  1031. },
  1032. #ifdef CONFIG_KEYS
  1033. {
  1034. .procname = "keys",
  1035. .mode = 0555,
  1036. .child = key_sysctls,
  1037. },
  1038. #endif
  1039. #ifdef CONFIG_PERF_EVENTS
  1040. /*
  1041. * User-space scripts rely on the existence of this file
  1042. * as a feature check for perf_events being enabled.
  1043. *
  1044. * So it's an ABI, do not remove!
  1045. */
  1046. {
  1047. .procname = "perf_event_paranoid",
  1048. .data = &sysctl_perf_event_paranoid,
  1049. .maxlen = sizeof(sysctl_perf_event_paranoid),
  1050. .mode = 0644,
  1051. .proc_handler = proc_dointvec,
  1052. },
  1053. {
  1054. .procname = "perf_event_mlock_kb",
  1055. .data = &sysctl_perf_event_mlock,
  1056. .maxlen = sizeof(sysctl_perf_event_mlock),
  1057. .mode = 0644,
  1058. .proc_handler = proc_dointvec,
  1059. },
  1060. {
  1061. .procname = "perf_event_max_sample_rate",
  1062. .data = &sysctl_perf_event_sample_rate,
  1063. .maxlen = sizeof(sysctl_perf_event_sample_rate),
  1064. .mode = 0644,
  1065. .proc_handler = perf_proc_update_handler,
  1066. .extra1 = &one,
  1067. },
  1068. {
  1069. .procname = "perf_cpu_time_max_percent",
  1070. .data = &sysctl_perf_cpu_time_max_percent,
  1071. .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
  1072. .mode = 0644,
  1073. .proc_handler = perf_cpu_time_max_percent_handler,
  1074. .extra1 = &zero,
  1075. .extra2 = &one_hundred,
  1076. },
  1077. #endif
  1078. #ifdef CONFIG_KMEMCHECK
  1079. {
  1080. .procname = "kmemcheck",
  1081. .data = &kmemcheck_enabled,
  1082. .maxlen = sizeof(int),
  1083. .mode = 0644,
  1084. .proc_handler = proc_dointvec,
  1085. },
  1086. #endif
  1087. {
  1088. .procname = "panic_on_warn",
  1089. .data = &panic_on_warn,
  1090. .maxlen = sizeof(int),
  1091. .mode = 0644,
  1092. .proc_handler = proc_dointvec_minmax,
  1093. .extra1 = &zero,
  1094. .extra2 = &one,
  1095. },
  1096. #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
  1097. {
  1098. .procname = "timer_migration",
  1099. .data = &sysctl_timer_migration,
  1100. .maxlen = sizeof(unsigned int),
  1101. .mode = 0644,
  1102. .proc_handler = timer_migration_handler,
  1103. },
  1104. #endif
  1105. { }
  1106. };
  1107. static struct ctl_table vm_table[] = {
  1108. {
  1109. .procname = "overcommit_memory",
  1110. .data = &sysctl_overcommit_memory,
  1111. .maxlen = sizeof(sysctl_overcommit_memory),
  1112. .mode = 0644,
  1113. .proc_handler = proc_dointvec_minmax,
  1114. .extra1 = &zero,
  1115. .extra2 = &two,
  1116. },
  1117. {
  1118. .procname = "panic_on_oom",
  1119. .data = &sysctl_panic_on_oom,
  1120. .maxlen = sizeof(sysctl_panic_on_oom),
  1121. .mode = 0644,
  1122. .proc_handler = proc_dointvec_minmax,
  1123. .extra1 = &zero,
  1124. .extra2 = &two,
  1125. },
  1126. {
  1127. .procname = "oom_kill_allocating_task",
  1128. .data = &sysctl_oom_kill_allocating_task,
  1129. .maxlen = sizeof(sysctl_oom_kill_allocating_task),
  1130. .mode = 0644,
  1131. .proc_handler = proc_dointvec,
  1132. },
  1133. {
  1134. .procname = "oom_dump_tasks",
  1135. .data = &sysctl_oom_dump_tasks,
  1136. .maxlen = sizeof(sysctl_oom_dump_tasks),
  1137. .mode = 0644,
  1138. .proc_handler = proc_dointvec,
  1139. },
  1140. {
  1141. .procname = "overcommit_ratio",
  1142. .data = &sysctl_overcommit_ratio,
  1143. .maxlen = sizeof(sysctl_overcommit_ratio),
  1144. .mode = 0644,
  1145. .proc_handler = overcommit_ratio_handler,
  1146. },
  1147. {
  1148. .procname = "overcommit_kbytes",
  1149. .data = &sysctl_overcommit_kbytes,
  1150. .maxlen = sizeof(sysctl_overcommit_kbytes),
  1151. .mode = 0644,
  1152. .proc_handler = overcommit_kbytes_handler,
  1153. },
  1154. {
  1155. .procname = "page-cluster",
  1156. .data = &page_cluster,
  1157. .maxlen = sizeof(int),
  1158. .mode = 0644,
  1159. .proc_handler = proc_dointvec_minmax,
  1160. .extra1 = &zero,
  1161. },
  1162. {
  1163. .procname = "dirty_background_ratio",
  1164. .data = &dirty_background_ratio,
  1165. .maxlen = sizeof(dirty_background_ratio),
  1166. .mode = 0644,
  1167. .proc_handler = dirty_background_ratio_handler,
  1168. .extra1 = &zero,
  1169. .extra2 = &one_hundred,
  1170. },
  1171. {
  1172. .procname = "dirty_background_bytes",
  1173. .data = &dirty_background_bytes,
  1174. .maxlen = sizeof(dirty_background_bytes),
  1175. .mode = 0644,
  1176. .proc_handler = dirty_background_bytes_handler,
  1177. .extra1 = &one_ul,
  1178. },
  1179. {
  1180. .procname = "dirty_ratio",
  1181. .data = &vm_dirty_ratio,
  1182. .maxlen = sizeof(vm_dirty_ratio),
  1183. .mode = 0644,
  1184. .proc_handler = dirty_ratio_handler,
  1185. .extra1 = &zero,
  1186. .extra2 = &one_hundred,
  1187. },
  1188. {
  1189. .procname = "dirty_bytes",
  1190. .data = &vm_dirty_bytes,
  1191. .maxlen = sizeof(vm_dirty_bytes),
  1192. .mode = 0644,
  1193. .proc_handler = dirty_bytes_handler,
  1194. .extra1 = &dirty_bytes_min,
  1195. },
  1196. {
  1197. .procname = "dirty_writeback_centisecs",
  1198. .data = &dirty_writeback_interval,
  1199. .maxlen = sizeof(dirty_writeback_interval),
  1200. .mode = 0644,
  1201. .proc_handler = dirty_writeback_centisecs_handler,
  1202. },
  1203. {
  1204. .procname = "dirty_expire_centisecs",
  1205. .data = &dirty_expire_interval,
  1206. .maxlen = sizeof(dirty_expire_interval),
  1207. .mode = 0644,
  1208. .proc_handler = proc_dointvec_minmax,
  1209. .extra1 = &zero,
  1210. },
  1211. {
  1212. .procname = "dirtytime_expire_seconds",
  1213. .data = &dirtytime_expire_interval,
  1214. .maxlen = sizeof(dirty_expire_interval),
  1215. .mode = 0644,
  1216. .proc_handler = dirtytime_interval_handler,
  1217. .extra1 = &zero,
  1218. },
  1219. {
  1220. .procname = "nr_pdflush_threads",
  1221. .mode = 0444 /* read-only */,
  1222. .proc_handler = pdflush_proc_obsolete,
  1223. },
  1224. {
  1225. .procname = "swappiness",
  1226. .data = &vm_swappiness,
  1227. .maxlen = sizeof(vm_swappiness),
  1228. .mode = 0644,
  1229. .proc_handler = proc_dointvec_minmax,
  1230. .extra1 = &zero,
  1231. .extra2 = &one_hundred,
  1232. },
  1233. #ifdef CONFIG_HUGETLB_PAGE
  1234. {
  1235. .procname = "nr_hugepages",
  1236. .data = NULL,
  1237. .maxlen = sizeof(unsigned long),
  1238. .mode = 0644,
  1239. .proc_handler = hugetlb_sysctl_handler,
  1240. },
  1241. #ifdef CONFIG_NUMA
  1242. {
  1243. .procname = "nr_hugepages_mempolicy",
  1244. .data = NULL,
  1245. .maxlen = sizeof(unsigned long),
  1246. .mode = 0644,
  1247. .proc_handler = &hugetlb_mempolicy_sysctl_handler,
  1248. },
  1249. #endif
  1250. {
  1251. .procname = "hugetlb_shm_group",
  1252. .data = &sysctl_hugetlb_shm_group,
  1253. .maxlen = sizeof(gid_t),
  1254. .mode = 0644,
  1255. .proc_handler = proc_dointvec,
  1256. },
  1257. {
  1258. .procname = "hugepages_treat_as_movable",
  1259. .data = &hugepages_treat_as_movable,
  1260. .maxlen = sizeof(int),
  1261. .mode = 0644,
  1262. .proc_handler = proc_dointvec,
  1263. },
  1264. {
  1265. .procname = "nr_overcommit_hugepages",
  1266. .data = NULL,
  1267. .maxlen = sizeof(unsigned long),
  1268. .mode = 0644,
  1269. .proc_handler = hugetlb_overcommit_handler,
  1270. },
  1271. #endif
  1272. {
  1273. .procname = "lowmem_reserve_ratio",
  1274. .data = &sysctl_lowmem_reserve_ratio,
  1275. .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
  1276. .mode = 0644,
  1277. .proc_handler = lowmem_reserve_ratio_sysctl_handler,
  1278. },
  1279. {
  1280. .procname = "drop_caches",
  1281. .data = &sysctl_drop_caches,
  1282. .maxlen = sizeof(int),
  1283. .mode = 0644,
  1284. .proc_handler = drop_caches_sysctl_handler,
  1285. .extra1 = &one,
  1286. .extra2 = &four,
  1287. },
  1288. #ifdef CONFIG_COMPACTION
  1289. {
  1290. .procname = "compact_memory",
  1291. .data = &sysctl_compact_memory,
  1292. .maxlen = sizeof(int),
  1293. .mode = 0200,
  1294. .proc_handler = sysctl_compaction_handler,
  1295. },
  1296. {
  1297. .procname = "extfrag_threshold",
  1298. .data = &sysctl_extfrag_threshold,
  1299. .maxlen = sizeof(int),
  1300. .mode = 0644,
  1301. .proc_handler = sysctl_extfrag_handler,
  1302. .extra1 = &min_extfrag_threshold,
  1303. .extra2 = &max_extfrag_threshold,
  1304. },
  1305. {
  1306. .procname = "compact_unevictable_allowed",
  1307. .data = &sysctl_compact_unevictable_allowed,
  1308. .maxlen = sizeof(int),
  1309. .mode = 0644,
  1310. .proc_handler = proc_dointvec,
  1311. .extra1 = &zero,
  1312. .extra2 = &one,
  1313. },
  1314. #endif /* CONFIG_COMPACTION */
  1315. {
  1316. .procname = "min_free_kbytes",
  1317. .data = &min_free_kbytes,
  1318. .maxlen = sizeof(min_free_kbytes),
  1319. .mode = 0644,
  1320. .proc_handler = min_free_kbytes_sysctl_handler,
  1321. .extra1 = &zero,
  1322. },
  1323. {
  1324. .procname = "percpu_pagelist_fraction",
  1325. .data = &percpu_pagelist_fraction,
  1326. .maxlen = sizeof(percpu_pagelist_fraction),
  1327. .mode = 0644,
  1328. .proc_handler = percpu_pagelist_fraction_sysctl_handler,
  1329. .extra1 = &zero,
  1330. },
  1331. #ifdef CONFIG_MMU
  1332. {
  1333. .procname = "max_map_count",
  1334. .data = &sysctl_max_map_count,
  1335. .maxlen = sizeof(sysctl_max_map_count),
  1336. .mode = 0644,
  1337. .proc_handler = proc_dointvec_minmax,
  1338. .extra1 = &zero,
  1339. },
  1340. #else
  1341. {
  1342. .procname = "nr_trim_pages",
  1343. .data = &sysctl_nr_trim_pages,
  1344. .maxlen = sizeof(sysctl_nr_trim_pages),
  1345. .mode = 0644,
  1346. .proc_handler = proc_dointvec_minmax,
  1347. .extra1 = &zero,
  1348. },
  1349. #endif
  1350. {
  1351. .procname = "laptop_mode",
  1352. .data = &laptop_mode,
  1353. .maxlen = sizeof(laptop_mode),
  1354. .mode = 0644,
  1355. .proc_handler = proc_dointvec_jiffies,
  1356. },
  1357. {
  1358. .procname = "block_dump",
  1359. .data = &block_dump,
  1360. .maxlen = sizeof(block_dump),
  1361. .mode = 0644,
  1362. .proc_handler = proc_dointvec,
  1363. .extra1 = &zero,
  1364. },
  1365. {
  1366. .procname = "vfs_cache_pressure",
  1367. .data = &sysctl_vfs_cache_pressure,
  1368. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  1369. .mode = 0644,
  1370. .proc_handler = proc_dointvec,
  1371. .extra1 = &zero,
  1372. },
  1373. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  1374. {
  1375. .procname = "legacy_va_layout",
  1376. .data = &sysctl_legacy_va_layout,
  1377. .maxlen = sizeof(sysctl_legacy_va_layout),
  1378. .mode = 0644,
  1379. .proc_handler = proc_dointvec,
  1380. .extra1 = &zero,
  1381. },
  1382. #endif
  1383. #ifdef CONFIG_NUMA
  1384. {
  1385. .procname = "zone_reclaim_mode",
  1386. .data = &zone_reclaim_mode,
  1387. .maxlen = sizeof(zone_reclaim_mode),
  1388. .mode = 0644,
  1389. .proc_handler = proc_dointvec,
  1390. .extra1 = &zero,
  1391. },
  1392. {
  1393. .procname = "min_unmapped_ratio",
  1394. .data = &sysctl_min_unmapped_ratio,
  1395. .maxlen = sizeof(sysctl_min_unmapped_ratio),
  1396. .mode = 0644,
  1397. .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
  1398. .extra1 = &zero,
  1399. .extra2 = &one_hundred,
  1400. },
  1401. {
  1402. .procname = "min_slab_ratio",
  1403. .data = &sysctl_min_slab_ratio,
  1404. .maxlen = sizeof(sysctl_min_slab_ratio),
  1405. .mode = 0644,
  1406. .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
  1407. .extra1 = &zero,
  1408. .extra2 = &one_hundred,
  1409. },
  1410. #endif
  1411. #ifdef CONFIG_SMP
  1412. {
  1413. .procname = "stat_interval",
  1414. .data = &sysctl_stat_interval,
  1415. .maxlen = sizeof(sysctl_stat_interval),
  1416. .mode = 0644,
  1417. .proc_handler = proc_dointvec_jiffies,
  1418. },
  1419. #endif
  1420. #ifdef CONFIG_MMU
  1421. {
  1422. .procname = "mmap_min_addr",
  1423. .data = &dac_mmap_min_addr,
  1424. .maxlen = sizeof(unsigned long),
  1425. .mode = 0644,
  1426. .proc_handler = mmap_min_addr_handler,
  1427. },
  1428. #endif
  1429. #ifdef CONFIG_NUMA
  1430. {
  1431. .procname = "numa_zonelist_order",
  1432. .data = &numa_zonelist_order,
  1433. .maxlen = NUMA_ZONELIST_ORDER_LEN,
  1434. .mode = 0644,
  1435. .proc_handler = numa_zonelist_order_handler,
  1436. },
  1437. #endif
  1438. #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
  1439. (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
  1440. {
  1441. .procname = "vdso_enabled",
  1442. #ifdef CONFIG_X86_32
  1443. .data = &vdso32_enabled,
  1444. .maxlen = sizeof(vdso32_enabled),
  1445. #else
  1446. .data = &vdso_enabled,
  1447. .maxlen = sizeof(vdso_enabled),
  1448. #endif
  1449. .mode = 0644,
  1450. .proc_handler = proc_dointvec,
  1451. .extra1 = &zero,
  1452. },
  1453. #endif
  1454. #ifdef CONFIG_HIGHMEM
  1455. {
  1456. .procname = "highmem_is_dirtyable",
  1457. .data = &vm_highmem_is_dirtyable,
  1458. .maxlen = sizeof(vm_highmem_is_dirtyable),
  1459. .mode = 0644,
  1460. .proc_handler = proc_dointvec_minmax,
  1461. .extra1 = &zero,
  1462. .extra2 = &one,
  1463. },
  1464. #endif
  1465. #ifdef CONFIG_MEMORY_FAILURE
  1466. {
  1467. .procname = "memory_failure_early_kill",
  1468. .data = &sysctl_memory_failure_early_kill,
  1469. .maxlen = sizeof(sysctl_memory_failure_early_kill),
  1470. .mode = 0644,
  1471. .proc_handler = proc_dointvec_minmax,
  1472. .extra1 = &zero,
  1473. .extra2 = &one,
  1474. },
  1475. {
  1476. .procname = "memory_failure_recovery",
  1477. .data = &sysctl_memory_failure_recovery,
  1478. .maxlen = sizeof(sysctl_memory_failure_recovery),
  1479. .mode = 0644,
  1480. .proc_handler = proc_dointvec_minmax,
  1481. .extra1 = &zero,
  1482. .extra2 = &one,
  1483. },
  1484. #endif
  1485. {
  1486. .procname = "user_reserve_kbytes",
  1487. .data = &sysctl_user_reserve_kbytes,
  1488. .maxlen = sizeof(sysctl_user_reserve_kbytes),
  1489. .mode = 0644,
  1490. .proc_handler = proc_doulongvec_minmax,
  1491. },
  1492. {
  1493. .procname = "admin_reserve_kbytes",
  1494. .data = &sysctl_admin_reserve_kbytes,
  1495. .maxlen = sizeof(sysctl_admin_reserve_kbytes),
  1496. .mode = 0644,
  1497. .proc_handler = proc_doulongvec_minmax,
  1498. },
  1499. { }
  1500. };
  1501. static struct ctl_table fs_table[] = {
  1502. {
  1503. .procname = "inode-nr",
  1504. .data = &inodes_stat,
  1505. .maxlen = 2*sizeof(long),
  1506. .mode = 0444,
  1507. .proc_handler = proc_nr_inodes,
  1508. },
  1509. {
  1510. .procname = "inode-state",
  1511. .data = &inodes_stat,
  1512. .maxlen = 7*sizeof(long),
  1513. .mode = 0444,
  1514. .proc_handler = proc_nr_inodes,
  1515. },
  1516. {
  1517. .procname = "file-nr",
  1518. .data = &files_stat,
  1519. .maxlen = sizeof(files_stat),
  1520. .mode = 0444,
  1521. .proc_handler = proc_nr_files,
  1522. },
  1523. {
  1524. .procname = "file-max",
  1525. .data = &files_stat.max_files,
  1526. .maxlen = sizeof(files_stat.max_files),
  1527. .mode = 0644,
  1528. .proc_handler = proc_doulongvec_minmax,
  1529. },
  1530. {
  1531. .procname = "nr_open",
  1532. .data = &sysctl_nr_open,
  1533. .maxlen = sizeof(int),
  1534. .mode = 0644,
  1535. .proc_handler = proc_dointvec_minmax,
  1536. .extra1 = &sysctl_nr_open_min,
  1537. .extra2 = &sysctl_nr_open_max,
  1538. },
  1539. {
  1540. .procname = "dentry-state",
  1541. .data = &dentry_stat,
  1542. .maxlen = 6*sizeof(long),
  1543. .mode = 0444,
  1544. .proc_handler = proc_nr_dentry,
  1545. },
  1546. {
  1547. .procname = "overflowuid",
  1548. .data = &fs_overflowuid,
  1549. .maxlen = sizeof(int),
  1550. .mode = 0644,
  1551. .proc_handler = proc_dointvec_minmax,
  1552. .extra1 = &minolduid,
  1553. .extra2 = &maxolduid,
  1554. },
  1555. {
  1556. .procname = "overflowgid",
  1557. .data = &fs_overflowgid,
  1558. .maxlen = sizeof(int),
  1559. .mode = 0644,
  1560. .proc_handler = proc_dointvec_minmax,
  1561. .extra1 = &minolduid,
  1562. .extra2 = &maxolduid,
  1563. },
  1564. #ifdef CONFIG_FILE_LOCKING
  1565. {
  1566. .procname = "leases-enable",
  1567. .data = &leases_enable,
  1568. .maxlen = sizeof(int),
  1569. .mode = 0644,
  1570. .proc_handler = proc_dointvec,
  1571. },
  1572. #endif
  1573. #ifdef CONFIG_DNOTIFY
  1574. {
  1575. .procname = "dir-notify-enable",
  1576. .data = &dir_notify_enable,
  1577. .maxlen = sizeof(int),
  1578. .mode = 0644,
  1579. .proc_handler = proc_dointvec,
  1580. },
  1581. #endif
  1582. #ifdef CONFIG_MMU
  1583. #ifdef CONFIG_FILE_LOCKING
  1584. {
  1585. .procname = "lease-break-time",
  1586. .data = &lease_break_time,
  1587. .maxlen = sizeof(int),
  1588. .mode = 0644,
  1589. .proc_handler = proc_dointvec,
  1590. },
  1591. #endif
  1592. #ifdef CONFIG_AIO
  1593. {
  1594. .procname = "aio-nr",
  1595. .data = &aio_nr,
  1596. .maxlen = sizeof(aio_nr),
  1597. .mode = 0444,
  1598. .proc_handler = proc_doulongvec_minmax,
  1599. },
  1600. {
  1601. .procname = "aio-max-nr",
  1602. .data = &aio_max_nr,
  1603. .maxlen = sizeof(aio_max_nr),
  1604. .mode = 0644,
  1605. .proc_handler = proc_doulongvec_minmax,
  1606. },
  1607. #endif /* CONFIG_AIO */
  1608. #ifdef CONFIG_INOTIFY_USER
  1609. {
  1610. .procname = "inotify",
  1611. .mode = 0555,
  1612. .child = inotify_table,
  1613. },
  1614. #endif
  1615. #ifdef CONFIG_EPOLL
  1616. {
  1617. .procname = "epoll",
  1618. .mode = 0555,
  1619. .child = epoll_table,
  1620. },
  1621. #endif
  1622. #endif
  1623. {
  1624. .procname = "protected_symlinks",
  1625. .data = &sysctl_protected_symlinks,
  1626. .maxlen = sizeof(int),
  1627. .mode = 0600,
  1628. .proc_handler = proc_dointvec_minmax,
  1629. .extra1 = &zero,
  1630. .extra2 = &one,
  1631. },
  1632. {
  1633. .procname = "protected_hardlinks",
  1634. .data = &sysctl_protected_hardlinks,
  1635. .maxlen = sizeof(int),
  1636. .mode = 0600,
  1637. .proc_handler = proc_dointvec_minmax,
  1638. .extra1 = &zero,
  1639. .extra2 = &one,
  1640. },
  1641. {
  1642. .procname = "suid_dumpable",
  1643. .data = &suid_dumpable,
  1644. .maxlen = sizeof(int),
  1645. .mode = 0644,
  1646. .proc_handler = proc_dointvec_minmax_coredump,
  1647. .extra1 = &zero,
  1648. .extra2 = &two,
  1649. },
  1650. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1651. {
  1652. .procname = "binfmt_misc",
  1653. .mode = 0555,
  1654. .child = sysctl_mount_point,
  1655. },
  1656. #endif
  1657. {
  1658. .procname = "pipe-max-size",
  1659. .data = &pipe_max_size,
  1660. .maxlen = sizeof(int),
  1661. .mode = 0644,
  1662. .proc_handler = &pipe_proc_fn,
  1663. .extra1 = &pipe_min_size,
  1664. },
  1665. { }
  1666. };
  1667. static struct ctl_table debug_table[] = {
  1668. #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
  1669. {
  1670. .procname = "exception-trace",
  1671. .data = &show_unhandled_signals,
  1672. .maxlen = sizeof(int),
  1673. .mode = 0644,
  1674. .proc_handler = proc_dointvec
  1675. },
  1676. #endif
  1677. #if defined(CONFIG_OPTPROBES)
  1678. {
  1679. .procname = "kprobes-optimization",
  1680. .data = &sysctl_kprobes_optimization,
  1681. .maxlen = sizeof(int),
  1682. .mode = 0644,
  1683. .proc_handler = proc_kprobes_optimization_handler,
  1684. .extra1 = &zero,
  1685. .extra2 = &one,
  1686. },
  1687. #endif
  1688. { }
  1689. };
  1690. static struct ctl_table dev_table[] = {
  1691. { }
  1692. };
  1693. int __init sysctl_init(void)
  1694. {
  1695. struct ctl_table_header *hdr;
  1696. hdr = register_sysctl_table(sysctl_base_table);
  1697. kmemleak_not_leak(hdr);
  1698. return 0;
  1699. }
  1700. #endif /* CONFIG_SYSCTL */
  1701. /*
  1702. * /proc/sys support
  1703. */
  1704. #ifdef CONFIG_PROC_SYSCTL
  1705. static int _proc_do_string(char *data, int maxlen, int write,
  1706. char __user *buffer,
  1707. size_t *lenp, loff_t *ppos)
  1708. {
  1709. size_t len;
  1710. char __user *p;
  1711. char c;
  1712. if (!data || !maxlen || !*lenp) {
  1713. *lenp = 0;
  1714. return 0;
  1715. }
  1716. if (write) {
  1717. if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
  1718. /* Only continue writes not past the end of buffer. */
  1719. len = strlen(data);
  1720. if (len > maxlen - 1)
  1721. len = maxlen - 1;
  1722. if (*ppos > len)
  1723. return 0;
  1724. len = *ppos;
  1725. } else {
  1726. /* Start writing from beginning of buffer. */
  1727. len = 0;
  1728. }
  1729. *ppos += *lenp;
  1730. p = buffer;
  1731. while ((p - buffer) < *lenp && len < maxlen - 1) {
  1732. if (get_user(c, p++))
  1733. return -EFAULT;
  1734. if (c == 0 || c == '\n')
  1735. break;
  1736. data[len++] = c;
  1737. }
  1738. data[len] = 0;
  1739. } else {
  1740. len = strlen(data);
  1741. if (len > maxlen)
  1742. len = maxlen;
  1743. if (*ppos > len) {
  1744. *lenp = 0;
  1745. return 0;
  1746. }
  1747. data += *ppos;
  1748. len -= *ppos;
  1749. if (len > *lenp)
  1750. len = *lenp;
  1751. if (len)
  1752. if (copy_to_user(buffer, data, len))
  1753. return -EFAULT;
  1754. if (len < *lenp) {
  1755. if (put_user('\n', buffer + len))
  1756. return -EFAULT;
  1757. len++;
  1758. }
  1759. *lenp = len;
  1760. *ppos += len;
  1761. }
  1762. return 0;
  1763. }
  1764. static void warn_sysctl_write(struct ctl_table *table)
  1765. {
  1766. pr_warn_once("%s wrote to %s when file position was not 0!\n"
  1767. "This will not be supported in the future. To silence this\n"
  1768. "warning, set kernel.sysctl_writes_strict = -1\n",
  1769. current->comm, table->procname);
  1770. }
  1771. /**
  1772. * proc_dostring - read a string sysctl
  1773. * @table: the sysctl table
  1774. * @write: %TRUE if this is a write to the sysctl file
  1775. * @buffer: the user buffer
  1776. * @lenp: the size of the user buffer
  1777. * @ppos: file position
  1778. *
  1779. * Reads/writes a string from/to the user buffer. If the kernel
  1780. * buffer provided is not large enough to hold the string, the
  1781. * string is truncated. The copied string is %NULL-terminated.
  1782. * If the string is being read by the user process, it is copied
  1783. * and a newline '\n' is added. It is truncated if the buffer is
  1784. * not large enough.
  1785. *
  1786. * Returns 0 on success.
  1787. */
  1788. int proc_dostring(struct ctl_table *table, int write,
  1789. void __user *buffer, size_t *lenp, loff_t *ppos)
  1790. {
  1791. if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
  1792. warn_sysctl_write(table);
  1793. return _proc_do_string((char *)(table->data), table->maxlen, write,
  1794. (char __user *)buffer, lenp, ppos);
  1795. }
  1796. static size_t proc_skip_spaces(char **buf)
  1797. {
  1798. size_t ret;
  1799. char *tmp = skip_spaces(*buf);
  1800. ret = tmp - *buf;
  1801. *buf = tmp;
  1802. return ret;
  1803. }
  1804. static void proc_skip_char(char **buf, size_t *size, const char v)
  1805. {
  1806. while (*size) {
  1807. if (**buf != v)
  1808. break;
  1809. (*size)--;
  1810. (*buf)++;
  1811. }
  1812. }
  1813. #define TMPBUFLEN 22
  1814. /**
  1815. * proc_get_long - reads an ASCII formatted integer from a user buffer
  1816. *
  1817. * @buf: a kernel buffer
  1818. * @size: size of the kernel buffer
  1819. * @val: this is where the number will be stored
  1820. * @neg: set to %TRUE if number is negative
  1821. * @perm_tr: a vector which contains the allowed trailers
  1822. * @perm_tr_len: size of the perm_tr vector
  1823. * @tr: pointer to store the trailer character
  1824. *
  1825. * In case of success %0 is returned and @buf and @size are updated with
  1826. * the amount of bytes read. If @tr is non-NULL and a trailing
  1827. * character exists (size is non-zero after returning from this
  1828. * function), @tr is updated with the trailing character.
  1829. */
  1830. static int proc_get_long(char **buf, size_t *size,
  1831. unsigned long *val, bool *neg,
  1832. const char *perm_tr, unsigned perm_tr_len, char *tr)
  1833. {
  1834. int len;
  1835. char *p, tmp[TMPBUFLEN];
  1836. if (!*size)
  1837. return -EINVAL;
  1838. len = *size;
  1839. if (len > TMPBUFLEN - 1)
  1840. len = TMPBUFLEN - 1;
  1841. memcpy(tmp, *buf, len);
  1842. tmp[len] = 0;
  1843. p = tmp;
  1844. if (*p == '-' && *size > 1) {
  1845. *neg = true;
  1846. p++;
  1847. } else
  1848. *neg = false;
  1849. if (!isdigit(*p))
  1850. return -EINVAL;
  1851. *val = simple_strtoul(p, &p, 0);
  1852. len = p - tmp;
  1853. /* We don't know if the next char is whitespace thus we may accept
  1854. * invalid integers (e.g. 1234...a) or two integers instead of one
  1855. * (e.g. 123...1). So lets not allow such large numbers. */
  1856. if (len == TMPBUFLEN - 1)
  1857. return -EINVAL;
  1858. if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
  1859. return -EINVAL;
  1860. if (tr && (len < *size))
  1861. *tr = *p;
  1862. *buf += len;
  1863. *size -= len;
  1864. return 0;
  1865. }
  1866. /**
  1867. * proc_put_long - converts an integer to a decimal ASCII formatted string
  1868. *
  1869. * @buf: the user buffer
  1870. * @size: the size of the user buffer
  1871. * @val: the integer to be converted
  1872. * @neg: sign of the number, %TRUE for negative
  1873. *
  1874. * In case of success %0 is returned and @buf and @size are updated with
  1875. * the amount of bytes written.
  1876. */
  1877. static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
  1878. bool neg)
  1879. {
  1880. int len;
  1881. char tmp[TMPBUFLEN], *p = tmp;
  1882. sprintf(p, "%s%lu", neg ? "-" : "", val);
  1883. len = strlen(tmp);
  1884. if (len > *size)
  1885. len = *size;
  1886. if (copy_to_user(*buf, tmp, len))
  1887. return -EFAULT;
  1888. *size -= len;
  1889. *buf += len;
  1890. return 0;
  1891. }
  1892. #undef TMPBUFLEN
  1893. static int proc_put_char(void __user **buf, size_t *size, char c)
  1894. {
  1895. if (*size) {
  1896. char __user **buffer = (char __user **)buf;
  1897. if (put_user(c, *buffer))
  1898. return -EFAULT;
  1899. (*size)--, (*buffer)++;
  1900. *buf = *buffer;
  1901. }
  1902. return 0;
  1903. }
  1904. static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
  1905. int *valp,
  1906. int write, void *data)
  1907. {
  1908. if (write) {
  1909. if (*negp) {
  1910. if (*lvalp > (unsigned long) INT_MAX + 1)
  1911. return -EINVAL;
  1912. *valp = -*lvalp;
  1913. } else {
  1914. if (*lvalp > (unsigned long) INT_MAX)
  1915. return -EINVAL;
  1916. *valp = *lvalp;
  1917. }
  1918. } else {
  1919. int val = *valp;
  1920. if (val < 0) {
  1921. *negp = true;
  1922. *lvalp = (unsigned long)-val;
  1923. } else {
  1924. *negp = false;
  1925. *lvalp = (unsigned long)val;
  1926. }
  1927. }
  1928. return 0;
  1929. }
  1930. static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
  1931. static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
  1932. int write, void __user *buffer,
  1933. size_t *lenp, loff_t *ppos,
  1934. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  1935. int write, void *data),
  1936. void *data)
  1937. {
  1938. int *i, vleft, first = 1, err = 0;
  1939. unsigned long page = 0;
  1940. size_t left;
  1941. char *kbuf;
  1942. if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
  1943. *lenp = 0;
  1944. return 0;
  1945. }
  1946. i = (int *) tbl_data;
  1947. vleft = table->maxlen / sizeof(*i);
  1948. left = *lenp;
  1949. if (!conv)
  1950. conv = do_proc_dointvec_conv;
  1951. if (write) {
  1952. if (*ppos) {
  1953. switch (sysctl_writes_strict) {
  1954. case SYSCTL_WRITES_STRICT:
  1955. goto out;
  1956. case SYSCTL_WRITES_WARN:
  1957. warn_sysctl_write(table);
  1958. break;
  1959. default:
  1960. break;
  1961. }
  1962. }
  1963. if (left > PAGE_SIZE - 1)
  1964. left = PAGE_SIZE - 1;
  1965. page = __get_free_page(GFP_TEMPORARY);
  1966. kbuf = (char *) page;
  1967. if (!kbuf)
  1968. return -ENOMEM;
  1969. if (copy_from_user(kbuf, buffer, left)) {
  1970. err = -EFAULT;
  1971. goto free;
  1972. }
  1973. kbuf[left] = 0;
  1974. }
  1975. for (; left && vleft--; i++, first=0) {
  1976. unsigned long lval;
  1977. bool neg;
  1978. if (write) {
  1979. left -= proc_skip_spaces(&kbuf);
  1980. if (!left)
  1981. break;
  1982. err = proc_get_long(&kbuf, &left, &lval, &neg,
  1983. proc_wspace_sep,
  1984. sizeof(proc_wspace_sep), NULL);
  1985. if (err)
  1986. break;
  1987. if (conv(&neg, &lval, i, 1, data)) {
  1988. err = -EINVAL;
  1989. break;
  1990. }
  1991. } else {
  1992. if (conv(&neg, &lval, i, 0, data)) {
  1993. err = -EINVAL;
  1994. break;
  1995. }
  1996. if (!first)
  1997. err = proc_put_char(&buffer, &left, '\t');
  1998. if (err)
  1999. break;
  2000. err = proc_put_long(&buffer, &left, lval, neg);
  2001. if (err)
  2002. break;
  2003. }
  2004. }
  2005. if (!write && !first && left && !err)
  2006. err = proc_put_char(&buffer, &left, '\n');
  2007. if (write && !err && left)
  2008. left -= proc_skip_spaces(&kbuf);
  2009. free:
  2010. if (write) {
  2011. free_page(page);
  2012. if (first)
  2013. return err ? : -EINVAL;
  2014. }
  2015. *lenp -= left;
  2016. out:
  2017. *ppos += *lenp;
  2018. return err;
  2019. }
  2020. static int do_proc_dointvec(struct ctl_table *table, int write,
  2021. void __user *buffer, size_t *lenp, loff_t *ppos,
  2022. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  2023. int write, void *data),
  2024. void *data)
  2025. {
  2026. return __do_proc_dointvec(table->data, table, write,
  2027. buffer, lenp, ppos, conv, data);
  2028. }
  2029. /**
  2030. * proc_dointvec - read a vector of integers
  2031. * @table: the sysctl table
  2032. * @write: %TRUE if this is a write to the sysctl file
  2033. * @buffer: the user buffer
  2034. * @lenp: the size of the user buffer
  2035. * @ppos: file position
  2036. *
  2037. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2038. * values from/to the user buffer, treated as an ASCII string.
  2039. *
  2040. * Returns 0 on success.
  2041. */
  2042. int proc_dointvec(struct ctl_table *table, int write,
  2043. void __user *buffer, size_t *lenp, loff_t *ppos)
  2044. {
  2045. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  2046. NULL,NULL);
  2047. }
  2048. /*
  2049. * Taint values can only be increased
  2050. * This means we can safely use a temporary.
  2051. */
  2052. static int proc_taint(struct ctl_table *table, int write,
  2053. void __user *buffer, size_t *lenp, loff_t *ppos)
  2054. {
  2055. struct ctl_table t;
  2056. unsigned long tmptaint = get_taint();
  2057. int err;
  2058. if (write && !capable(CAP_SYS_ADMIN))
  2059. return -EPERM;
  2060. t = *table;
  2061. t.data = &tmptaint;
  2062. err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
  2063. if (err < 0)
  2064. return err;
  2065. if (write) {
  2066. /*
  2067. * Poor man's atomic or. Not worth adding a primitive
  2068. * to everyone's atomic.h for this
  2069. */
  2070. int i;
  2071. for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
  2072. if ((tmptaint >> i) & 1)
  2073. add_taint(i, LOCKDEP_STILL_OK);
  2074. }
  2075. }
  2076. return err;
  2077. }
  2078. #ifdef CONFIG_PRINTK
  2079. static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  2080. void __user *buffer, size_t *lenp, loff_t *ppos)
  2081. {
  2082. if (write && !capable(CAP_SYS_ADMIN))
  2083. return -EPERM;
  2084. return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  2085. }
  2086. #endif
  2087. struct do_proc_dointvec_minmax_conv_param {
  2088. int *min;
  2089. int *max;
  2090. };
  2091. static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
  2092. int *valp,
  2093. int write, void *data)
  2094. {
  2095. struct do_proc_dointvec_minmax_conv_param *param = data;
  2096. if (write) {
  2097. int val = *negp ? -*lvalp : *lvalp;
  2098. if ((param->min && *param->min > val) ||
  2099. (param->max && *param->max < val))
  2100. return -EINVAL;
  2101. *valp = val;
  2102. } else {
  2103. int val = *valp;
  2104. if (val < 0) {
  2105. *negp = true;
  2106. *lvalp = (unsigned long)-val;
  2107. } else {
  2108. *negp = false;
  2109. *lvalp = (unsigned long)val;
  2110. }
  2111. }
  2112. return 0;
  2113. }
  2114. /**
  2115. * proc_dointvec_minmax - read a vector of integers with min/max values
  2116. * @table: the sysctl table
  2117. * @write: %TRUE if this is a write to the sysctl file
  2118. * @buffer: the user buffer
  2119. * @lenp: the size of the user buffer
  2120. * @ppos: file position
  2121. *
  2122. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2123. * values from/to the user buffer, treated as an ASCII string.
  2124. *
  2125. * This routine will ensure the values are within the range specified by
  2126. * table->extra1 (min) and table->extra2 (max).
  2127. *
  2128. * Returns 0 on success.
  2129. */
  2130. int proc_dointvec_minmax(struct ctl_table *table, int write,
  2131. void __user *buffer, size_t *lenp, loff_t *ppos)
  2132. {
  2133. struct do_proc_dointvec_minmax_conv_param param = {
  2134. .min = (int *) table->extra1,
  2135. .max = (int *) table->extra2,
  2136. };
  2137. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  2138. do_proc_dointvec_minmax_conv, &param);
  2139. }
  2140. static void validate_coredump_safety(void)
  2141. {
  2142. #ifdef CONFIG_COREDUMP
  2143. if (suid_dumpable == SUID_DUMP_ROOT &&
  2144. core_pattern[0] != '/' && core_pattern[0] != '|') {
  2145. printk(KERN_WARNING "Unsafe core_pattern used with "\
  2146. "suid_dumpable=2. Pipe handler or fully qualified "\
  2147. "core dump path required.\n");
  2148. }
  2149. #endif
  2150. }
  2151. static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
  2152. void __user *buffer, size_t *lenp, loff_t *ppos)
  2153. {
  2154. int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  2155. if (!error)
  2156. validate_coredump_safety();
  2157. return error;
  2158. }
  2159. #ifdef CONFIG_COREDUMP
  2160. static int proc_dostring_coredump(struct ctl_table *table, int write,
  2161. void __user *buffer, size_t *lenp, loff_t *ppos)
  2162. {
  2163. int error = proc_dostring(table, write, buffer, lenp, ppos);
  2164. if (!error)
  2165. validate_coredump_safety();
  2166. return error;
  2167. }
  2168. #endif
  2169. static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
  2170. void __user *buffer,
  2171. size_t *lenp, loff_t *ppos,
  2172. unsigned long convmul,
  2173. unsigned long convdiv)
  2174. {
  2175. unsigned long *i, *min, *max;
  2176. int vleft, first = 1, err = 0;
  2177. unsigned long page = 0;
  2178. size_t left;
  2179. char *kbuf;
  2180. if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
  2181. *lenp = 0;
  2182. return 0;
  2183. }
  2184. i = (unsigned long *) data;
  2185. min = (unsigned long *) table->extra1;
  2186. max = (unsigned long *) table->extra2;
  2187. vleft = table->maxlen / sizeof(unsigned long);
  2188. left = *lenp;
  2189. if (write) {
  2190. if (*ppos) {
  2191. switch (sysctl_writes_strict) {
  2192. case SYSCTL_WRITES_STRICT:
  2193. goto out;
  2194. case SYSCTL_WRITES_WARN:
  2195. warn_sysctl_write(table);
  2196. break;
  2197. default:
  2198. break;
  2199. }
  2200. }
  2201. if (left > PAGE_SIZE - 1)
  2202. left = PAGE_SIZE - 1;
  2203. page = __get_free_page(GFP_TEMPORARY);
  2204. kbuf = (char *) page;
  2205. if (!kbuf)
  2206. return -ENOMEM;
  2207. if (copy_from_user(kbuf, buffer, left)) {
  2208. err = -EFAULT;
  2209. goto free;
  2210. }
  2211. kbuf[left] = 0;
  2212. }
  2213. for (; left && vleft--; i++, first = 0) {
  2214. unsigned long val;
  2215. if (write) {
  2216. bool neg;
  2217. left -= proc_skip_spaces(&kbuf);
  2218. err = proc_get_long(&kbuf, &left, &val, &neg,
  2219. proc_wspace_sep,
  2220. sizeof(proc_wspace_sep), NULL);
  2221. if (err)
  2222. break;
  2223. if (neg)
  2224. continue;
  2225. if ((min && val < *min) || (max && val > *max))
  2226. continue;
  2227. *i = val;
  2228. } else {
  2229. val = convdiv * (*i) / convmul;
  2230. if (!first) {
  2231. err = proc_put_char(&buffer, &left, '\t');
  2232. if (err)
  2233. break;
  2234. }
  2235. err = proc_put_long(&buffer, &left, val, false);
  2236. if (err)
  2237. break;
  2238. }
  2239. }
  2240. if (!write && !first && left && !err)
  2241. err = proc_put_char(&buffer, &left, '\n');
  2242. if (write && !err)
  2243. left -= proc_skip_spaces(&kbuf);
  2244. free:
  2245. if (write) {
  2246. free_page(page);
  2247. if (first)
  2248. return err ? : -EINVAL;
  2249. }
  2250. *lenp -= left;
  2251. out:
  2252. *ppos += *lenp;
  2253. return err;
  2254. }
  2255. static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
  2256. void __user *buffer,
  2257. size_t *lenp, loff_t *ppos,
  2258. unsigned long convmul,
  2259. unsigned long convdiv)
  2260. {
  2261. return __do_proc_doulongvec_minmax(table->data, table, write,
  2262. buffer, lenp, ppos, convmul, convdiv);
  2263. }
  2264. /**
  2265. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  2266. * @table: the sysctl table
  2267. * @write: %TRUE if this is a write to the sysctl file
  2268. * @buffer: the user buffer
  2269. * @lenp: the size of the user buffer
  2270. * @ppos: file position
  2271. *
  2272. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2273. * values from/to the user buffer, treated as an ASCII string.
  2274. *
  2275. * This routine will ensure the values are within the range specified by
  2276. * table->extra1 (min) and table->extra2 (max).
  2277. *
  2278. * Returns 0 on success.
  2279. */
  2280. int proc_doulongvec_minmax(struct ctl_table *table, int write,
  2281. void __user *buffer, size_t *lenp, loff_t *ppos)
  2282. {
  2283. return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
  2284. }
  2285. /**
  2286. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  2287. * @table: the sysctl table
  2288. * @write: %TRUE if this is a write to the sysctl file
  2289. * @buffer: the user buffer
  2290. * @lenp: the size of the user buffer
  2291. * @ppos: file position
  2292. *
  2293. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2294. * values from/to the user buffer, treated as an ASCII string. The values
  2295. * are treated as milliseconds, and converted to jiffies when they are stored.
  2296. *
  2297. * This routine will ensure the values are within the range specified by
  2298. * table->extra1 (min) and table->extra2 (max).
  2299. *
  2300. * Returns 0 on success.
  2301. */
  2302. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  2303. void __user *buffer,
  2304. size_t *lenp, loff_t *ppos)
  2305. {
  2306. return do_proc_doulongvec_minmax(table, write, buffer,
  2307. lenp, ppos, HZ, 1000l);
  2308. }
  2309. static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
  2310. int *valp,
  2311. int write, void *data)
  2312. {
  2313. if (write) {
  2314. if (*lvalp > LONG_MAX / HZ)
  2315. return 1;
  2316. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  2317. } else {
  2318. int val = *valp;
  2319. unsigned long lval;
  2320. if (val < 0) {
  2321. *negp = true;
  2322. lval = (unsigned long)-val;
  2323. } else {
  2324. *negp = false;
  2325. lval = (unsigned long)val;
  2326. }
  2327. *lvalp = lval / HZ;
  2328. }
  2329. return 0;
  2330. }
  2331. static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
  2332. int *valp,
  2333. int write, void *data)
  2334. {
  2335. if (write) {
  2336. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  2337. return 1;
  2338. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  2339. } else {
  2340. int val = *valp;
  2341. unsigned long lval;
  2342. if (val < 0) {
  2343. *negp = true;
  2344. lval = (unsigned long)-val;
  2345. } else {
  2346. *negp = false;
  2347. lval = (unsigned long)val;
  2348. }
  2349. *lvalp = jiffies_to_clock_t(lval);
  2350. }
  2351. return 0;
  2352. }
  2353. static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
  2354. int *valp,
  2355. int write, void *data)
  2356. {
  2357. if (write) {
  2358. unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  2359. if (jif > INT_MAX)
  2360. return 1;
  2361. *valp = (int)jif;
  2362. } else {
  2363. int val = *valp;
  2364. unsigned long lval;
  2365. if (val < 0) {
  2366. *negp = true;
  2367. lval = (unsigned long)-val;
  2368. } else {
  2369. *negp = false;
  2370. lval = (unsigned long)val;
  2371. }
  2372. *lvalp = jiffies_to_msecs(lval);
  2373. }
  2374. return 0;
  2375. }
  2376. /**
  2377. * proc_dointvec_jiffies - read a vector of integers as seconds
  2378. * @table: the sysctl table
  2379. * @write: %TRUE if this is a write to the sysctl file
  2380. * @buffer: the user buffer
  2381. * @lenp: the size of the user buffer
  2382. * @ppos: file position
  2383. *
  2384. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2385. * values from/to the user buffer, treated as an ASCII string.
  2386. * The values read are assumed to be in seconds, and are converted into
  2387. * jiffies.
  2388. *
  2389. * Returns 0 on success.
  2390. */
  2391. int proc_dointvec_jiffies(struct ctl_table *table, int write,
  2392. void __user *buffer, size_t *lenp, loff_t *ppos)
  2393. {
  2394. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  2395. do_proc_dointvec_jiffies_conv,NULL);
  2396. }
  2397. /**
  2398. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  2399. * @table: the sysctl table
  2400. * @write: %TRUE if this is a write to the sysctl file
  2401. * @buffer: the user buffer
  2402. * @lenp: the size of the user buffer
  2403. * @ppos: pointer to the file position
  2404. *
  2405. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2406. * values from/to the user buffer, treated as an ASCII string.
  2407. * The values read are assumed to be in 1/USER_HZ seconds, and
  2408. * are converted into jiffies.
  2409. *
  2410. * Returns 0 on success.
  2411. */
  2412. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
  2413. void __user *buffer, size_t *lenp, loff_t *ppos)
  2414. {
  2415. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  2416. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2417. }
  2418. /**
  2419. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2420. * @table: the sysctl table
  2421. * @write: %TRUE if this is a write to the sysctl file
  2422. * @buffer: the user buffer
  2423. * @lenp: the size of the user buffer
  2424. * @ppos: file position
  2425. * @ppos: the current position in the file
  2426. *
  2427. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2428. * values from/to the user buffer, treated as an ASCII string.
  2429. * The values read are assumed to be in 1/1000 seconds, and
  2430. * are converted into jiffies.
  2431. *
  2432. * Returns 0 on success.
  2433. */
  2434. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
  2435. void __user *buffer, size_t *lenp, loff_t *ppos)
  2436. {
  2437. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  2438. do_proc_dointvec_ms_jiffies_conv, NULL);
  2439. }
  2440. static int proc_do_cad_pid(struct ctl_table *table, int write,
  2441. void __user *buffer, size_t *lenp, loff_t *ppos)
  2442. {
  2443. struct pid *new_pid;
  2444. pid_t tmp;
  2445. int r;
  2446. tmp = pid_vnr(cad_pid);
  2447. r = __do_proc_dointvec(&tmp, table, write, buffer,
  2448. lenp, ppos, NULL, NULL);
  2449. if (r || !write)
  2450. return r;
  2451. new_pid = find_get_pid(tmp);
  2452. if (!new_pid)
  2453. return -ESRCH;
  2454. put_pid(xchg(&cad_pid, new_pid));
  2455. return 0;
  2456. }
  2457. /**
  2458. * proc_do_large_bitmap - read/write from/to a large bitmap
  2459. * @table: the sysctl table
  2460. * @write: %TRUE if this is a write to the sysctl file
  2461. * @buffer: the user buffer
  2462. * @lenp: the size of the user buffer
  2463. * @ppos: file position
  2464. *
  2465. * The bitmap is stored at table->data and the bitmap length (in bits)
  2466. * in table->maxlen.
  2467. *
  2468. * We use a range comma separated format (e.g. 1,3-4,10-10) so that
  2469. * large bitmaps may be represented in a compact manner. Writing into
  2470. * the file will clear the bitmap then update it with the given input.
  2471. *
  2472. * Returns 0 on success.
  2473. */
  2474. int proc_do_large_bitmap(struct ctl_table *table, int write,
  2475. void __user *buffer, size_t *lenp, loff_t *ppos)
  2476. {
  2477. int err = 0;
  2478. bool first = 1;
  2479. size_t left = *lenp;
  2480. unsigned long bitmap_len = table->maxlen;
  2481. unsigned long *bitmap = *(unsigned long **) table->data;
  2482. unsigned long *tmp_bitmap = NULL;
  2483. char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
  2484. if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
  2485. *lenp = 0;
  2486. return 0;
  2487. }
  2488. if (write) {
  2489. unsigned long page = 0;
  2490. char *kbuf;
  2491. if (left > PAGE_SIZE - 1)
  2492. left = PAGE_SIZE - 1;
  2493. page = __get_free_page(GFP_TEMPORARY);
  2494. kbuf = (char *) page;
  2495. if (!kbuf)
  2496. return -ENOMEM;
  2497. if (copy_from_user(kbuf, buffer, left)) {
  2498. free_page(page);
  2499. return -EFAULT;
  2500. }
  2501. kbuf[left] = 0;
  2502. tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
  2503. GFP_KERNEL);
  2504. if (!tmp_bitmap) {
  2505. free_page(page);
  2506. return -ENOMEM;
  2507. }
  2508. proc_skip_char(&kbuf, &left, '\n');
  2509. while (!err && left) {
  2510. unsigned long val_a, val_b;
  2511. bool neg;
  2512. err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
  2513. sizeof(tr_a), &c);
  2514. if (err)
  2515. break;
  2516. if (val_a >= bitmap_len || neg) {
  2517. err = -EINVAL;
  2518. break;
  2519. }
  2520. val_b = val_a;
  2521. if (left) {
  2522. kbuf++;
  2523. left--;
  2524. }
  2525. if (c == '-') {
  2526. err = proc_get_long(&kbuf, &left, &val_b,
  2527. &neg, tr_b, sizeof(tr_b),
  2528. &c);
  2529. if (err)
  2530. break;
  2531. if (val_b >= bitmap_len || neg ||
  2532. val_a > val_b) {
  2533. err = -EINVAL;
  2534. break;
  2535. }
  2536. if (left) {
  2537. kbuf++;
  2538. left--;
  2539. }
  2540. }
  2541. bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
  2542. first = 0;
  2543. proc_skip_char(&kbuf, &left, '\n');
  2544. }
  2545. free_page(page);
  2546. } else {
  2547. unsigned long bit_a, bit_b = 0;
  2548. while (left) {
  2549. bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
  2550. if (bit_a >= bitmap_len)
  2551. break;
  2552. bit_b = find_next_zero_bit(bitmap, bitmap_len,
  2553. bit_a + 1) - 1;
  2554. if (!first) {
  2555. err = proc_put_char(&buffer, &left, ',');
  2556. if (err)
  2557. break;
  2558. }
  2559. err = proc_put_long(&buffer, &left, bit_a, false);
  2560. if (err)
  2561. break;
  2562. if (bit_a != bit_b) {
  2563. err = proc_put_char(&buffer, &left, '-');
  2564. if (err)
  2565. break;
  2566. err = proc_put_long(&buffer, &left, bit_b, false);
  2567. if (err)
  2568. break;
  2569. }
  2570. first = 0; bit_b++;
  2571. }
  2572. if (!err)
  2573. err = proc_put_char(&buffer, &left, '\n');
  2574. }
  2575. if (!err) {
  2576. if (write) {
  2577. if (*ppos)
  2578. bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
  2579. else
  2580. bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
  2581. }
  2582. kfree(tmp_bitmap);
  2583. *lenp -= left;
  2584. *ppos += *lenp;
  2585. return 0;
  2586. } else {
  2587. kfree(tmp_bitmap);
  2588. return err;
  2589. }
  2590. }
  2591. #else /* CONFIG_PROC_SYSCTL */
  2592. int proc_dostring(struct ctl_table *table, int write,
  2593. void __user *buffer, size_t *lenp, loff_t *ppos)
  2594. {
  2595. return -ENOSYS;
  2596. }
  2597. int proc_dointvec(struct ctl_table *table, int write,
  2598. void __user *buffer, size_t *lenp, loff_t *ppos)
  2599. {
  2600. return -ENOSYS;
  2601. }
  2602. int proc_dointvec_minmax(struct ctl_table *table, int write,
  2603. void __user *buffer, size_t *lenp, loff_t *ppos)
  2604. {
  2605. return -ENOSYS;
  2606. }
  2607. int proc_dointvec_jiffies(struct ctl_table *table, int write,
  2608. void __user *buffer, size_t *lenp, loff_t *ppos)
  2609. {
  2610. return -ENOSYS;
  2611. }
  2612. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
  2613. void __user *buffer, size_t *lenp, loff_t *ppos)
  2614. {
  2615. return -ENOSYS;
  2616. }
  2617. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
  2618. void __user *buffer, size_t *lenp, loff_t *ppos)
  2619. {
  2620. return -ENOSYS;
  2621. }
  2622. int proc_doulongvec_minmax(struct ctl_table *table, int write,
  2623. void __user *buffer, size_t *lenp, loff_t *ppos)
  2624. {
  2625. return -ENOSYS;
  2626. }
  2627. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  2628. void __user *buffer,
  2629. size_t *lenp, loff_t *ppos)
  2630. {
  2631. return -ENOSYS;
  2632. }
  2633. #endif /* CONFIG_PROC_SYSCTL */
  2634. /*
  2635. * No sense putting this after each symbol definition, twice,
  2636. * exception granted :-)
  2637. */
  2638. EXPORT_SYMBOL(proc_dointvec);
  2639. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2640. EXPORT_SYMBOL(proc_dointvec_minmax);
  2641. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2642. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2643. EXPORT_SYMBOL(proc_dostring);
  2644. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2645. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);