sysctl.c 68 KB

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