sysctl.c 69 KB

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