sysctl.c 77 KB

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