sysctl.c 69 KB

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