sysctl.c 68 KB

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