sysctl.c 68 KB

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