sysctl.c 69 KB

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