sysctl.c 69 KB

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