sysctl.c 68 KB

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