sysctl.c 68 KB

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