sysctl.c 77 KB

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