sysctl.c 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * sysctl.c: General linux system control interface
  4. *
  5. * Begun 24 March 1995, Stephen Tweedie
  6. * Added /proc support, Dec 1995
  7. * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
  8. * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
  9. * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
  10. * Dynamic registration fixes, Stephen Tweedie.
  11. * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
  12. * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
  13. * Horn.
  14. * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
  15. * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
  16. * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
  17. * Wendling.
  18. * The list_for_each() macro wasn't appropriate for the sysctl loop.
  19. * Removed it and replaced it with older style, 03/23/00, Bill Wendling
  20. */
  21. #include <linux/module.h>
  22. #include <linux/aio.h>
  23. #include <linux/mm.h>
  24. #include <linux/swap.h>
  25. #include <linux/slab.h>
  26. #include <linux/sysctl.h>
  27. #include <linux/bitmap.h>
  28. #include <linux/signal.h>
  29. #include <linux/printk.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/security.h>
  32. #include <linux/ctype.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/sched/coredump.h>
  66. #include <linux/kexec.h>
  67. #include <linux/bpf.h>
  68. #include <linux/mount.h>
  69. #include <linux/userfaultfd_k.h>
  70. #include <linux/coredump.h>
  71. #include <linux/latencytop.h>
  72. #include <linux/pid.h>
  73. #include "../lib/kstrtox.h"
  74. #include <linux/uaccess.h>
  75. #include <asm/processor.h>
  76. #ifdef CONFIG_X86
  77. #include <asm/nmi.h>
  78. #include <asm/stacktrace.h>
  79. #include <asm/io.h>
  80. #endif
  81. #ifdef CONFIG_SPARC
  82. #include <asm/setup.h>
  83. #endif
  84. #ifdef CONFIG_BSD_PROCESS_ACCT
  85. #include <linux/acct.h>
  86. #endif
  87. #ifdef CONFIG_RT_MUTEXES
  88. #include <linux/rtmutex.h>
  89. #endif
  90. #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
  91. #include <linux/lockdep.h>
  92. #endif
  93. #ifdef CONFIG_CHR_DEV_SG
  94. #include <scsi/sg.h>
  95. #endif
  96. #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
  97. #include <linux/stackleak.h>
  98. #endif
  99. #ifdef CONFIG_LOCKUP_DETECTOR
  100. #include <linux/nmi.h>
  101. #endif
  102. #if defined(CONFIG_SYSCTL)
  103. /* External variables not in a header file. */
  104. extern int extra_free_kbytes;
  105. /* Constants used for minimum and maximum */
  106. #ifdef CONFIG_LOCKUP_DETECTOR
  107. static int sixty = 60;
  108. #endif
  109. static int __maybe_unused neg_one = -1;
  110. static int __maybe_unused two = 2;
  111. static int __maybe_unused four = 4;
  112. static unsigned long zero_ul;
  113. static unsigned long one_ul = 1;
  114. static unsigned long long_max = LONG_MAX;
  115. static int one_hundred = 100;
  116. static int two_hundred = 200;
  117. static int one_thousand = 1000;
  118. #ifdef CONFIG_PRINTK
  119. static int ten_thousand = 10000;
  120. #endif
  121. #ifdef CONFIG_PERF_EVENTS
  122. static int six_hundred_forty_kb = 640 * 1024;
  123. #endif
  124. /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
  125. static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
  126. /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
  127. static int maxolduid = 65535;
  128. static int minolduid;
  129. static int ngroups_max = NGROUPS_MAX;
  130. static const int cap_last_cap = CAP_LAST_CAP;
  131. /*
  132. * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
  133. * and hung_task_check_interval_secs
  134. */
  135. #ifdef CONFIG_DETECT_HUNG_TASK
  136. static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
  137. #endif
  138. #ifdef CONFIG_INOTIFY_USER
  139. #include <linux/inotify.h>
  140. #endif
  141. #ifdef CONFIG_PROC_SYSCTL
  142. /**
  143. * enum sysctl_writes_mode - supported sysctl write modes
  144. *
  145. * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
  146. * to be written, and multiple writes on the same sysctl file descriptor
  147. * will rewrite the sysctl value, regardless of file position. No warning
  148. * is issued when the initial position is not 0.
  149. * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
  150. * not 0.
  151. * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
  152. * file position 0 and the value must be fully contained in the buffer
  153. * sent to the write syscall. If dealing with strings respect the file
  154. * position, but restrict this to the max length of the buffer, anything
  155. * passed the max length will be ignored. Multiple writes will append
  156. * to the buffer.
  157. *
  158. * These write modes control how current file position affects the behavior of
  159. * updating sysctl values through the proc interface on each write.
  160. */
  161. enum sysctl_writes_mode {
  162. SYSCTL_WRITES_LEGACY = -1,
  163. SYSCTL_WRITES_WARN = 0,
  164. SYSCTL_WRITES_STRICT = 1,
  165. };
  166. static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
  167. #endif /* CONFIG_PROC_SYSCTL */
  168. #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
  169. defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
  170. int sysctl_legacy_va_layout;
  171. #endif
  172. #ifdef CONFIG_SCHED_DEBUG
  173. static int min_sched_granularity_ns = 100000; /* 100 usecs */
  174. static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
  175. static int min_wakeup_granularity_ns; /* 0 usecs */
  176. static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
  177. #ifdef CONFIG_SMP
  178. static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
  179. static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
  180. #endif /* CONFIG_SMP */
  181. #endif /* CONFIG_SCHED_DEBUG */
  182. #ifdef CONFIG_COMPACTION
  183. static int min_extfrag_threshold;
  184. static int max_extfrag_threshold = 1000;
  185. #endif
  186. #endif /* CONFIG_SYSCTL */
  187. #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
  188. static int bpf_stats_handler(struct ctl_table *table, int write,
  189. void *buffer, size_t *lenp, loff_t *ppos)
  190. {
  191. struct static_key *key = (struct static_key *)table->data;
  192. static int saved_val;
  193. int val, ret;
  194. struct ctl_table tmp = {
  195. .data = &val,
  196. .maxlen = sizeof(val),
  197. .mode = table->mode,
  198. .extra1 = SYSCTL_ZERO,
  199. .extra2 = SYSCTL_ONE,
  200. };
  201. if (write && !capable(CAP_SYS_ADMIN))
  202. return -EPERM;
  203. mutex_lock(&bpf_stats_enabled_mutex);
  204. val = saved_val;
  205. ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
  206. if (write && !ret && val != saved_val) {
  207. if (val)
  208. static_key_slow_inc(key);
  209. else
  210. static_key_slow_dec(key);
  211. saved_val = val;
  212. }
  213. mutex_unlock(&bpf_stats_enabled_mutex);
  214. return ret;
  215. }
  216. void __weak unpriv_ebpf_notify(int new_state)
  217. {
  218. }
  219. static int bpf_unpriv_handler(struct ctl_table *table, int write,
  220. void *buffer, size_t *lenp, loff_t *ppos)
  221. {
  222. int ret, unpriv_enable = *(int *)table->data;
  223. bool locked_state = unpriv_enable == 1;
  224. struct ctl_table tmp = *table;
  225. if (write && !capable(CAP_SYS_ADMIN))
  226. return -EPERM;
  227. tmp.data = &unpriv_enable;
  228. ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
  229. if (write && !ret) {
  230. if (locked_state && unpriv_enable != 1)
  231. return -EPERM;
  232. *(int *)table->data = unpriv_enable;
  233. }
  234. unpriv_ebpf_notify(unpriv_enable);
  235. return ret;
  236. }
  237. #endif /* CONFIG_BPF_SYSCALL && CONFIG_SYSCTL */
  238. /*
  239. * /proc/sys support
  240. */
  241. #ifdef CONFIG_PROC_SYSCTL
  242. static int _proc_do_string(char *data, int maxlen, int write,
  243. char *buffer, size_t *lenp, loff_t *ppos)
  244. {
  245. size_t len;
  246. char c, *p;
  247. if (!data || !maxlen || !*lenp) {
  248. *lenp = 0;
  249. return 0;
  250. }
  251. if (write) {
  252. if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
  253. /* Only continue writes not past the end of buffer. */
  254. len = strlen(data);
  255. if (len > maxlen - 1)
  256. len = maxlen - 1;
  257. if (*ppos > len)
  258. return 0;
  259. len = *ppos;
  260. } else {
  261. /* Start writing from beginning of buffer. */
  262. len = 0;
  263. }
  264. *ppos += *lenp;
  265. p = buffer;
  266. while ((p - buffer) < *lenp && len < maxlen - 1) {
  267. c = *(p++);
  268. if (c == 0 || c == '\n')
  269. break;
  270. data[len++] = c;
  271. }
  272. data[len] = 0;
  273. } else {
  274. len = strlen(data);
  275. if (len > maxlen)
  276. len = maxlen;
  277. if (*ppos > len) {
  278. *lenp = 0;
  279. return 0;
  280. }
  281. data += *ppos;
  282. len -= *ppos;
  283. if (len > *lenp)
  284. len = *lenp;
  285. if (len)
  286. memcpy(buffer, data, len);
  287. if (len < *lenp) {
  288. buffer[len] = '\n';
  289. len++;
  290. }
  291. *lenp = len;
  292. *ppos += len;
  293. }
  294. return 0;
  295. }
  296. static void warn_sysctl_write(struct ctl_table *table)
  297. {
  298. pr_warn_once("%s wrote to %s when file position was not 0!\n"
  299. "This will not be supported in the future. To silence this\n"
  300. "warning, set kernel.sysctl_writes_strict = -1\n",
  301. current->comm, table->procname);
  302. }
  303. /**
  304. * proc_first_pos_non_zero_ignore - check if first position is allowed
  305. * @ppos: file position
  306. * @table: the sysctl table
  307. *
  308. * Returns true if the first position is non-zero and the sysctl_writes_strict
  309. * mode indicates this is not allowed for numeric input types. String proc
  310. * handlers can ignore the return value.
  311. */
  312. static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
  313. struct ctl_table *table)
  314. {
  315. if (!*ppos)
  316. return false;
  317. switch (sysctl_writes_strict) {
  318. case SYSCTL_WRITES_STRICT:
  319. return true;
  320. case SYSCTL_WRITES_WARN:
  321. warn_sysctl_write(table);
  322. return false;
  323. default:
  324. return false;
  325. }
  326. }
  327. /**
  328. * proc_dostring - read a string sysctl
  329. * @table: the sysctl table
  330. * @write: %TRUE if this is a write to the sysctl file
  331. * @buffer: the user buffer
  332. * @lenp: the size of the user buffer
  333. * @ppos: file position
  334. *
  335. * Reads/writes a string from/to the user buffer. If the kernel
  336. * buffer provided is not large enough to hold the string, the
  337. * string is truncated. The copied string is %NULL-terminated.
  338. * If the string is being read by the user process, it is copied
  339. * and a newline '\n' is added. It is truncated if the buffer is
  340. * not large enough.
  341. *
  342. * Returns 0 on success.
  343. */
  344. int proc_dostring(struct ctl_table *table, int write,
  345. void *buffer, size_t *lenp, loff_t *ppos)
  346. {
  347. if (write)
  348. proc_first_pos_non_zero_ignore(ppos, table);
  349. return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
  350. ppos);
  351. }
  352. static size_t proc_skip_spaces(char **buf)
  353. {
  354. size_t ret;
  355. char *tmp = skip_spaces(*buf);
  356. ret = tmp - *buf;
  357. *buf = tmp;
  358. return ret;
  359. }
  360. static void proc_skip_char(char **buf, size_t *size, const char v)
  361. {
  362. while (*size) {
  363. if (**buf != v)
  364. break;
  365. (*size)--;
  366. (*buf)++;
  367. }
  368. }
  369. /**
  370. * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
  371. * fail on overflow
  372. *
  373. * @cp: kernel buffer containing the string to parse
  374. * @endp: pointer to store the trailing characters
  375. * @base: the base to use
  376. * @res: where the parsed integer will be stored
  377. *
  378. * In case of success 0 is returned and @res will contain the parsed integer,
  379. * @endp will hold any trailing characters.
  380. * This function will fail the parse on overflow. If there wasn't an overflow
  381. * the function will defer the decision what characters count as invalid to the
  382. * caller.
  383. */
  384. static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
  385. unsigned long *res)
  386. {
  387. unsigned long long result;
  388. unsigned int rv;
  389. cp = _parse_integer_fixup_radix(cp, &base);
  390. rv = _parse_integer(cp, base, &result);
  391. if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
  392. return -ERANGE;
  393. cp += rv;
  394. if (endp)
  395. *endp = (char *)cp;
  396. *res = (unsigned long)result;
  397. return 0;
  398. }
  399. #define TMPBUFLEN 22
  400. /**
  401. * proc_get_long - reads an ASCII formatted integer from a user buffer
  402. *
  403. * @buf: a kernel buffer
  404. * @size: size of the kernel buffer
  405. * @val: this is where the number will be stored
  406. * @neg: set to %TRUE if number is negative
  407. * @perm_tr: a vector which contains the allowed trailers
  408. * @perm_tr_len: size of the perm_tr vector
  409. * @tr: pointer to store the trailer character
  410. *
  411. * In case of success %0 is returned and @buf and @size are updated with
  412. * the amount of bytes read. If @tr is non-NULL and a trailing
  413. * character exists (size is non-zero after returning from this
  414. * function), @tr is updated with the trailing character.
  415. */
  416. static int proc_get_long(char **buf, size_t *size,
  417. unsigned long *val, bool *neg,
  418. const char *perm_tr, unsigned perm_tr_len, char *tr)
  419. {
  420. int len;
  421. char *p, tmp[TMPBUFLEN];
  422. if (!*size)
  423. return -EINVAL;
  424. len = *size;
  425. if (len > TMPBUFLEN - 1)
  426. len = TMPBUFLEN - 1;
  427. memcpy(tmp, *buf, len);
  428. tmp[len] = 0;
  429. p = tmp;
  430. if (*p == '-' && *size > 1) {
  431. *neg = true;
  432. p++;
  433. } else
  434. *neg = false;
  435. if (!isdigit(*p))
  436. return -EINVAL;
  437. if (strtoul_lenient(p, &p, 0, val))
  438. return -EINVAL;
  439. len = p - tmp;
  440. /* We don't know if the next char is whitespace thus we may accept
  441. * invalid integers (e.g. 1234...a) or two integers instead of one
  442. * (e.g. 123...1). So lets not allow such large numbers. */
  443. if (len == TMPBUFLEN - 1)
  444. return -EINVAL;
  445. if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
  446. return -EINVAL;
  447. if (tr && (len < *size))
  448. *tr = *p;
  449. *buf += len;
  450. *size -= len;
  451. return 0;
  452. }
  453. /**
  454. * proc_put_long - converts an integer to a decimal ASCII formatted string
  455. *
  456. * @buf: the user buffer
  457. * @size: the size of the user buffer
  458. * @val: the integer to be converted
  459. * @neg: sign of the number, %TRUE for negative
  460. *
  461. * In case of success @buf and @size are updated with the amount of bytes
  462. * written.
  463. */
  464. static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
  465. {
  466. int len;
  467. char tmp[TMPBUFLEN], *p = tmp;
  468. sprintf(p, "%s%lu", neg ? "-" : "", val);
  469. len = strlen(tmp);
  470. if (len > *size)
  471. len = *size;
  472. memcpy(*buf, tmp, len);
  473. *size -= len;
  474. *buf += len;
  475. }
  476. #undef TMPBUFLEN
  477. static void proc_put_char(void **buf, size_t *size, char c)
  478. {
  479. if (*size) {
  480. char **buffer = (char **)buf;
  481. **buffer = c;
  482. (*size)--;
  483. (*buffer)++;
  484. *buf = *buffer;
  485. }
  486. }
  487. static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
  488. int *valp,
  489. int write, void *data)
  490. {
  491. if (write) {
  492. if (*negp) {
  493. if (*lvalp > (unsigned long) INT_MAX + 1)
  494. return -EINVAL;
  495. *valp = -*lvalp;
  496. } else {
  497. if (*lvalp > (unsigned long) INT_MAX)
  498. return -EINVAL;
  499. *valp = *lvalp;
  500. }
  501. } else {
  502. int val = *valp;
  503. if (val < 0) {
  504. *negp = true;
  505. *lvalp = -(unsigned long)val;
  506. } else {
  507. *negp = false;
  508. *lvalp = (unsigned long)val;
  509. }
  510. }
  511. return 0;
  512. }
  513. static int do_proc_douintvec_conv(unsigned long *lvalp,
  514. unsigned int *valp,
  515. int write, void *data)
  516. {
  517. if (write) {
  518. if (*lvalp > UINT_MAX)
  519. return -EINVAL;
  520. *valp = *lvalp;
  521. } else {
  522. unsigned int val = *valp;
  523. *lvalp = (unsigned long)val;
  524. }
  525. return 0;
  526. }
  527. static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
  528. static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
  529. int write, void *buffer,
  530. size_t *lenp, loff_t *ppos,
  531. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  532. int write, void *data),
  533. void *data)
  534. {
  535. int *i, vleft, first = 1, err = 0;
  536. size_t left;
  537. char *p;
  538. if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
  539. *lenp = 0;
  540. return 0;
  541. }
  542. i = (int *) tbl_data;
  543. vleft = table->maxlen / sizeof(*i);
  544. left = *lenp;
  545. if (!conv)
  546. conv = do_proc_dointvec_conv;
  547. if (write) {
  548. if (proc_first_pos_non_zero_ignore(ppos, table))
  549. goto out;
  550. if (left > PAGE_SIZE - 1)
  551. left = PAGE_SIZE - 1;
  552. p = buffer;
  553. }
  554. for (; left && vleft--; i++, first=0) {
  555. unsigned long lval;
  556. bool neg;
  557. if (write) {
  558. left -= proc_skip_spaces(&p);
  559. if (!left)
  560. break;
  561. err = proc_get_long(&p, &left, &lval, &neg,
  562. proc_wspace_sep,
  563. sizeof(proc_wspace_sep), NULL);
  564. if (err)
  565. break;
  566. if (conv(&neg, &lval, i, 1, data)) {
  567. err = -EINVAL;
  568. break;
  569. }
  570. } else {
  571. if (conv(&neg, &lval, i, 0, data)) {
  572. err = -EINVAL;
  573. break;
  574. }
  575. if (!first)
  576. proc_put_char(&buffer, &left, '\t');
  577. proc_put_long(&buffer, &left, lval, neg);
  578. }
  579. }
  580. if (!write && !first && left && !err)
  581. proc_put_char(&buffer, &left, '\n');
  582. if (write && !err && left)
  583. left -= proc_skip_spaces(&p);
  584. if (write && first)
  585. return err ? : -EINVAL;
  586. *lenp -= left;
  587. out:
  588. *ppos += *lenp;
  589. return err;
  590. }
  591. static int do_proc_dointvec(struct ctl_table *table, int write,
  592. void *buffer, size_t *lenp, loff_t *ppos,
  593. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  594. int write, void *data),
  595. void *data)
  596. {
  597. return __do_proc_dointvec(table->data, table, write,
  598. buffer, lenp, ppos, conv, data);
  599. }
  600. static int do_proc_douintvec_w(unsigned int *tbl_data,
  601. struct ctl_table *table,
  602. void *buffer,
  603. size_t *lenp, loff_t *ppos,
  604. int (*conv)(unsigned long *lvalp,
  605. unsigned int *valp,
  606. int write, void *data),
  607. void *data)
  608. {
  609. unsigned long lval;
  610. int err = 0;
  611. size_t left;
  612. bool neg;
  613. char *p = buffer;
  614. left = *lenp;
  615. if (proc_first_pos_non_zero_ignore(ppos, table))
  616. goto bail_early;
  617. if (left > PAGE_SIZE - 1)
  618. left = PAGE_SIZE - 1;
  619. left -= proc_skip_spaces(&p);
  620. if (!left) {
  621. err = -EINVAL;
  622. goto out_free;
  623. }
  624. err = proc_get_long(&p, &left, &lval, &neg,
  625. proc_wspace_sep,
  626. sizeof(proc_wspace_sep), NULL);
  627. if (err || neg) {
  628. err = -EINVAL;
  629. goto out_free;
  630. }
  631. if (conv(&lval, tbl_data, 1, data)) {
  632. err = -EINVAL;
  633. goto out_free;
  634. }
  635. if (!err && left)
  636. left -= proc_skip_spaces(&p);
  637. out_free:
  638. if (err)
  639. return -EINVAL;
  640. return 0;
  641. /* This is in keeping with old __do_proc_dointvec() */
  642. bail_early:
  643. *ppos += *lenp;
  644. return err;
  645. }
  646. static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
  647. size_t *lenp, loff_t *ppos,
  648. int (*conv)(unsigned long *lvalp,
  649. unsigned int *valp,
  650. int write, void *data),
  651. void *data)
  652. {
  653. unsigned long lval;
  654. int err = 0;
  655. size_t left;
  656. left = *lenp;
  657. if (conv(&lval, tbl_data, 0, data)) {
  658. err = -EINVAL;
  659. goto out;
  660. }
  661. proc_put_long(&buffer, &left, lval, false);
  662. if (!left)
  663. goto out;
  664. proc_put_char(&buffer, &left, '\n');
  665. out:
  666. *lenp -= left;
  667. *ppos += *lenp;
  668. return err;
  669. }
  670. static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
  671. int write, void *buffer,
  672. size_t *lenp, loff_t *ppos,
  673. int (*conv)(unsigned long *lvalp,
  674. unsigned int *valp,
  675. int write, void *data),
  676. void *data)
  677. {
  678. unsigned int *i, vleft;
  679. if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
  680. *lenp = 0;
  681. return 0;
  682. }
  683. i = (unsigned int *) tbl_data;
  684. vleft = table->maxlen / sizeof(*i);
  685. /*
  686. * Arrays are not supported, keep this simple. *Do not* add
  687. * support for them.
  688. */
  689. if (vleft != 1) {
  690. *lenp = 0;
  691. return -EINVAL;
  692. }
  693. if (!conv)
  694. conv = do_proc_douintvec_conv;
  695. if (write)
  696. return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
  697. conv, data);
  698. return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
  699. }
  700. static int do_proc_douintvec(struct ctl_table *table, int write,
  701. void *buffer, size_t *lenp, loff_t *ppos,
  702. int (*conv)(unsigned long *lvalp,
  703. unsigned int *valp,
  704. int write, void *data),
  705. void *data)
  706. {
  707. return __do_proc_douintvec(table->data, table, write,
  708. buffer, lenp, ppos, conv, data);
  709. }
  710. /**
  711. * proc_dointvec - read a vector of integers
  712. * @table: the sysctl table
  713. * @write: %TRUE if this is a write to the sysctl file
  714. * @buffer: the user buffer
  715. * @lenp: the size of the user buffer
  716. * @ppos: file position
  717. *
  718. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  719. * values from/to the user buffer, treated as an ASCII string.
  720. *
  721. * Returns 0 on success.
  722. */
  723. int proc_dointvec(struct ctl_table *table, int write, void *buffer,
  724. size_t *lenp, loff_t *ppos)
  725. {
  726. return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
  727. }
  728. #ifdef CONFIG_COMPACTION
  729. static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
  730. int write, void *buffer, size_t *lenp, loff_t *ppos)
  731. {
  732. int ret, old;
  733. if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
  734. return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  735. old = *(int *)table->data;
  736. ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  737. if (ret)
  738. return ret;
  739. if (old != *(int *)table->data)
  740. pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
  741. table->procname, current->comm,
  742. task_pid_nr(current));
  743. return ret;
  744. }
  745. #endif
  746. /**
  747. * proc_douintvec - read a vector of unsigned integers
  748. * @table: the sysctl table
  749. * @write: %TRUE if this is a write to the sysctl file
  750. * @buffer: the user buffer
  751. * @lenp: the size of the user buffer
  752. * @ppos: file position
  753. *
  754. * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
  755. * values from/to the user buffer, treated as an ASCII string.
  756. *
  757. * Returns 0 on success.
  758. */
  759. int proc_douintvec(struct ctl_table *table, int write, void *buffer,
  760. size_t *lenp, loff_t *ppos)
  761. {
  762. return do_proc_douintvec(table, write, buffer, lenp, ppos,
  763. do_proc_douintvec_conv, NULL);
  764. }
  765. /*
  766. * Taint values can only be increased
  767. * This means we can safely use a temporary.
  768. */
  769. static int proc_taint(struct ctl_table *table, int write,
  770. void *buffer, size_t *lenp, loff_t *ppos)
  771. {
  772. struct ctl_table t;
  773. unsigned long tmptaint = get_taint();
  774. int err;
  775. if (write && !capable(CAP_SYS_ADMIN))
  776. return -EPERM;
  777. t = *table;
  778. t.data = &tmptaint;
  779. err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
  780. if (err < 0)
  781. return err;
  782. if (write) {
  783. int i;
  784. /*
  785. * If we are relying on panic_on_taint not producing
  786. * false positives due to userspace input, bail out
  787. * before setting the requested taint flags.
  788. */
  789. if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
  790. return -EINVAL;
  791. /*
  792. * Poor man's atomic or. Not worth adding a primitive
  793. * to everyone's atomic.h for this
  794. */
  795. for (i = 0; i < TAINT_FLAGS_COUNT; i++)
  796. if ((1UL << i) & tmptaint)
  797. add_taint(i, LOCKDEP_STILL_OK);
  798. }
  799. return err;
  800. }
  801. #ifdef CONFIG_PRINTK
  802. static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
  803. void *buffer, size_t *lenp, loff_t *ppos)
  804. {
  805. if (write && !capable(CAP_SYS_ADMIN))
  806. return -EPERM;
  807. return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  808. }
  809. #endif
  810. /**
  811. * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
  812. * @min: pointer to minimum allowable value
  813. * @max: pointer to maximum allowable value
  814. *
  815. * The do_proc_dointvec_minmax_conv_param structure provides the
  816. * minimum and maximum values for doing range checking for those sysctl
  817. * parameters that use the proc_dointvec_minmax() handler.
  818. */
  819. struct do_proc_dointvec_minmax_conv_param {
  820. int *min;
  821. int *max;
  822. };
  823. static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
  824. int *valp,
  825. int write, void *data)
  826. {
  827. int tmp, ret;
  828. struct do_proc_dointvec_minmax_conv_param *param = data;
  829. /*
  830. * If writing, first do so via a temporary local int so we can
  831. * bounds-check it before touching *valp.
  832. */
  833. int *ip = write ? &tmp : valp;
  834. ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
  835. if (ret)
  836. return ret;
  837. if (write) {
  838. if ((param->min && *param->min > tmp) ||
  839. (param->max && *param->max < tmp))
  840. return -EINVAL;
  841. *valp = tmp;
  842. }
  843. return 0;
  844. }
  845. /**
  846. * proc_dointvec_minmax - read a vector of integers with min/max values
  847. * @table: the sysctl table
  848. * @write: %TRUE if this is a write to the sysctl file
  849. * @buffer: the user buffer
  850. * @lenp: the size of the user buffer
  851. * @ppos: file position
  852. *
  853. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  854. * values from/to the user buffer, treated as an ASCII string.
  855. *
  856. * This routine will ensure the values are within the range specified by
  857. * table->extra1 (min) and table->extra2 (max).
  858. *
  859. * Returns 0 on success or -EINVAL on write when the range check fails.
  860. */
  861. int proc_dointvec_minmax(struct ctl_table *table, int write,
  862. void *buffer, size_t *lenp, loff_t *ppos)
  863. {
  864. struct do_proc_dointvec_minmax_conv_param param = {
  865. .min = (int *) table->extra1,
  866. .max = (int *) table->extra2,
  867. };
  868. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  869. do_proc_dointvec_minmax_conv, &param);
  870. }
  871. /**
  872. * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
  873. * @min: pointer to minimum allowable value
  874. * @max: pointer to maximum allowable value
  875. *
  876. * The do_proc_douintvec_minmax_conv_param structure provides the
  877. * minimum and maximum values for doing range checking for those sysctl
  878. * parameters that use the proc_douintvec_minmax() handler.
  879. */
  880. struct do_proc_douintvec_minmax_conv_param {
  881. unsigned int *min;
  882. unsigned int *max;
  883. };
  884. static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
  885. unsigned int *valp,
  886. int write, void *data)
  887. {
  888. int ret;
  889. unsigned int tmp;
  890. struct do_proc_douintvec_minmax_conv_param *param = data;
  891. /* write via temporary local uint for bounds-checking */
  892. unsigned int *up = write ? &tmp : valp;
  893. ret = do_proc_douintvec_conv(lvalp, up, write, data);
  894. if (ret)
  895. return ret;
  896. if (write) {
  897. if ((param->min && *param->min > tmp) ||
  898. (param->max && *param->max < tmp))
  899. return -ERANGE;
  900. *valp = tmp;
  901. }
  902. return 0;
  903. }
  904. /**
  905. * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
  906. * @table: the sysctl table
  907. * @write: %TRUE if this is a write to the sysctl file
  908. * @buffer: the user buffer
  909. * @lenp: the size of the user buffer
  910. * @ppos: file position
  911. *
  912. * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
  913. * values from/to the user buffer, treated as an ASCII string. Negative
  914. * strings are not allowed.
  915. *
  916. * This routine will ensure the values are within the range specified by
  917. * table->extra1 (min) and table->extra2 (max). There is a final sanity
  918. * check for UINT_MAX to avoid having to support wrap around uses from
  919. * userspace.
  920. *
  921. * Returns 0 on success or -ERANGE on write when the range check fails.
  922. */
  923. int proc_douintvec_minmax(struct ctl_table *table, int write,
  924. void *buffer, size_t *lenp, loff_t *ppos)
  925. {
  926. struct do_proc_douintvec_minmax_conv_param param = {
  927. .min = (unsigned int *) table->extra1,
  928. .max = (unsigned int *) table->extra2,
  929. };
  930. return do_proc_douintvec(table, write, buffer, lenp, ppos,
  931. do_proc_douintvec_minmax_conv, &param);
  932. }
  933. static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
  934. unsigned int *valp,
  935. int write, void *data)
  936. {
  937. if (write) {
  938. unsigned int val;
  939. val = round_pipe_size(*lvalp);
  940. if (val == 0)
  941. return -EINVAL;
  942. *valp = val;
  943. } else {
  944. unsigned int val = *valp;
  945. *lvalp = (unsigned long) val;
  946. }
  947. return 0;
  948. }
  949. static int proc_dopipe_max_size(struct ctl_table *table, int write,
  950. void *buffer, size_t *lenp, loff_t *ppos)
  951. {
  952. return do_proc_douintvec(table, write, buffer, lenp, ppos,
  953. do_proc_dopipe_max_size_conv, NULL);
  954. }
  955. static void validate_coredump_safety(void)
  956. {
  957. #ifdef CONFIG_COREDUMP
  958. if (suid_dumpable == SUID_DUMP_ROOT &&
  959. core_pattern[0] != '/' && core_pattern[0] != '|') {
  960. printk(KERN_WARNING
  961. "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
  962. "Pipe handler or fully qualified core dump path required.\n"
  963. "Set kernel.core_pattern before fs.suid_dumpable.\n"
  964. );
  965. }
  966. #endif
  967. }
  968. static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
  969. void *buffer, size_t *lenp, loff_t *ppos)
  970. {
  971. int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  972. if (!error)
  973. validate_coredump_safety();
  974. return error;
  975. }
  976. #ifdef CONFIG_COREDUMP
  977. static int proc_dostring_coredump(struct ctl_table *table, int write,
  978. void *buffer, size_t *lenp, loff_t *ppos)
  979. {
  980. int error = proc_dostring(table, write, buffer, lenp, ppos);
  981. if (!error)
  982. validate_coredump_safety();
  983. return error;
  984. }
  985. #endif
  986. #ifdef CONFIG_MAGIC_SYSRQ
  987. static int sysrq_sysctl_handler(struct ctl_table *table, int write,
  988. void *buffer, size_t *lenp, loff_t *ppos)
  989. {
  990. int tmp, ret;
  991. tmp = sysrq_mask();
  992. ret = __do_proc_dointvec(&tmp, table, write, buffer,
  993. lenp, ppos, NULL, NULL);
  994. if (ret || !write)
  995. return ret;
  996. if (write)
  997. sysrq_toggle_support(tmp);
  998. return 0;
  999. }
  1000. #endif
  1001. static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
  1002. int write, void *buffer, size_t *lenp, loff_t *ppos,
  1003. unsigned long convmul, unsigned long convdiv)
  1004. {
  1005. unsigned long *i, *min, *max;
  1006. int vleft, first = 1, err = 0;
  1007. size_t left;
  1008. char *p;
  1009. if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
  1010. *lenp = 0;
  1011. return 0;
  1012. }
  1013. i = (unsigned long *) data;
  1014. min = (unsigned long *) table->extra1;
  1015. max = (unsigned long *) table->extra2;
  1016. vleft = table->maxlen / sizeof(unsigned long);
  1017. left = *lenp;
  1018. if (write) {
  1019. if (proc_first_pos_non_zero_ignore(ppos, table))
  1020. goto out;
  1021. if (left > PAGE_SIZE - 1)
  1022. left = PAGE_SIZE - 1;
  1023. p = buffer;
  1024. }
  1025. for (; left && vleft--; i++, first = 0) {
  1026. unsigned long val;
  1027. if (write) {
  1028. bool neg;
  1029. left -= proc_skip_spaces(&p);
  1030. if (!left)
  1031. break;
  1032. err = proc_get_long(&p, &left, &val, &neg,
  1033. proc_wspace_sep,
  1034. sizeof(proc_wspace_sep), NULL);
  1035. if (err)
  1036. break;
  1037. if (neg)
  1038. continue;
  1039. val = convmul * val / convdiv;
  1040. if ((min && val < *min) || (max && val > *max)) {
  1041. err = -EINVAL;
  1042. break;
  1043. }
  1044. *i = val;
  1045. } else {
  1046. val = convdiv * (*i) / convmul;
  1047. if (!first)
  1048. proc_put_char(&buffer, &left, '\t');
  1049. proc_put_long(&buffer, &left, val, false);
  1050. }
  1051. }
  1052. if (!write && !first && left && !err)
  1053. proc_put_char(&buffer, &left, '\n');
  1054. if (write && !err)
  1055. left -= proc_skip_spaces(&p);
  1056. if (write && first)
  1057. return err ? : -EINVAL;
  1058. *lenp -= left;
  1059. out:
  1060. *ppos += *lenp;
  1061. return err;
  1062. }
  1063. static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
  1064. void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
  1065. unsigned long convdiv)
  1066. {
  1067. return __do_proc_doulongvec_minmax(table->data, table, write,
  1068. buffer, lenp, ppos, convmul, convdiv);
  1069. }
  1070. /**
  1071. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  1072. * @table: the sysctl table
  1073. * @write: %TRUE if this is a write to the sysctl file
  1074. * @buffer: the user buffer
  1075. * @lenp: the size of the user buffer
  1076. * @ppos: file position
  1077. *
  1078. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1079. * values from/to the user buffer, treated as an ASCII string.
  1080. *
  1081. * This routine will ensure the values are within the range specified by
  1082. * table->extra1 (min) and table->extra2 (max).
  1083. *
  1084. * Returns 0 on success.
  1085. */
  1086. int proc_doulongvec_minmax(struct ctl_table *table, int write,
  1087. void *buffer, size_t *lenp, loff_t *ppos)
  1088. {
  1089. return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
  1090. }
  1091. /**
  1092. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  1093. * @table: the sysctl table
  1094. * @write: %TRUE if this is a write to the sysctl file
  1095. * @buffer: the user buffer
  1096. * @lenp: the size of the user buffer
  1097. * @ppos: file position
  1098. *
  1099. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1100. * values from/to the user buffer, treated as an ASCII string. The values
  1101. * are treated as milliseconds, and converted to jiffies when they are stored.
  1102. *
  1103. * This routine will ensure the values are within the range specified by
  1104. * table->extra1 (min) and table->extra2 (max).
  1105. *
  1106. * Returns 0 on success.
  1107. */
  1108. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  1109. void *buffer, size_t *lenp, loff_t *ppos)
  1110. {
  1111. return do_proc_doulongvec_minmax(table, write, buffer,
  1112. lenp, ppos, HZ, 1000l);
  1113. }
  1114. static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
  1115. int *valp,
  1116. int write, void *data)
  1117. {
  1118. if (write) {
  1119. if (*lvalp > INT_MAX / HZ)
  1120. return 1;
  1121. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  1122. } else {
  1123. int val = *valp;
  1124. unsigned long lval;
  1125. if (val < 0) {
  1126. *negp = true;
  1127. lval = -(unsigned long)val;
  1128. } else {
  1129. *negp = false;
  1130. lval = (unsigned long)val;
  1131. }
  1132. *lvalp = lval / HZ;
  1133. }
  1134. return 0;
  1135. }
  1136. static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
  1137. int *valp,
  1138. int write, void *data)
  1139. {
  1140. if (write) {
  1141. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  1142. return 1;
  1143. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  1144. } else {
  1145. int val = *valp;
  1146. unsigned long lval;
  1147. if (val < 0) {
  1148. *negp = true;
  1149. lval = -(unsigned long)val;
  1150. } else {
  1151. *negp = false;
  1152. lval = (unsigned long)val;
  1153. }
  1154. *lvalp = jiffies_to_clock_t(lval);
  1155. }
  1156. return 0;
  1157. }
  1158. static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
  1159. int *valp,
  1160. int write, void *data)
  1161. {
  1162. if (write) {
  1163. unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  1164. if (jif > INT_MAX)
  1165. return 1;
  1166. *valp = (int)jif;
  1167. } else {
  1168. int val = *valp;
  1169. unsigned long lval;
  1170. if (val < 0) {
  1171. *negp = true;
  1172. lval = -(unsigned long)val;
  1173. } else {
  1174. *negp = false;
  1175. lval = (unsigned long)val;
  1176. }
  1177. *lvalp = jiffies_to_msecs(lval);
  1178. }
  1179. return 0;
  1180. }
  1181. /**
  1182. * proc_dointvec_jiffies - read a vector of integers as seconds
  1183. * @table: the sysctl table
  1184. * @write: %TRUE if this is a write to the sysctl file
  1185. * @buffer: the user buffer
  1186. * @lenp: the size of the user buffer
  1187. * @ppos: file position
  1188. *
  1189. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1190. * values from/to the user buffer, treated as an ASCII string.
  1191. * The values read are assumed to be in seconds, and are converted into
  1192. * jiffies.
  1193. *
  1194. * Returns 0 on success.
  1195. */
  1196. int proc_dointvec_jiffies(struct ctl_table *table, int write,
  1197. void *buffer, size_t *lenp, loff_t *ppos)
  1198. {
  1199. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  1200. do_proc_dointvec_jiffies_conv,NULL);
  1201. }
  1202. /**
  1203. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  1204. * @table: the sysctl table
  1205. * @write: %TRUE if this is a write to the sysctl file
  1206. * @buffer: the user buffer
  1207. * @lenp: the size of the user buffer
  1208. * @ppos: pointer to the file position
  1209. *
  1210. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1211. * values from/to the user buffer, treated as an ASCII string.
  1212. * The values read are assumed to be in 1/USER_HZ seconds, and
  1213. * are converted into jiffies.
  1214. *
  1215. * Returns 0 on success.
  1216. */
  1217. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
  1218. void *buffer, size_t *lenp, loff_t *ppos)
  1219. {
  1220. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  1221. do_proc_dointvec_userhz_jiffies_conv,NULL);
  1222. }
  1223. /**
  1224. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  1225. * @table: the sysctl table
  1226. * @write: %TRUE if this is a write to the sysctl file
  1227. * @buffer: the user buffer
  1228. * @lenp: the size of the user buffer
  1229. * @ppos: file position
  1230. * @ppos: the current position in the file
  1231. *
  1232. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1233. * values from/to the user buffer, treated as an ASCII string.
  1234. * The values read are assumed to be in 1/1000 seconds, and
  1235. * are converted into jiffies.
  1236. *
  1237. * Returns 0 on success.
  1238. */
  1239. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
  1240. size_t *lenp, loff_t *ppos)
  1241. {
  1242. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  1243. do_proc_dointvec_ms_jiffies_conv, NULL);
  1244. }
  1245. static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
  1246. size_t *lenp, loff_t *ppos)
  1247. {
  1248. struct pid *new_pid;
  1249. pid_t tmp;
  1250. int r;
  1251. tmp = pid_vnr(cad_pid);
  1252. r = __do_proc_dointvec(&tmp, table, write, buffer,
  1253. lenp, ppos, NULL, NULL);
  1254. if (r || !write)
  1255. return r;
  1256. new_pid = find_get_pid(tmp);
  1257. if (!new_pid)
  1258. return -ESRCH;
  1259. put_pid(xchg(&cad_pid, new_pid));
  1260. return 0;
  1261. }
  1262. /**
  1263. * proc_do_large_bitmap - read/write from/to a large bitmap
  1264. * @table: the sysctl table
  1265. * @write: %TRUE if this is a write to the sysctl file
  1266. * @buffer: the user buffer
  1267. * @lenp: the size of the user buffer
  1268. * @ppos: file position
  1269. *
  1270. * The bitmap is stored at table->data and the bitmap length (in bits)
  1271. * in table->maxlen.
  1272. *
  1273. * We use a range comma separated format (e.g. 1,3-4,10-10) so that
  1274. * large bitmaps may be represented in a compact manner. Writing into
  1275. * the file will clear the bitmap then update it with the given input.
  1276. *
  1277. * Returns 0 on success.
  1278. */
  1279. int proc_do_large_bitmap(struct ctl_table *table, int write,
  1280. void *buffer, size_t *lenp, loff_t *ppos)
  1281. {
  1282. int err = 0;
  1283. bool first = 1;
  1284. size_t left = *lenp;
  1285. unsigned long bitmap_len = table->maxlen;
  1286. unsigned long *bitmap = *(unsigned long **) table->data;
  1287. unsigned long *tmp_bitmap = NULL;
  1288. char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
  1289. if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
  1290. *lenp = 0;
  1291. return 0;
  1292. }
  1293. if (write) {
  1294. char *p = buffer;
  1295. size_t skipped = 0;
  1296. if (left > PAGE_SIZE - 1) {
  1297. left = PAGE_SIZE - 1;
  1298. /* How much of the buffer we'll skip this pass */
  1299. skipped = *lenp - left;
  1300. }
  1301. tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
  1302. if (!tmp_bitmap)
  1303. return -ENOMEM;
  1304. proc_skip_char(&p, &left, '\n');
  1305. while (!err && left) {
  1306. unsigned long val_a, val_b;
  1307. bool neg;
  1308. size_t saved_left;
  1309. /* In case we stop parsing mid-number, we can reset */
  1310. saved_left = left;
  1311. err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
  1312. sizeof(tr_a), &c);
  1313. /*
  1314. * If we consumed the entirety of a truncated buffer or
  1315. * only one char is left (may be a "-"), then stop here,
  1316. * reset, & come back for more.
  1317. */
  1318. if ((left <= 1) && skipped) {
  1319. left = saved_left;
  1320. break;
  1321. }
  1322. if (err)
  1323. break;
  1324. if (val_a >= bitmap_len || neg) {
  1325. err = -EINVAL;
  1326. break;
  1327. }
  1328. val_b = val_a;
  1329. if (left) {
  1330. p++;
  1331. left--;
  1332. }
  1333. if (c == '-') {
  1334. err = proc_get_long(&p, &left, &val_b,
  1335. &neg, tr_b, sizeof(tr_b),
  1336. &c);
  1337. /*
  1338. * If we consumed all of a truncated buffer or
  1339. * then stop here, reset, & come back for more.
  1340. */
  1341. if (!left && skipped) {
  1342. left = saved_left;
  1343. break;
  1344. }
  1345. if (err)
  1346. break;
  1347. if (val_b >= bitmap_len || neg ||
  1348. val_a > val_b) {
  1349. err = -EINVAL;
  1350. break;
  1351. }
  1352. if (left) {
  1353. p++;
  1354. left--;
  1355. }
  1356. }
  1357. bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
  1358. first = 0;
  1359. proc_skip_char(&p, &left, '\n');
  1360. }
  1361. left += skipped;
  1362. } else {
  1363. unsigned long bit_a, bit_b = 0;
  1364. while (left) {
  1365. bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
  1366. if (bit_a >= bitmap_len)
  1367. break;
  1368. bit_b = find_next_zero_bit(bitmap, bitmap_len,
  1369. bit_a + 1) - 1;
  1370. if (!first)
  1371. proc_put_char(&buffer, &left, ',');
  1372. proc_put_long(&buffer, &left, bit_a, false);
  1373. if (bit_a != bit_b) {
  1374. proc_put_char(&buffer, &left, '-');
  1375. proc_put_long(&buffer, &left, bit_b, false);
  1376. }
  1377. first = 0; bit_b++;
  1378. }
  1379. proc_put_char(&buffer, &left, '\n');
  1380. }
  1381. if (!err) {
  1382. if (write) {
  1383. if (*ppos)
  1384. bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
  1385. else
  1386. bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
  1387. }
  1388. *lenp -= left;
  1389. *ppos += *lenp;
  1390. }
  1391. bitmap_free(tmp_bitmap);
  1392. return err;
  1393. }
  1394. #else /* CONFIG_PROC_SYSCTL */
  1395. int proc_dostring(struct ctl_table *table, int write,
  1396. void *buffer, size_t *lenp, loff_t *ppos)
  1397. {
  1398. return -ENOSYS;
  1399. }
  1400. int proc_dointvec(struct ctl_table *table, int write,
  1401. void *buffer, size_t *lenp, loff_t *ppos)
  1402. {
  1403. return -ENOSYS;
  1404. }
  1405. int proc_douintvec(struct ctl_table *table, int write,
  1406. void *buffer, size_t *lenp, loff_t *ppos)
  1407. {
  1408. return -ENOSYS;
  1409. }
  1410. int proc_dointvec_minmax(struct ctl_table *table, int write,
  1411. void *buffer, size_t *lenp, loff_t *ppos)
  1412. {
  1413. return -ENOSYS;
  1414. }
  1415. int proc_douintvec_minmax(struct ctl_table *table, int write,
  1416. void *buffer, size_t *lenp, loff_t *ppos)
  1417. {
  1418. return -ENOSYS;
  1419. }
  1420. int proc_dointvec_jiffies(struct ctl_table *table, int write,
  1421. void *buffer, size_t *lenp, loff_t *ppos)
  1422. {
  1423. return -ENOSYS;
  1424. }
  1425. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
  1426. void *buffer, size_t *lenp, loff_t *ppos)
  1427. {
  1428. return -ENOSYS;
  1429. }
  1430. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
  1431. void *buffer, size_t *lenp, loff_t *ppos)
  1432. {
  1433. return -ENOSYS;
  1434. }
  1435. int proc_doulongvec_minmax(struct ctl_table *table, int write,
  1436. void *buffer, size_t *lenp, loff_t *ppos)
  1437. {
  1438. return -ENOSYS;
  1439. }
  1440. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  1441. void *buffer, size_t *lenp, loff_t *ppos)
  1442. {
  1443. return -ENOSYS;
  1444. }
  1445. int proc_do_large_bitmap(struct ctl_table *table, int write,
  1446. void *buffer, size_t *lenp, loff_t *ppos)
  1447. {
  1448. return -ENOSYS;
  1449. }
  1450. #endif /* CONFIG_PROC_SYSCTL */
  1451. #if defined(CONFIG_SYSCTL)
  1452. int proc_do_static_key(struct ctl_table *table, int write,
  1453. void *buffer, size_t *lenp, loff_t *ppos)
  1454. {
  1455. struct static_key *key = (struct static_key *)table->data;
  1456. static DEFINE_MUTEX(static_key_mutex);
  1457. int val, ret;
  1458. struct ctl_table tmp = {
  1459. .data = &val,
  1460. .maxlen = sizeof(val),
  1461. .mode = table->mode,
  1462. .extra1 = SYSCTL_ZERO,
  1463. .extra2 = SYSCTL_ONE,
  1464. };
  1465. if (write && !capable(CAP_SYS_ADMIN))
  1466. return -EPERM;
  1467. mutex_lock(&static_key_mutex);
  1468. val = static_key_enabled(key);
  1469. ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
  1470. if (write && !ret) {
  1471. if (val)
  1472. static_key_enable(key);
  1473. else
  1474. static_key_disable(key);
  1475. }
  1476. mutex_unlock(&static_key_mutex);
  1477. return ret;
  1478. }
  1479. static struct ctl_table kern_table[] = {
  1480. {
  1481. .procname = "sched_child_runs_first",
  1482. .data = &sysctl_sched_child_runs_first,
  1483. .maxlen = sizeof(unsigned int),
  1484. .mode = 0644,
  1485. .proc_handler = proc_dointvec,
  1486. },
  1487. #ifdef CONFIG_SCHED_DEBUG
  1488. {
  1489. .procname = "sched_min_granularity_ns",
  1490. .data = &sysctl_sched_min_granularity,
  1491. .maxlen = sizeof(unsigned int),
  1492. .mode = 0644,
  1493. .proc_handler = sched_proc_update_handler,
  1494. .extra1 = &min_sched_granularity_ns,
  1495. .extra2 = &max_sched_granularity_ns,
  1496. },
  1497. {
  1498. .procname = "sched_latency_ns",
  1499. .data = &sysctl_sched_latency,
  1500. .maxlen = sizeof(unsigned int),
  1501. .mode = 0644,
  1502. .proc_handler = sched_proc_update_handler,
  1503. .extra1 = &min_sched_granularity_ns,
  1504. .extra2 = &max_sched_granularity_ns,
  1505. },
  1506. {
  1507. .procname = "sched_wakeup_granularity_ns",
  1508. .data = &sysctl_sched_wakeup_granularity,
  1509. .maxlen = sizeof(unsigned int),
  1510. .mode = 0644,
  1511. .proc_handler = sched_proc_update_handler,
  1512. .extra1 = &min_wakeup_granularity_ns,
  1513. .extra2 = &max_wakeup_granularity_ns,
  1514. },
  1515. #ifdef CONFIG_SMP
  1516. {
  1517. .procname = "sched_tunable_scaling",
  1518. .data = &sysctl_sched_tunable_scaling,
  1519. .maxlen = sizeof(enum sched_tunable_scaling),
  1520. .mode = 0644,
  1521. .proc_handler = sched_proc_update_handler,
  1522. .extra1 = &min_sched_tunable_scaling,
  1523. .extra2 = &max_sched_tunable_scaling,
  1524. },
  1525. {
  1526. .procname = "sched_migration_cost_ns",
  1527. .data = &sysctl_sched_migration_cost,
  1528. .maxlen = sizeof(unsigned int),
  1529. .mode = 0644,
  1530. .proc_handler = proc_dointvec,
  1531. },
  1532. {
  1533. .procname = "sched_nr_migrate",
  1534. .data = &sysctl_sched_nr_migrate,
  1535. .maxlen = sizeof(unsigned int),
  1536. .mode = 0644,
  1537. .proc_handler = proc_dointvec,
  1538. },
  1539. #ifdef CONFIG_SCHEDSTATS
  1540. {
  1541. .procname = "sched_schedstats",
  1542. .data = NULL,
  1543. .maxlen = sizeof(unsigned int),
  1544. .mode = 0644,
  1545. .proc_handler = sysctl_schedstats,
  1546. .extra1 = SYSCTL_ZERO,
  1547. .extra2 = SYSCTL_ONE,
  1548. },
  1549. #endif /* CONFIG_SCHEDSTATS */
  1550. #endif /* CONFIG_SMP */
  1551. #ifdef CONFIG_NUMA_BALANCING
  1552. {
  1553. .procname = "numa_balancing_scan_delay_ms",
  1554. .data = &sysctl_numa_balancing_scan_delay,
  1555. .maxlen = sizeof(unsigned int),
  1556. .mode = 0644,
  1557. .proc_handler = proc_dointvec,
  1558. },
  1559. {
  1560. .procname = "numa_balancing_scan_period_min_ms",
  1561. .data = &sysctl_numa_balancing_scan_period_min,
  1562. .maxlen = sizeof(unsigned int),
  1563. .mode = 0644,
  1564. .proc_handler = proc_dointvec,
  1565. },
  1566. {
  1567. .procname = "numa_balancing_scan_period_max_ms",
  1568. .data = &sysctl_numa_balancing_scan_period_max,
  1569. .maxlen = sizeof(unsigned int),
  1570. .mode = 0644,
  1571. .proc_handler = proc_dointvec,
  1572. },
  1573. {
  1574. .procname = "numa_balancing_scan_size_mb",
  1575. .data = &sysctl_numa_balancing_scan_size,
  1576. .maxlen = sizeof(unsigned int),
  1577. .mode = 0644,
  1578. .proc_handler = proc_dointvec_minmax,
  1579. .extra1 = SYSCTL_ONE,
  1580. },
  1581. {
  1582. .procname = "numa_balancing",
  1583. .data = NULL, /* filled in by handler */
  1584. .maxlen = sizeof(unsigned int),
  1585. .mode = 0644,
  1586. .proc_handler = sysctl_numa_balancing,
  1587. .extra1 = SYSCTL_ZERO,
  1588. .extra2 = SYSCTL_ONE,
  1589. },
  1590. #endif /* CONFIG_NUMA_BALANCING */
  1591. #endif /* CONFIG_SCHED_DEBUG */
  1592. {
  1593. .procname = "sched_rt_period_us",
  1594. .data = &sysctl_sched_rt_period,
  1595. .maxlen = sizeof(unsigned int),
  1596. .mode = 0644,
  1597. .proc_handler = sched_rt_handler,
  1598. },
  1599. {
  1600. .procname = "sched_rt_runtime_us",
  1601. .data = &sysctl_sched_rt_runtime,
  1602. .maxlen = sizeof(int),
  1603. .mode = 0644,
  1604. .proc_handler = sched_rt_handler,
  1605. },
  1606. {
  1607. .procname = "sched_deadline_period_max_us",
  1608. .data = &sysctl_sched_dl_period_max,
  1609. .maxlen = sizeof(unsigned int),
  1610. .mode = 0644,
  1611. .proc_handler = proc_dointvec,
  1612. },
  1613. {
  1614. .procname = "sched_deadline_period_min_us",
  1615. .data = &sysctl_sched_dl_period_min,
  1616. .maxlen = sizeof(unsigned int),
  1617. .mode = 0644,
  1618. .proc_handler = proc_dointvec,
  1619. },
  1620. {
  1621. .procname = "sched_rr_timeslice_ms",
  1622. .data = &sysctl_sched_rr_timeslice,
  1623. .maxlen = sizeof(int),
  1624. .mode = 0644,
  1625. .proc_handler = sched_rr_handler,
  1626. },
  1627. #ifdef CONFIG_UCLAMP_TASK
  1628. {
  1629. .procname = "sched_util_clamp_min",
  1630. .data = &sysctl_sched_uclamp_util_min,
  1631. .maxlen = sizeof(unsigned int),
  1632. .mode = 0644,
  1633. .proc_handler = sysctl_sched_uclamp_handler,
  1634. },
  1635. {
  1636. .procname = "sched_util_clamp_max",
  1637. .data = &sysctl_sched_uclamp_util_max,
  1638. .maxlen = sizeof(unsigned int),
  1639. .mode = 0644,
  1640. .proc_handler = sysctl_sched_uclamp_handler,
  1641. },
  1642. {
  1643. .procname = "sched_util_clamp_min_rt_default",
  1644. .data = &sysctl_sched_uclamp_util_min_rt_default,
  1645. .maxlen = sizeof(unsigned int),
  1646. .mode = 0644,
  1647. .proc_handler = sysctl_sched_uclamp_handler,
  1648. },
  1649. #endif
  1650. #ifdef CONFIG_SCHED_AUTOGROUP
  1651. {
  1652. .procname = "sched_autogroup_enabled",
  1653. .data = &sysctl_sched_autogroup_enabled,
  1654. .maxlen = sizeof(unsigned int),
  1655. .mode = 0644,
  1656. .proc_handler = proc_dointvec_minmax,
  1657. .extra1 = SYSCTL_ZERO,
  1658. .extra2 = SYSCTL_ONE,
  1659. },
  1660. #endif
  1661. #ifdef CONFIG_CFS_BANDWIDTH
  1662. {
  1663. .procname = "sched_cfs_bandwidth_slice_us",
  1664. .data = &sysctl_sched_cfs_bandwidth_slice,
  1665. .maxlen = sizeof(unsigned int),
  1666. .mode = 0644,
  1667. .proc_handler = proc_dointvec_minmax,
  1668. .extra1 = SYSCTL_ONE,
  1669. },
  1670. #endif
  1671. #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
  1672. {
  1673. .procname = "sched_energy_aware",
  1674. .data = &sysctl_sched_energy_aware,
  1675. .maxlen = sizeof(unsigned int),
  1676. .mode = 0644,
  1677. .proc_handler = sched_energy_aware_handler,
  1678. .extra1 = SYSCTL_ZERO,
  1679. .extra2 = SYSCTL_ONE,
  1680. },
  1681. #endif
  1682. #ifdef CONFIG_PROVE_LOCKING
  1683. {
  1684. .procname = "prove_locking",
  1685. .data = &prove_locking,
  1686. .maxlen = sizeof(int),
  1687. .mode = 0644,
  1688. .proc_handler = proc_dointvec,
  1689. },
  1690. #endif
  1691. #ifdef CONFIG_LOCK_STAT
  1692. {
  1693. .procname = "lock_stat",
  1694. .data = &lock_stat,
  1695. .maxlen = sizeof(int),
  1696. .mode = 0644,
  1697. .proc_handler = proc_dointvec,
  1698. },
  1699. #endif
  1700. {
  1701. .procname = "panic",
  1702. .data = &panic_timeout,
  1703. .maxlen = sizeof(int),
  1704. .mode = 0644,
  1705. .proc_handler = proc_dointvec,
  1706. },
  1707. #ifdef CONFIG_COREDUMP
  1708. {
  1709. .procname = "core_uses_pid",
  1710. .data = &core_uses_pid,
  1711. .maxlen = sizeof(int),
  1712. .mode = 0644,
  1713. .proc_handler = proc_dointvec,
  1714. },
  1715. {
  1716. .procname = "core_pattern",
  1717. .data = core_pattern,
  1718. .maxlen = CORENAME_MAX_SIZE,
  1719. .mode = 0644,
  1720. .proc_handler = proc_dostring_coredump,
  1721. },
  1722. {
  1723. .procname = "core_pipe_limit",
  1724. .data = &core_pipe_limit,
  1725. .maxlen = sizeof(unsigned int),
  1726. .mode = 0644,
  1727. .proc_handler = proc_dointvec,
  1728. },
  1729. #endif
  1730. #ifdef CONFIG_PROC_SYSCTL
  1731. {
  1732. .procname = "tainted",
  1733. .maxlen = sizeof(long),
  1734. .mode = 0644,
  1735. .proc_handler = proc_taint,
  1736. },
  1737. {
  1738. .procname = "sysctl_writes_strict",
  1739. .data = &sysctl_writes_strict,
  1740. .maxlen = sizeof(int),
  1741. .mode = 0644,
  1742. .proc_handler = proc_dointvec_minmax,
  1743. .extra1 = &neg_one,
  1744. .extra2 = SYSCTL_ONE,
  1745. },
  1746. #endif
  1747. #ifdef CONFIG_LATENCYTOP
  1748. {
  1749. .procname = "latencytop",
  1750. .data = &latencytop_enabled,
  1751. .maxlen = sizeof(int),
  1752. .mode = 0644,
  1753. .proc_handler = sysctl_latencytop,
  1754. },
  1755. #endif
  1756. #ifdef CONFIG_BLK_DEV_INITRD
  1757. {
  1758. .procname = "real-root-dev",
  1759. .data = &real_root_dev,
  1760. .maxlen = sizeof(int),
  1761. .mode = 0644,
  1762. .proc_handler = proc_dointvec,
  1763. },
  1764. #endif
  1765. {
  1766. .procname = "print-fatal-signals",
  1767. .data = &print_fatal_signals,
  1768. .maxlen = sizeof(int),
  1769. .mode = 0644,
  1770. .proc_handler = proc_dointvec,
  1771. },
  1772. #ifdef CONFIG_SPARC
  1773. {
  1774. .procname = "reboot-cmd",
  1775. .data = reboot_command,
  1776. .maxlen = 256,
  1777. .mode = 0644,
  1778. .proc_handler = proc_dostring,
  1779. },
  1780. {
  1781. .procname = "stop-a",
  1782. .data = &stop_a_enabled,
  1783. .maxlen = sizeof (int),
  1784. .mode = 0644,
  1785. .proc_handler = proc_dointvec,
  1786. },
  1787. {
  1788. .procname = "scons-poweroff",
  1789. .data = &scons_pwroff,
  1790. .maxlen = sizeof (int),
  1791. .mode = 0644,
  1792. .proc_handler = proc_dointvec,
  1793. },
  1794. #endif
  1795. #ifdef CONFIG_SPARC64
  1796. {
  1797. .procname = "tsb-ratio",
  1798. .data = &sysctl_tsb_ratio,
  1799. .maxlen = sizeof (int),
  1800. .mode = 0644,
  1801. .proc_handler = proc_dointvec,
  1802. },
  1803. #endif
  1804. #ifdef CONFIG_PARISC
  1805. {
  1806. .procname = "soft-power",
  1807. .data = &pwrsw_enabled,
  1808. .maxlen = sizeof (int),
  1809. .mode = 0644,
  1810. .proc_handler = proc_dointvec,
  1811. },
  1812. #endif
  1813. #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
  1814. {
  1815. .procname = "unaligned-trap",
  1816. .data = &unaligned_enabled,
  1817. .maxlen = sizeof (int),
  1818. .mode = 0644,
  1819. .proc_handler = proc_dointvec,
  1820. },
  1821. #endif
  1822. {
  1823. .procname = "ctrl-alt-del",
  1824. .data = &C_A_D,
  1825. .maxlen = sizeof(int),
  1826. .mode = 0644,
  1827. .proc_handler = proc_dointvec,
  1828. },
  1829. #ifdef CONFIG_FUNCTION_TRACER
  1830. {
  1831. .procname = "ftrace_enabled",
  1832. .data = &ftrace_enabled,
  1833. .maxlen = sizeof(int),
  1834. .mode = 0644,
  1835. .proc_handler = ftrace_enable_sysctl,
  1836. },
  1837. #endif
  1838. #ifdef CONFIG_STACK_TRACER
  1839. {
  1840. .procname = "stack_tracer_enabled",
  1841. .data = &stack_tracer_enabled,
  1842. .maxlen = sizeof(int),
  1843. .mode = 0644,
  1844. .proc_handler = stack_trace_sysctl,
  1845. },
  1846. #endif
  1847. #ifdef CONFIG_TRACING
  1848. {
  1849. .procname = "ftrace_dump_on_oops",
  1850. .data = &ftrace_dump_on_oops,
  1851. .maxlen = sizeof(int),
  1852. .mode = 0644,
  1853. .proc_handler = proc_dointvec,
  1854. },
  1855. {
  1856. .procname = "traceoff_on_warning",
  1857. .data = &__disable_trace_on_warning,
  1858. .maxlen = sizeof(__disable_trace_on_warning),
  1859. .mode = 0644,
  1860. .proc_handler = proc_dointvec,
  1861. },
  1862. {
  1863. .procname = "tracepoint_printk",
  1864. .data = &tracepoint_printk,
  1865. .maxlen = sizeof(tracepoint_printk),
  1866. .mode = 0644,
  1867. .proc_handler = tracepoint_printk_sysctl,
  1868. },
  1869. #endif
  1870. #ifdef CONFIG_KEXEC_CORE
  1871. {
  1872. .procname = "kexec_load_disabled",
  1873. .data = &kexec_load_disabled,
  1874. .maxlen = sizeof(int),
  1875. .mode = 0644,
  1876. /* only handle a transition from default "0" to "1" */
  1877. .proc_handler = proc_dointvec_minmax,
  1878. .extra1 = SYSCTL_ONE,
  1879. .extra2 = SYSCTL_ONE,
  1880. },
  1881. #endif
  1882. #ifdef CONFIG_MODULES
  1883. {
  1884. .procname = "modprobe",
  1885. .data = &modprobe_path,
  1886. .maxlen = KMOD_PATH_LEN,
  1887. .mode = 0644,
  1888. .proc_handler = proc_dostring,
  1889. },
  1890. {
  1891. .procname = "modules_disabled",
  1892. .data = &modules_disabled,
  1893. .maxlen = sizeof(int),
  1894. .mode = 0644,
  1895. /* only handle a transition from default "0" to "1" */
  1896. .proc_handler = proc_dointvec_minmax,
  1897. .extra1 = SYSCTL_ONE,
  1898. .extra2 = SYSCTL_ONE,
  1899. },
  1900. #endif
  1901. #ifdef CONFIG_UEVENT_HELPER
  1902. {
  1903. .procname = "hotplug",
  1904. .data = &uevent_helper,
  1905. .maxlen = UEVENT_HELPER_PATH_LEN,
  1906. .mode = 0644,
  1907. .proc_handler = proc_dostring,
  1908. },
  1909. #endif
  1910. #ifdef CONFIG_CHR_DEV_SG
  1911. {
  1912. .procname = "sg-big-buff",
  1913. .data = &sg_big_buff,
  1914. .maxlen = sizeof (int),
  1915. .mode = 0444,
  1916. .proc_handler = proc_dointvec,
  1917. },
  1918. #endif
  1919. #ifdef CONFIG_BSD_PROCESS_ACCT
  1920. {
  1921. .procname = "acct",
  1922. .data = &acct_parm,
  1923. .maxlen = 3*sizeof(int),
  1924. .mode = 0644,
  1925. .proc_handler = proc_dointvec,
  1926. },
  1927. #endif
  1928. #ifdef CONFIG_MAGIC_SYSRQ
  1929. {
  1930. .procname = "sysrq",
  1931. .data = NULL,
  1932. .maxlen = sizeof (int),
  1933. .mode = 0644,
  1934. .proc_handler = sysrq_sysctl_handler,
  1935. },
  1936. #endif
  1937. #ifdef CONFIG_PROC_SYSCTL
  1938. {
  1939. .procname = "cad_pid",
  1940. .data = NULL,
  1941. .maxlen = sizeof (int),
  1942. .mode = 0600,
  1943. .proc_handler = proc_do_cad_pid,
  1944. },
  1945. #endif
  1946. {
  1947. .procname = "threads-max",
  1948. .data = NULL,
  1949. .maxlen = sizeof(int),
  1950. .mode = 0644,
  1951. .proc_handler = sysctl_max_threads,
  1952. },
  1953. {
  1954. .procname = "random",
  1955. .mode = 0555,
  1956. .child = random_table,
  1957. },
  1958. {
  1959. .procname = "usermodehelper",
  1960. .mode = 0555,
  1961. .child = usermodehelper_table,
  1962. },
  1963. #ifdef CONFIG_FW_LOADER_USER_HELPER
  1964. {
  1965. .procname = "firmware_config",
  1966. .mode = 0555,
  1967. .child = firmware_config_table,
  1968. },
  1969. #endif
  1970. {
  1971. .procname = "overflowuid",
  1972. .data = &overflowuid,
  1973. .maxlen = sizeof(int),
  1974. .mode = 0644,
  1975. .proc_handler = proc_dointvec_minmax,
  1976. .extra1 = &minolduid,
  1977. .extra2 = &maxolduid,
  1978. },
  1979. {
  1980. .procname = "overflowgid",
  1981. .data = &overflowgid,
  1982. .maxlen = sizeof(int),
  1983. .mode = 0644,
  1984. .proc_handler = proc_dointvec_minmax,
  1985. .extra1 = &minolduid,
  1986. .extra2 = &maxolduid,
  1987. },
  1988. #ifdef CONFIG_S390
  1989. {
  1990. .procname = "userprocess_debug",
  1991. .data = &show_unhandled_signals,
  1992. .maxlen = sizeof(int),
  1993. .mode = 0644,
  1994. .proc_handler = proc_dointvec,
  1995. },
  1996. #endif
  1997. #ifdef CONFIG_SMP
  1998. {
  1999. .procname = "oops_all_cpu_backtrace",
  2000. .data = &sysctl_oops_all_cpu_backtrace,
  2001. .maxlen = sizeof(int),
  2002. .mode = 0644,
  2003. .proc_handler = proc_dointvec_minmax,
  2004. .extra1 = SYSCTL_ZERO,
  2005. .extra2 = SYSCTL_ONE,
  2006. },
  2007. #endif /* CONFIG_SMP */
  2008. {
  2009. .procname = "pid_max",
  2010. .data = &pid_max,
  2011. .maxlen = sizeof (int),
  2012. .mode = 0644,
  2013. .proc_handler = proc_dointvec_minmax,
  2014. .extra1 = &pid_max_min,
  2015. .extra2 = &pid_max_max,
  2016. },
  2017. {
  2018. .procname = "panic_on_oops",
  2019. .data = &panic_on_oops,
  2020. .maxlen = sizeof(int),
  2021. .mode = 0644,
  2022. .proc_handler = proc_dointvec,
  2023. },
  2024. {
  2025. .procname = "panic_print",
  2026. .data = &panic_print,
  2027. .maxlen = sizeof(unsigned long),
  2028. .mode = 0644,
  2029. .proc_handler = proc_doulongvec_minmax,
  2030. },
  2031. #if defined CONFIG_PRINTK
  2032. {
  2033. .procname = "printk",
  2034. .data = &console_loglevel,
  2035. .maxlen = 4*sizeof(int),
  2036. .mode = 0644,
  2037. .proc_handler = proc_dointvec,
  2038. },
  2039. {
  2040. .procname = "printk_ratelimit",
  2041. .data = &printk_ratelimit_state.interval,
  2042. .maxlen = sizeof(int),
  2043. .mode = 0644,
  2044. .proc_handler = proc_dointvec_jiffies,
  2045. },
  2046. {
  2047. .procname = "printk_ratelimit_burst",
  2048. .data = &printk_ratelimit_state.burst,
  2049. .maxlen = sizeof(int),
  2050. .mode = 0644,
  2051. .proc_handler = proc_dointvec,
  2052. },
  2053. {
  2054. .procname = "printk_delay",
  2055. .data = &printk_delay_msec,
  2056. .maxlen = sizeof(int),
  2057. .mode = 0644,
  2058. .proc_handler = proc_dointvec_minmax,
  2059. .extra1 = SYSCTL_ZERO,
  2060. .extra2 = &ten_thousand,
  2061. },
  2062. {
  2063. .procname = "printk_devkmsg",
  2064. .data = devkmsg_log_str,
  2065. .maxlen = DEVKMSG_STR_MAX_SIZE,
  2066. .mode = 0644,
  2067. .proc_handler = devkmsg_sysctl_set_loglvl,
  2068. },
  2069. {
  2070. .procname = "dmesg_restrict",
  2071. .data = &dmesg_restrict,
  2072. .maxlen = sizeof(int),
  2073. .mode = 0644,
  2074. .proc_handler = proc_dointvec_minmax_sysadmin,
  2075. .extra1 = SYSCTL_ZERO,
  2076. .extra2 = SYSCTL_ONE,
  2077. },
  2078. {
  2079. .procname = "kptr_restrict",
  2080. .data = &kptr_restrict,
  2081. .maxlen = sizeof(int),
  2082. .mode = 0644,
  2083. .proc_handler = proc_dointvec_minmax_sysadmin,
  2084. .extra1 = SYSCTL_ZERO,
  2085. .extra2 = &two,
  2086. },
  2087. #endif
  2088. {
  2089. .procname = "ngroups_max",
  2090. .data = &ngroups_max,
  2091. .maxlen = sizeof (int),
  2092. .mode = 0444,
  2093. .proc_handler = proc_dointvec,
  2094. },
  2095. {
  2096. .procname = "cap_last_cap",
  2097. .data = (void *)&cap_last_cap,
  2098. .maxlen = sizeof(int),
  2099. .mode = 0444,
  2100. .proc_handler = proc_dointvec,
  2101. },
  2102. #if defined(CONFIG_LOCKUP_DETECTOR)
  2103. {
  2104. .procname = "watchdog",
  2105. .data = &watchdog_user_enabled,
  2106. .maxlen = sizeof(int),
  2107. .mode = 0644,
  2108. .proc_handler = proc_watchdog,
  2109. .extra1 = SYSCTL_ZERO,
  2110. .extra2 = SYSCTL_ONE,
  2111. },
  2112. {
  2113. .procname = "watchdog_thresh",
  2114. .data = &watchdog_thresh,
  2115. .maxlen = sizeof(int),
  2116. .mode = 0644,
  2117. .proc_handler = proc_watchdog_thresh,
  2118. .extra1 = SYSCTL_ZERO,
  2119. .extra2 = &sixty,
  2120. },
  2121. {
  2122. .procname = "nmi_watchdog",
  2123. .data = &nmi_watchdog_user_enabled,
  2124. .maxlen = sizeof(int),
  2125. .mode = NMI_WATCHDOG_SYSCTL_PERM,
  2126. .proc_handler = proc_nmi_watchdog,
  2127. .extra1 = SYSCTL_ZERO,
  2128. .extra2 = SYSCTL_ONE,
  2129. },
  2130. {
  2131. .procname = "watchdog_cpumask",
  2132. .data = &watchdog_cpumask_bits,
  2133. .maxlen = NR_CPUS,
  2134. .mode = 0644,
  2135. .proc_handler = proc_watchdog_cpumask,
  2136. },
  2137. #ifdef CONFIG_SOFTLOCKUP_DETECTOR
  2138. {
  2139. .procname = "soft_watchdog",
  2140. .data = &soft_watchdog_user_enabled,
  2141. .maxlen = sizeof(int),
  2142. .mode = 0644,
  2143. .proc_handler = proc_soft_watchdog,
  2144. .extra1 = SYSCTL_ZERO,
  2145. .extra2 = SYSCTL_ONE,
  2146. },
  2147. {
  2148. .procname = "softlockup_panic",
  2149. .data = &softlockup_panic,
  2150. .maxlen = sizeof(int),
  2151. .mode = 0644,
  2152. .proc_handler = proc_dointvec_minmax,
  2153. .extra1 = SYSCTL_ZERO,
  2154. .extra2 = SYSCTL_ONE,
  2155. },
  2156. #ifdef CONFIG_SMP
  2157. {
  2158. .procname = "softlockup_all_cpu_backtrace",
  2159. .data = &sysctl_softlockup_all_cpu_backtrace,
  2160. .maxlen = sizeof(int),
  2161. .mode = 0644,
  2162. .proc_handler = proc_dointvec_minmax,
  2163. .extra1 = SYSCTL_ZERO,
  2164. .extra2 = SYSCTL_ONE,
  2165. },
  2166. #endif /* CONFIG_SMP */
  2167. #endif
  2168. #ifdef CONFIG_HARDLOCKUP_DETECTOR
  2169. {
  2170. .procname = "hardlockup_panic",
  2171. .data = &hardlockup_panic,
  2172. .maxlen = sizeof(int),
  2173. .mode = 0644,
  2174. .proc_handler = proc_dointvec_minmax,
  2175. .extra1 = SYSCTL_ZERO,
  2176. .extra2 = SYSCTL_ONE,
  2177. },
  2178. #ifdef CONFIG_SMP
  2179. {
  2180. .procname = "hardlockup_all_cpu_backtrace",
  2181. .data = &sysctl_hardlockup_all_cpu_backtrace,
  2182. .maxlen = sizeof(int),
  2183. .mode = 0644,
  2184. .proc_handler = proc_dointvec_minmax,
  2185. .extra1 = SYSCTL_ZERO,
  2186. .extra2 = SYSCTL_ONE,
  2187. },
  2188. #endif /* CONFIG_SMP */
  2189. #endif
  2190. #endif
  2191. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
  2192. {
  2193. .procname = "unknown_nmi_panic",
  2194. .data = &unknown_nmi_panic,
  2195. .maxlen = sizeof (int),
  2196. .mode = 0644,
  2197. .proc_handler = proc_dointvec,
  2198. },
  2199. #endif
  2200. #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
  2201. defined(CONFIG_DEBUG_STACKOVERFLOW)
  2202. {
  2203. .procname = "panic_on_stackoverflow",
  2204. .data = &sysctl_panic_on_stackoverflow,
  2205. .maxlen = sizeof(int),
  2206. .mode = 0644,
  2207. .proc_handler = proc_dointvec,
  2208. },
  2209. #endif
  2210. #if defined(CONFIG_X86)
  2211. {
  2212. .procname = "panic_on_unrecovered_nmi",
  2213. .data = &panic_on_unrecovered_nmi,
  2214. .maxlen = sizeof(int),
  2215. .mode = 0644,
  2216. .proc_handler = proc_dointvec,
  2217. },
  2218. {
  2219. .procname = "panic_on_io_nmi",
  2220. .data = &panic_on_io_nmi,
  2221. .maxlen = sizeof(int),
  2222. .mode = 0644,
  2223. .proc_handler = proc_dointvec,
  2224. },
  2225. {
  2226. .procname = "bootloader_type",
  2227. .data = &bootloader_type,
  2228. .maxlen = sizeof (int),
  2229. .mode = 0444,
  2230. .proc_handler = proc_dointvec,
  2231. },
  2232. {
  2233. .procname = "bootloader_version",
  2234. .data = &bootloader_version,
  2235. .maxlen = sizeof (int),
  2236. .mode = 0444,
  2237. .proc_handler = proc_dointvec,
  2238. },
  2239. {
  2240. .procname = "io_delay_type",
  2241. .data = &io_delay_type,
  2242. .maxlen = sizeof(int),
  2243. .mode = 0644,
  2244. .proc_handler = proc_dointvec,
  2245. },
  2246. #endif
  2247. #if defined(CONFIG_MMU)
  2248. {
  2249. .procname = "randomize_va_space",
  2250. .data = &randomize_va_space,
  2251. .maxlen = sizeof(int),
  2252. .mode = 0644,
  2253. .proc_handler = proc_dointvec,
  2254. },
  2255. #endif
  2256. #if defined(CONFIG_S390) && defined(CONFIG_SMP)
  2257. {
  2258. .procname = "spin_retry",
  2259. .data = &spin_retry,
  2260. .maxlen = sizeof (int),
  2261. .mode = 0644,
  2262. .proc_handler = proc_dointvec,
  2263. },
  2264. #endif
  2265. #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
  2266. {
  2267. .procname = "acpi_video_flags",
  2268. .data = &acpi_realmode_flags,
  2269. .maxlen = sizeof (unsigned long),
  2270. .mode = 0644,
  2271. .proc_handler = proc_doulongvec_minmax,
  2272. },
  2273. #endif
  2274. #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
  2275. {
  2276. .procname = "ignore-unaligned-usertrap",
  2277. .data = &no_unaligned_warning,
  2278. .maxlen = sizeof (int),
  2279. .mode = 0644,
  2280. .proc_handler = proc_dointvec,
  2281. },
  2282. #endif
  2283. #ifdef CONFIG_IA64
  2284. {
  2285. .procname = "unaligned-dump-stack",
  2286. .data = &unaligned_dump_stack,
  2287. .maxlen = sizeof (int),
  2288. .mode = 0644,
  2289. .proc_handler = proc_dointvec,
  2290. },
  2291. #endif
  2292. #ifdef CONFIG_DETECT_HUNG_TASK
  2293. #ifdef CONFIG_SMP
  2294. {
  2295. .procname = "hung_task_all_cpu_backtrace",
  2296. .data = &sysctl_hung_task_all_cpu_backtrace,
  2297. .maxlen = sizeof(int),
  2298. .mode = 0644,
  2299. .proc_handler = proc_dointvec_minmax,
  2300. .extra1 = SYSCTL_ZERO,
  2301. .extra2 = SYSCTL_ONE,
  2302. },
  2303. #endif /* CONFIG_SMP */
  2304. {
  2305. .procname = "hung_task_panic",
  2306. .data = &sysctl_hung_task_panic,
  2307. .maxlen = sizeof(int),
  2308. .mode = 0644,
  2309. .proc_handler = proc_dointvec_minmax,
  2310. .extra1 = SYSCTL_ZERO,
  2311. .extra2 = SYSCTL_ONE,
  2312. },
  2313. {
  2314. .procname = "hung_task_check_count",
  2315. .data = &sysctl_hung_task_check_count,
  2316. .maxlen = sizeof(int),
  2317. .mode = 0644,
  2318. .proc_handler = proc_dointvec_minmax,
  2319. .extra1 = SYSCTL_ZERO,
  2320. },
  2321. {
  2322. .procname = "hung_task_timeout_secs",
  2323. .data = &sysctl_hung_task_timeout_secs,
  2324. .maxlen = sizeof(unsigned long),
  2325. .mode = 0644,
  2326. .proc_handler = proc_dohung_task_timeout_secs,
  2327. .extra2 = &hung_task_timeout_max,
  2328. },
  2329. {
  2330. .procname = "hung_task_check_interval_secs",
  2331. .data = &sysctl_hung_task_check_interval_secs,
  2332. .maxlen = sizeof(unsigned long),
  2333. .mode = 0644,
  2334. .proc_handler = proc_dohung_task_timeout_secs,
  2335. .extra2 = &hung_task_timeout_max,
  2336. },
  2337. {
  2338. .procname = "hung_task_warnings",
  2339. .data = &sysctl_hung_task_warnings,
  2340. .maxlen = sizeof(int),
  2341. .mode = 0644,
  2342. .proc_handler = proc_dointvec_minmax,
  2343. .extra1 = &neg_one,
  2344. },
  2345. #endif
  2346. #ifdef CONFIG_RT_MUTEXES
  2347. {
  2348. .procname = "max_lock_depth",
  2349. .data = &max_lock_depth,
  2350. .maxlen = sizeof(int),
  2351. .mode = 0644,
  2352. .proc_handler = proc_dointvec,
  2353. },
  2354. #endif
  2355. {
  2356. .procname = "poweroff_cmd",
  2357. .data = &poweroff_cmd,
  2358. .maxlen = POWEROFF_CMD_PATH_LEN,
  2359. .mode = 0644,
  2360. .proc_handler = proc_dostring,
  2361. },
  2362. #ifdef CONFIG_KEYS
  2363. {
  2364. .procname = "keys",
  2365. .mode = 0555,
  2366. .child = key_sysctls,
  2367. },
  2368. #endif
  2369. #ifdef CONFIG_PERF_EVENTS
  2370. /*
  2371. * User-space scripts rely on the existence of this file
  2372. * as a feature check for perf_events being enabled.
  2373. *
  2374. * So it's an ABI, do not remove!
  2375. */
  2376. {
  2377. .procname = "perf_event_paranoid",
  2378. .data = &sysctl_perf_event_paranoid,
  2379. .maxlen = sizeof(sysctl_perf_event_paranoid),
  2380. .mode = 0644,
  2381. .proc_handler = proc_dointvec,
  2382. },
  2383. {
  2384. .procname = "perf_event_mlock_kb",
  2385. .data = &sysctl_perf_event_mlock,
  2386. .maxlen = sizeof(sysctl_perf_event_mlock),
  2387. .mode = 0644,
  2388. .proc_handler = proc_dointvec,
  2389. },
  2390. {
  2391. .procname = "perf_event_max_sample_rate",
  2392. .data = &sysctl_perf_event_sample_rate,
  2393. .maxlen = sizeof(sysctl_perf_event_sample_rate),
  2394. .mode = 0644,
  2395. .proc_handler = perf_proc_update_handler,
  2396. .extra1 = SYSCTL_ONE,
  2397. },
  2398. {
  2399. .procname = "perf_cpu_time_max_percent",
  2400. .data = &sysctl_perf_cpu_time_max_percent,
  2401. .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
  2402. .mode = 0644,
  2403. .proc_handler = perf_cpu_time_max_percent_handler,
  2404. .extra1 = SYSCTL_ZERO,
  2405. .extra2 = &one_hundred,
  2406. },
  2407. {
  2408. .procname = "perf_event_max_stack",
  2409. .data = &sysctl_perf_event_max_stack,
  2410. .maxlen = sizeof(sysctl_perf_event_max_stack),
  2411. .mode = 0644,
  2412. .proc_handler = perf_event_max_stack_handler,
  2413. .extra1 = SYSCTL_ZERO,
  2414. .extra2 = &six_hundred_forty_kb,
  2415. },
  2416. {
  2417. .procname = "perf_event_max_contexts_per_stack",
  2418. .data = &sysctl_perf_event_max_contexts_per_stack,
  2419. .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
  2420. .mode = 0644,
  2421. .proc_handler = perf_event_max_stack_handler,
  2422. .extra1 = SYSCTL_ZERO,
  2423. .extra2 = &one_thousand,
  2424. },
  2425. #endif
  2426. {
  2427. .procname = "panic_on_warn",
  2428. .data = &panic_on_warn,
  2429. .maxlen = sizeof(int),
  2430. .mode = 0644,
  2431. .proc_handler = proc_dointvec_minmax,
  2432. .extra1 = SYSCTL_ZERO,
  2433. .extra2 = SYSCTL_ONE,
  2434. },
  2435. #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
  2436. {
  2437. .procname = "timer_migration",
  2438. .data = &sysctl_timer_migration,
  2439. .maxlen = sizeof(unsigned int),
  2440. .mode = 0644,
  2441. .proc_handler = timer_migration_handler,
  2442. .extra1 = SYSCTL_ZERO,
  2443. .extra2 = SYSCTL_ONE,
  2444. },
  2445. #endif
  2446. #ifdef CONFIG_BPF_SYSCALL
  2447. {
  2448. .procname = "unprivileged_bpf_disabled",
  2449. .data = &sysctl_unprivileged_bpf_disabled,
  2450. .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
  2451. .mode = 0644,
  2452. .proc_handler = bpf_unpriv_handler,
  2453. .extra1 = SYSCTL_ZERO,
  2454. .extra2 = &two,
  2455. },
  2456. {
  2457. .procname = "bpf_stats_enabled",
  2458. .data = &bpf_stats_enabled_key.key,
  2459. .maxlen = sizeof(bpf_stats_enabled_key),
  2460. .mode = 0644,
  2461. .proc_handler = bpf_stats_handler,
  2462. },
  2463. #endif
  2464. #if defined(CONFIG_TREE_RCU)
  2465. {
  2466. .procname = "panic_on_rcu_stall",
  2467. .data = &sysctl_panic_on_rcu_stall,
  2468. .maxlen = sizeof(sysctl_panic_on_rcu_stall),
  2469. .mode = 0644,
  2470. .proc_handler = proc_dointvec_minmax,
  2471. .extra1 = SYSCTL_ZERO,
  2472. .extra2 = SYSCTL_ONE,
  2473. },
  2474. #endif
  2475. #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
  2476. {
  2477. .procname = "stack_erasing",
  2478. .data = NULL,
  2479. .maxlen = sizeof(int),
  2480. .mode = 0600,
  2481. .proc_handler = stack_erasing_sysctl,
  2482. .extra1 = SYSCTL_ZERO,
  2483. .extra2 = SYSCTL_ONE,
  2484. },
  2485. #endif
  2486. { }
  2487. };
  2488. static struct ctl_table vm_table[] = {
  2489. {
  2490. .procname = "overcommit_memory",
  2491. .data = &sysctl_overcommit_memory,
  2492. .maxlen = sizeof(sysctl_overcommit_memory),
  2493. .mode = 0644,
  2494. .proc_handler = overcommit_policy_handler,
  2495. .extra1 = SYSCTL_ZERO,
  2496. .extra2 = &two,
  2497. },
  2498. {
  2499. .procname = "panic_on_oom",
  2500. .data = &sysctl_panic_on_oom,
  2501. .maxlen = sizeof(sysctl_panic_on_oom),
  2502. .mode = 0644,
  2503. .proc_handler = proc_dointvec_minmax,
  2504. .extra1 = SYSCTL_ZERO,
  2505. .extra2 = &two,
  2506. },
  2507. {
  2508. .procname = "oom_kill_allocating_task",
  2509. .data = &sysctl_oom_kill_allocating_task,
  2510. .maxlen = sizeof(sysctl_oom_kill_allocating_task),
  2511. .mode = 0644,
  2512. .proc_handler = proc_dointvec,
  2513. },
  2514. {
  2515. .procname = "oom_dump_tasks",
  2516. .data = &sysctl_oom_dump_tasks,
  2517. .maxlen = sizeof(sysctl_oom_dump_tasks),
  2518. .mode = 0644,
  2519. .proc_handler = proc_dointvec,
  2520. },
  2521. {
  2522. .procname = "overcommit_ratio",
  2523. .data = &sysctl_overcommit_ratio,
  2524. .maxlen = sizeof(sysctl_overcommit_ratio),
  2525. .mode = 0644,
  2526. .proc_handler = overcommit_ratio_handler,
  2527. },
  2528. {
  2529. .procname = "overcommit_kbytes",
  2530. .data = &sysctl_overcommit_kbytes,
  2531. .maxlen = sizeof(sysctl_overcommit_kbytes),
  2532. .mode = 0644,
  2533. .proc_handler = overcommit_kbytes_handler,
  2534. },
  2535. {
  2536. .procname = "page-cluster",
  2537. .data = &page_cluster,
  2538. .maxlen = sizeof(int),
  2539. .mode = 0644,
  2540. .proc_handler = proc_dointvec_minmax,
  2541. .extra1 = SYSCTL_ZERO,
  2542. },
  2543. {
  2544. .procname = "dirty_background_ratio",
  2545. .data = &dirty_background_ratio,
  2546. .maxlen = sizeof(dirty_background_ratio),
  2547. .mode = 0644,
  2548. .proc_handler = dirty_background_ratio_handler,
  2549. .extra1 = SYSCTL_ZERO,
  2550. .extra2 = &one_hundred,
  2551. },
  2552. {
  2553. .procname = "dirty_background_bytes",
  2554. .data = &dirty_background_bytes,
  2555. .maxlen = sizeof(dirty_background_bytes),
  2556. .mode = 0644,
  2557. .proc_handler = dirty_background_bytes_handler,
  2558. .extra1 = &one_ul,
  2559. },
  2560. {
  2561. .procname = "dirty_ratio",
  2562. .data = &vm_dirty_ratio,
  2563. .maxlen = sizeof(vm_dirty_ratio),
  2564. .mode = 0644,
  2565. .proc_handler = dirty_ratio_handler,
  2566. .extra1 = SYSCTL_ZERO,
  2567. .extra2 = &one_hundred,
  2568. },
  2569. {
  2570. .procname = "dirty_bytes",
  2571. .data = &vm_dirty_bytes,
  2572. .maxlen = sizeof(vm_dirty_bytes),
  2573. .mode = 0644,
  2574. .proc_handler = dirty_bytes_handler,
  2575. .extra1 = &dirty_bytes_min,
  2576. },
  2577. {
  2578. .procname = "dirty_writeback_centisecs",
  2579. .data = &dirty_writeback_interval,
  2580. .maxlen = sizeof(dirty_writeback_interval),
  2581. .mode = 0644,
  2582. .proc_handler = dirty_writeback_centisecs_handler,
  2583. },
  2584. {
  2585. .procname = "dirty_expire_centisecs",
  2586. .data = &dirty_expire_interval,
  2587. .maxlen = sizeof(dirty_expire_interval),
  2588. .mode = 0644,
  2589. .proc_handler = proc_dointvec_minmax,
  2590. .extra1 = SYSCTL_ZERO,
  2591. },
  2592. {
  2593. .procname = "dirtytime_expire_seconds",
  2594. .data = &dirtytime_expire_interval,
  2595. .maxlen = sizeof(dirtytime_expire_interval),
  2596. .mode = 0644,
  2597. .proc_handler = dirtytime_interval_handler,
  2598. .extra1 = SYSCTL_ZERO,
  2599. },
  2600. {
  2601. .procname = "swappiness",
  2602. .data = &vm_swappiness,
  2603. .maxlen = sizeof(vm_swappiness),
  2604. .mode = 0644,
  2605. .proc_handler = proc_dointvec_minmax,
  2606. .extra1 = SYSCTL_ZERO,
  2607. .extra2 = &two_hundred,
  2608. },
  2609. #ifdef CONFIG_HUGETLB_PAGE
  2610. {
  2611. .procname = "nr_hugepages",
  2612. .data = NULL,
  2613. .maxlen = sizeof(unsigned long),
  2614. .mode = 0644,
  2615. .proc_handler = hugetlb_sysctl_handler,
  2616. },
  2617. #ifdef CONFIG_NUMA
  2618. {
  2619. .procname = "nr_hugepages_mempolicy",
  2620. .data = NULL,
  2621. .maxlen = sizeof(unsigned long),
  2622. .mode = 0644,
  2623. .proc_handler = &hugetlb_mempolicy_sysctl_handler,
  2624. },
  2625. {
  2626. .procname = "numa_stat",
  2627. .data = &sysctl_vm_numa_stat,
  2628. .maxlen = sizeof(int),
  2629. .mode = 0644,
  2630. .proc_handler = sysctl_vm_numa_stat_handler,
  2631. .extra1 = SYSCTL_ZERO,
  2632. .extra2 = SYSCTL_ONE,
  2633. },
  2634. #endif
  2635. {
  2636. .procname = "hugetlb_shm_group",
  2637. .data = &sysctl_hugetlb_shm_group,
  2638. .maxlen = sizeof(gid_t),
  2639. .mode = 0644,
  2640. .proc_handler = proc_dointvec,
  2641. },
  2642. {
  2643. .procname = "nr_overcommit_hugepages",
  2644. .data = NULL,
  2645. .maxlen = sizeof(unsigned long),
  2646. .mode = 0644,
  2647. .proc_handler = hugetlb_overcommit_handler,
  2648. },
  2649. #endif
  2650. {
  2651. .procname = "lowmem_reserve_ratio",
  2652. .data = &sysctl_lowmem_reserve_ratio,
  2653. .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
  2654. .mode = 0644,
  2655. .proc_handler = lowmem_reserve_ratio_sysctl_handler,
  2656. },
  2657. {
  2658. .procname = "drop_caches",
  2659. .data = &sysctl_drop_caches,
  2660. .maxlen = sizeof(int),
  2661. .mode = 0200,
  2662. .proc_handler = drop_caches_sysctl_handler,
  2663. .extra1 = SYSCTL_ONE,
  2664. .extra2 = &four,
  2665. },
  2666. #ifdef CONFIG_COMPACTION
  2667. {
  2668. .procname = "compact_memory",
  2669. .data = &sysctl_compact_memory,
  2670. .maxlen = sizeof(int),
  2671. .mode = 0200,
  2672. .proc_handler = sysctl_compaction_handler,
  2673. },
  2674. {
  2675. .procname = "compaction_proactiveness",
  2676. .data = &sysctl_compaction_proactiveness,
  2677. .maxlen = sizeof(sysctl_compaction_proactiveness),
  2678. .mode = 0644,
  2679. .proc_handler = compaction_proactiveness_sysctl_handler,
  2680. .extra1 = SYSCTL_ZERO,
  2681. .extra2 = &one_hundred,
  2682. },
  2683. {
  2684. .procname = "extfrag_threshold",
  2685. .data = &sysctl_extfrag_threshold,
  2686. .maxlen = sizeof(int),
  2687. .mode = 0644,
  2688. .proc_handler = proc_dointvec_minmax,
  2689. .extra1 = &min_extfrag_threshold,
  2690. .extra2 = &max_extfrag_threshold,
  2691. },
  2692. {
  2693. .procname = "compact_unevictable_allowed",
  2694. .data = &sysctl_compact_unevictable_allowed,
  2695. .maxlen = sizeof(int),
  2696. .mode = 0644,
  2697. .proc_handler = proc_dointvec_minmax_warn_RT_change,
  2698. .extra1 = SYSCTL_ZERO,
  2699. .extra2 = SYSCTL_ONE,
  2700. },
  2701. #endif /* CONFIG_COMPACTION */
  2702. {
  2703. .procname = "min_free_kbytes",
  2704. .data = &min_free_kbytes,
  2705. .maxlen = sizeof(min_free_kbytes),
  2706. .mode = 0644,
  2707. .proc_handler = min_free_kbytes_sysctl_handler,
  2708. .extra1 = SYSCTL_ZERO,
  2709. },
  2710. {
  2711. .procname = "watermark_boost_factor",
  2712. .data = &watermark_boost_factor,
  2713. .maxlen = sizeof(watermark_boost_factor),
  2714. .mode = 0644,
  2715. .proc_handler = proc_dointvec_minmax,
  2716. .extra1 = SYSCTL_ZERO,
  2717. },
  2718. {
  2719. .procname = "watermark_scale_factor",
  2720. .data = &watermark_scale_factor,
  2721. .maxlen = sizeof(watermark_scale_factor),
  2722. .mode = 0644,
  2723. .proc_handler = watermark_scale_factor_sysctl_handler,
  2724. .extra1 = SYSCTL_ONE,
  2725. .extra2 = &one_thousand,
  2726. },
  2727. {
  2728. .procname = "extra_free_kbytes",
  2729. .data = &extra_free_kbytes,
  2730. .maxlen = sizeof(extra_free_kbytes),
  2731. .mode = 0644,
  2732. .proc_handler = min_free_kbytes_sysctl_handler,
  2733. .extra1 = SYSCTL_ZERO,
  2734. },
  2735. {
  2736. .procname = "percpu_pagelist_fraction",
  2737. .data = &percpu_pagelist_fraction,
  2738. .maxlen = sizeof(percpu_pagelist_fraction),
  2739. .mode = 0644,
  2740. .proc_handler = percpu_pagelist_fraction_sysctl_handler,
  2741. .extra1 = SYSCTL_ZERO,
  2742. },
  2743. {
  2744. .procname = "page_lock_unfairness",
  2745. .data = &sysctl_page_lock_unfairness,
  2746. .maxlen = sizeof(sysctl_page_lock_unfairness),
  2747. .mode = 0644,
  2748. .proc_handler = proc_dointvec_minmax,
  2749. .extra1 = SYSCTL_ZERO,
  2750. },
  2751. #ifdef CONFIG_MMU
  2752. {
  2753. .procname = "max_map_count",
  2754. .data = &sysctl_max_map_count,
  2755. .maxlen = sizeof(sysctl_max_map_count),
  2756. .mode = 0644,
  2757. .proc_handler = proc_dointvec_minmax,
  2758. .extra1 = SYSCTL_ZERO,
  2759. },
  2760. #else
  2761. {
  2762. .procname = "nr_trim_pages",
  2763. .data = &sysctl_nr_trim_pages,
  2764. .maxlen = sizeof(sysctl_nr_trim_pages),
  2765. .mode = 0644,
  2766. .proc_handler = proc_dointvec_minmax,
  2767. .extra1 = SYSCTL_ZERO,
  2768. },
  2769. #endif
  2770. {
  2771. .procname = "laptop_mode",
  2772. .data = &laptop_mode,
  2773. .maxlen = sizeof(laptop_mode),
  2774. .mode = 0644,
  2775. .proc_handler = proc_dointvec_jiffies,
  2776. },
  2777. {
  2778. .procname = "block_dump",
  2779. .data = &block_dump,
  2780. .maxlen = sizeof(block_dump),
  2781. .mode = 0644,
  2782. .proc_handler = proc_dointvec_minmax,
  2783. .extra1 = SYSCTL_ZERO,
  2784. },
  2785. {
  2786. .procname = "vfs_cache_pressure",
  2787. .data = &sysctl_vfs_cache_pressure,
  2788. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  2789. .mode = 0644,
  2790. .proc_handler = proc_dointvec_minmax,
  2791. .extra1 = SYSCTL_ZERO,
  2792. },
  2793. #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
  2794. defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
  2795. {
  2796. .procname = "legacy_va_layout",
  2797. .data = &sysctl_legacy_va_layout,
  2798. .maxlen = sizeof(sysctl_legacy_va_layout),
  2799. .mode = 0644,
  2800. .proc_handler = proc_dointvec_minmax,
  2801. .extra1 = SYSCTL_ZERO,
  2802. },
  2803. #endif
  2804. #ifdef CONFIG_NUMA
  2805. {
  2806. .procname = "zone_reclaim_mode",
  2807. .data = &node_reclaim_mode,
  2808. .maxlen = sizeof(node_reclaim_mode),
  2809. .mode = 0644,
  2810. .proc_handler = proc_dointvec_minmax,
  2811. .extra1 = SYSCTL_ZERO,
  2812. },
  2813. {
  2814. .procname = "min_unmapped_ratio",
  2815. .data = &sysctl_min_unmapped_ratio,
  2816. .maxlen = sizeof(sysctl_min_unmapped_ratio),
  2817. .mode = 0644,
  2818. .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
  2819. .extra1 = SYSCTL_ZERO,
  2820. .extra2 = &one_hundred,
  2821. },
  2822. {
  2823. .procname = "min_slab_ratio",
  2824. .data = &sysctl_min_slab_ratio,
  2825. .maxlen = sizeof(sysctl_min_slab_ratio),
  2826. .mode = 0644,
  2827. .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
  2828. .extra1 = SYSCTL_ZERO,
  2829. .extra2 = &one_hundred,
  2830. },
  2831. #endif
  2832. #ifdef CONFIG_SMP
  2833. {
  2834. .procname = "stat_interval",
  2835. .data = &sysctl_stat_interval,
  2836. .maxlen = sizeof(sysctl_stat_interval),
  2837. .mode = 0644,
  2838. .proc_handler = proc_dointvec_jiffies,
  2839. },
  2840. {
  2841. .procname = "stat_refresh",
  2842. .data = NULL,
  2843. .maxlen = 0,
  2844. .mode = 0600,
  2845. .proc_handler = vmstat_refresh,
  2846. },
  2847. #endif
  2848. #ifdef CONFIG_MMU
  2849. {
  2850. .procname = "mmap_min_addr",
  2851. .data = &dac_mmap_min_addr,
  2852. .maxlen = sizeof(unsigned long),
  2853. .mode = 0644,
  2854. .proc_handler = mmap_min_addr_handler,
  2855. },
  2856. #endif
  2857. #ifdef CONFIG_NUMA
  2858. {
  2859. .procname = "numa_zonelist_order",
  2860. .data = &numa_zonelist_order,
  2861. .maxlen = NUMA_ZONELIST_ORDER_LEN,
  2862. .mode = 0644,
  2863. .proc_handler = numa_zonelist_order_handler,
  2864. },
  2865. #endif
  2866. #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
  2867. (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
  2868. {
  2869. .procname = "vdso_enabled",
  2870. #ifdef CONFIG_X86_32
  2871. .data = &vdso32_enabled,
  2872. .maxlen = sizeof(vdso32_enabled),
  2873. #else
  2874. .data = &vdso_enabled,
  2875. .maxlen = sizeof(vdso_enabled),
  2876. #endif
  2877. .mode = 0644,
  2878. .proc_handler = proc_dointvec,
  2879. .extra1 = SYSCTL_ZERO,
  2880. },
  2881. #endif
  2882. #ifdef CONFIG_HIGHMEM
  2883. {
  2884. .procname = "highmem_is_dirtyable",
  2885. .data = &vm_highmem_is_dirtyable,
  2886. .maxlen = sizeof(vm_highmem_is_dirtyable),
  2887. .mode = 0644,
  2888. .proc_handler = proc_dointvec_minmax,
  2889. .extra1 = SYSCTL_ZERO,
  2890. .extra2 = SYSCTL_ONE,
  2891. },
  2892. #endif
  2893. #ifdef CONFIG_MEMORY_FAILURE
  2894. {
  2895. .procname = "memory_failure_early_kill",
  2896. .data = &sysctl_memory_failure_early_kill,
  2897. .maxlen = sizeof(sysctl_memory_failure_early_kill),
  2898. .mode = 0644,
  2899. .proc_handler = proc_dointvec_minmax,
  2900. .extra1 = SYSCTL_ZERO,
  2901. .extra2 = SYSCTL_ONE,
  2902. },
  2903. {
  2904. .procname = "memory_failure_recovery",
  2905. .data = &sysctl_memory_failure_recovery,
  2906. .maxlen = sizeof(sysctl_memory_failure_recovery),
  2907. .mode = 0644,
  2908. .proc_handler = proc_dointvec_minmax,
  2909. .extra1 = SYSCTL_ZERO,
  2910. .extra2 = SYSCTL_ONE,
  2911. },
  2912. #endif
  2913. {
  2914. .procname = "user_reserve_kbytes",
  2915. .data = &sysctl_user_reserve_kbytes,
  2916. .maxlen = sizeof(sysctl_user_reserve_kbytes),
  2917. .mode = 0644,
  2918. .proc_handler = proc_doulongvec_minmax,
  2919. },
  2920. {
  2921. .procname = "admin_reserve_kbytes",
  2922. .data = &sysctl_admin_reserve_kbytes,
  2923. .maxlen = sizeof(sysctl_admin_reserve_kbytes),
  2924. .mode = 0644,
  2925. .proc_handler = proc_doulongvec_minmax,
  2926. },
  2927. #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
  2928. {
  2929. .procname = "mmap_rnd_bits",
  2930. .data = &mmap_rnd_bits,
  2931. .maxlen = sizeof(mmap_rnd_bits),
  2932. .mode = 0600,
  2933. .proc_handler = proc_dointvec_minmax,
  2934. .extra1 = (void *)&mmap_rnd_bits_min,
  2935. .extra2 = (void *)&mmap_rnd_bits_max,
  2936. },
  2937. #endif
  2938. #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
  2939. {
  2940. .procname = "mmap_rnd_compat_bits",
  2941. .data = &mmap_rnd_compat_bits,
  2942. .maxlen = sizeof(mmap_rnd_compat_bits),
  2943. .mode = 0600,
  2944. .proc_handler = proc_dointvec_minmax,
  2945. .extra1 = (void *)&mmap_rnd_compat_bits_min,
  2946. .extra2 = (void *)&mmap_rnd_compat_bits_max,
  2947. },
  2948. #endif
  2949. #ifdef CONFIG_USERFAULTFD
  2950. {
  2951. .procname = "unprivileged_userfaultfd",
  2952. .data = &sysctl_unprivileged_userfaultfd,
  2953. .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
  2954. .mode = 0644,
  2955. .proc_handler = proc_dointvec_minmax,
  2956. .extra1 = SYSCTL_ZERO,
  2957. .extra2 = SYSCTL_ONE,
  2958. },
  2959. #endif
  2960. { }
  2961. };
  2962. static struct ctl_table fs_table[] = {
  2963. {
  2964. .procname = "inode-nr",
  2965. .data = &inodes_stat,
  2966. .maxlen = 2*sizeof(long),
  2967. .mode = 0444,
  2968. .proc_handler = proc_nr_inodes,
  2969. },
  2970. {
  2971. .procname = "inode-state",
  2972. .data = &inodes_stat,
  2973. .maxlen = 7*sizeof(long),
  2974. .mode = 0444,
  2975. .proc_handler = proc_nr_inodes,
  2976. },
  2977. {
  2978. .procname = "file-nr",
  2979. .data = &files_stat,
  2980. .maxlen = sizeof(files_stat),
  2981. .mode = 0444,
  2982. .proc_handler = proc_nr_files,
  2983. },
  2984. {
  2985. .procname = "file-max",
  2986. .data = &files_stat.max_files,
  2987. .maxlen = sizeof(files_stat.max_files),
  2988. .mode = 0644,
  2989. .proc_handler = proc_doulongvec_minmax,
  2990. .extra1 = &zero_ul,
  2991. .extra2 = &long_max,
  2992. },
  2993. {
  2994. .procname = "nr_open",
  2995. .data = &sysctl_nr_open,
  2996. .maxlen = sizeof(unsigned int),
  2997. .mode = 0644,
  2998. .proc_handler = proc_dointvec_minmax,
  2999. .extra1 = &sysctl_nr_open_min,
  3000. .extra2 = &sysctl_nr_open_max,
  3001. },
  3002. {
  3003. .procname = "dentry-state",
  3004. .data = &dentry_stat,
  3005. .maxlen = 6*sizeof(long),
  3006. .mode = 0444,
  3007. .proc_handler = proc_nr_dentry,
  3008. },
  3009. {
  3010. .procname = "overflowuid",
  3011. .data = &fs_overflowuid,
  3012. .maxlen = sizeof(int),
  3013. .mode = 0644,
  3014. .proc_handler = proc_dointvec_minmax,
  3015. .extra1 = &minolduid,
  3016. .extra2 = &maxolduid,
  3017. },
  3018. {
  3019. .procname = "overflowgid",
  3020. .data = &fs_overflowgid,
  3021. .maxlen = sizeof(int),
  3022. .mode = 0644,
  3023. .proc_handler = proc_dointvec_minmax,
  3024. .extra1 = &minolduid,
  3025. .extra2 = &maxolduid,
  3026. },
  3027. #ifdef CONFIG_FILE_LOCKING
  3028. {
  3029. .procname = "leases-enable",
  3030. .data = &leases_enable,
  3031. .maxlen = sizeof(int),
  3032. .mode = 0644,
  3033. .proc_handler = proc_dointvec,
  3034. },
  3035. #endif
  3036. #ifdef CONFIG_DNOTIFY
  3037. {
  3038. .procname = "dir-notify-enable",
  3039. .data = &dir_notify_enable,
  3040. .maxlen = sizeof(int),
  3041. .mode = 0644,
  3042. .proc_handler = proc_dointvec,
  3043. },
  3044. #endif
  3045. #ifdef CONFIG_MMU
  3046. #ifdef CONFIG_FILE_LOCKING
  3047. {
  3048. .procname = "lease-break-time",
  3049. .data = &lease_break_time,
  3050. .maxlen = sizeof(int),
  3051. .mode = 0644,
  3052. .proc_handler = proc_dointvec,
  3053. },
  3054. #endif
  3055. #ifdef CONFIG_AIO
  3056. {
  3057. .procname = "aio-nr",
  3058. .data = &aio_nr,
  3059. .maxlen = sizeof(aio_nr),
  3060. .mode = 0444,
  3061. .proc_handler = proc_doulongvec_minmax,
  3062. },
  3063. {
  3064. .procname = "aio-max-nr",
  3065. .data = &aio_max_nr,
  3066. .maxlen = sizeof(aio_max_nr),
  3067. .mode = 0644,
  3068. .proc_handler = proc_doulongvec_minmax,
  3069. },
  3070. #endif /* CONFIG_AIO */
  3071. #ifdef CONFIG_INOTIFY_USER
  3072. {
  3073. .procname = "inotify",
  3074. .mode = 0555,
  3075. .child = inotify_table,
  3076. },
  3077. #endif
  3078. #ifdef CONFIG_EPOLL
  3079. {
  3080. .procname = "epoll",
  3081. .mode = 0555,
  3082. .child = epoll_table,
  3083. },
  3084. #endif
  3085. #endif
  3086. {
  3087. .procname = "protected_symlinks",
  3088. .data = &sysctl_protected_symlinks,
  3089. .maxlen = sizeof(int),
  3090. .mode = 0600,
  3091. .proc_handler = proc_dointvec_minmax,
  3092. .extra1 = SYSCTL_ZERO,
  3093. .extra2 = SYSCTL_ONE,
  3094. },
  3095. {
  3096. .procname = "protected_hardlinks",
  3097. .data = &sysctl_protected_hardlinks,
  3098. .maxlen = sizeof(int),
  3099. .mode = 0600,
  3100. .proc_handler = proc_dointvec_minmax,
  3101. .extra1 = SYSCTL_ZERO,
  3102. .extra2 = SYSCTL_ONE,
  3103. },
  3104. {
  3105. .procname = "protected_fifos",
  3106. .data = &sysctl_protected_fifos,
  3107. .maxlen = sizeof(int),
  3108. .mode = 0600,
  3109. .proc_handler = proc_dointvec_minmax,
  3110. .extra1 = SYSCTL_ZERO,
  3111. .extra2 = &two,
  3112. },
  3113. {
  3114. .procname = "protected_regular",
  3115. .data = &sysctl_protected_regular,
  3116. .maxlen = sizeof(int),
  3117. .mode = 0600,
  3118. .proc_handler = proc_dointvec_minmax,
  3119. .extra1 = SYSCTL_ZERO,
  3120. .extra2 = &two,
  3121. },
  3122. {
  3123. .procname = "suid_dumpable",
  3124. .data = &suid_dumpable,
  3125. .maxlen = sizeof(int),
  3126. .mode = 0644,
  3127. .proc_handler = proc_dointvec_minmax_coredump,
  3128. .extra1 = SYSCTL_ZERO,
  3129. .extra2 = &two,
  3130. },
  3131. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  3132. {
  3133. .procname = "binfmt_misc",
  3134. .mode = 0555,
  3135. .child = sysctl_mount_point,
  3136. },
  3137. #endif
  3138. {
  3139. .procname = "pipe-max-size",
  3140. .data = &pipe_max_size,
  3141. .maxlen = sizeof(pipe_max_size),
  3142. .mode = 0644,
  3143. .proc_handler = proc_dopipe_max_size,
  3144. },
  3145. {
  3146. .procname = "pipe-user-pages-hard",
  3147. .data = &pipe_user_pages_hard,
  3148. .maxlen = sizeof(pipe_user_pages_hard),
  3149. .mode = 0644,
  3150. .proc_handler = proc_doulongvec_minmax,
  3151. },
  3152. {
  3153. .procname = "pipe-user-pages-soft",
  3154. .data = &pipe_user_pages_soft,
  3155. .maxlen = sizeof(pipe_user_pages_soft),
  3156. .mode = 0644,
  3157. .proc_handler = proc_doulongvec_minmax,
  3158. },
  3159. {
  3160. .procname = "mount-max",
  3161. .data = &sysctl_mount_max,
  3162. .maxlen = sizeof(unsigned int),
  3163. .mode = 0644,
  3164. .proc_handler = proc_dointvec_minmax,
  3165. .extra1 = SYSCTL_ONE,
  3166. },
  3167. { }
  3168. };
  3169. static struct ctl_table debug_table[] = {
  3170. #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
  3171. {
  3172. .procname = "exception-trace",
  3173. .data = &show_unhandled_signals,
  3174. .maxlen = sizeof(int),
  3175. .mode = 0644,
  3176. .proc_handler = proc_dointvec
  3177. },
  3178. #endif
  3179. #if defined(CONFIG_OPTPROBES)
  3180. {
  3181. .procname = "kprobes-optimization",
  3182. .data = &sysctl_kprobes_optimization,
  3183. .maxlen = sizeof(int),
  3184. .mode = 0644,
  3185. .proc_handler = proc_kprobes_optimization_handler,
  3186. .extra1 = SYSCTL_ZERO,
  3187. .extra2 = SYSCTL_ONE,
  3188. },
  3189. #endif
  3190. { }
  3191. };
  3192. static struct ctl_table dev_table[] = {
  3193. { }
  3194. };
  3195. static struct ctl_table sysctl_base_table[] = {
  3196. {
  3197. .procname = "kernel",
  3198. .mode = 0555,
  3199. .child = kern_table,
  3200. },
  3201. {
  3202. .procname = "vm",
  3203. .mode = 0555,
  3204. .child = vm_table,
  3205. },
  3206. {
  3207. .procname = "fs",
  3208. .mode = 0555,
  3209. .child = fs_table,
  3210. },
  3211. {
  3212. .procname = "debug",
  3213. .mode = 0555,
  3214. .child = debug_table,
  3215. },
  3216. {
  3217. .procname = "dev",
  3218. .mode = 0555,
  3219. .child = dev_table,
  3220. },
  3221. { }
  3222. };
  3223. int __init sysctl_init(void)
  3224. {
  3225. struct ctl_table_header *hdr;
  3226. hdr = register_sysctl_table(sysctl_base_table);
  3227. kmemleak_not_leak(hdr);
  3228. return 0;
  3229. }
  3230. #endif /* CONFIG_SYSCTL */
  3231. /*
  3232. * No sense putting this after each symbol definition, twice,
  3233. * exception granted :-)
  3234. */
  3235. EXPORT_SYMBOL(proc_dointvec);
  3236. EXPORT_SYMBOL(proc_douintvec);
  3237. EXPORT_SYMBOL(proc_dointvec_jiffies);
  3238. EXPORT_SYMBOL(proc_dointvec_minmax);
  3239. EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
  3240. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  3241. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  3242. EXPORT_SYMBOL(proc_dostring);
  3243. EXPORT_SYMBOL(proc_doulongvec_minmax);
  3244. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  3245. EXPORT_SYMBOL(proc_do_large_bitmap);