sysctl.c 68 KB

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