sysctl.c 69 KB

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