sysctl.c 68 KB

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