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