sysctl.c 69 KB

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