sysctl.c 69 KB

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