sysctl.c 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004
  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. {
  775. .procname = "bootloader_type",
  776. .data = &bootloader_type,
  777. .maxlen = sizeof (int),
  778. .mode = 0444,
  779. .proc_handler = proc_dointvec,
  780. },
  781. {
  782. .procname = "bootloader_version",
  783. .data = &bootloader_version,
  784. .maxlen = sizeof (int),
  785. .mode = 0444,
  786. .proc_handler = proc_dointvec,
  787. },
  788. {
  789. .procname = "kstack_depth_to_print",
  790. .data = &kstack_depth_to_print,
  791. .maxlen = sizeof(int),
  792. .mode = 0644,
  793. .proc_handler = proc_dointvec,
  794. },
  795. {
  796. .procname = "io_delay_type",
  797. .data = &io_delay_type,
  798. .maxlen = sizeof(int),
  799. .mode = 0644,
  800. .proc_handler = proc_dointvec,
  801. },
  802. #endif
  803. #if defined(CONFIG_MMU)
  804. {
  805. .procname = "randomize_va_space",
  806. .data = &randomize_va_space,
  807. .maxlen = sizeof(int),
  808. .mode = 0644,
  809. .proc_handler = proc_dointvec,
  810. },
  811. #endif
  812. #if defined(CONFIG_S390) && defined(CONFIG_SMP)
  813. {
  814. .procname = "spin_retry",
  815. .data = &spin_retry,
  816. .maxlen = sizeof (int),
  817. .mode = 0644,
  818. .proc_handler = proc_dointvec,
  819. },
  820. #endif
  821. #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
  822. {
  823. .procname = "acpi_video_flags",
  824. .data = &acpi_realmode_flags,
  825. .maxlen = sizeof (unsigned long),
  826. .mode = 0644,
  827. .proc_handler = proc_doulongvec_minmax,
  828. },
  829. #endif
  830. #ifdef CONFIG_IA64
  831. {
  832. .procname = "ignore-unaligned-usertrap",
  833. .data = &no_unaligned_warning,
  834. .maxlen = sizeof (int),
  835. .mode = 0644,
  836. .proc_handler = proc_dointvec,
  837. },
  838. {
  839. .procname = "unaligned-dump-stack",
  840. .data = &unaligned_dump_stack,
  841. .maxlen = sizeof (int),
  842. .mode = 0644,
  843. .proc_handler = proc_dointvec,
  844. },
  845. #endif
  846. #ifdef CONFIG_DETECT_HUNG_TASK
  847. {
  848. .procname = "hung_task_panic",
  849. .data = &sysctl_hung_task_panic,
  850. .maxlen = sizeof(int),
  851. .mode = 0644,
  852. .proc_handler = proc_dointvec_minmax,
  853. .extra1 = &zero,
  854. .extra2 = &one,
  855. },
  856. {
  857. .procname = "hung_task_check_count",
  858. .data = &sysctl_hung_task_check_count,
  859. .maxlen = sizeof(unsigned long),
  860. .mode = 0644,
  861. .proc_handler = proc_doulongvec_minmax,
  862. },
  863. {
  864. .procname = "hung_task_timeout_secs",
  865. .data = &sysctl_hung_task_timeout_secs,
  866. .maxlen = sizeof(unsigned long),
  867. .mode = 0644,
  868. .proc_handler = proc_dohung_task_timeout_secs,
  869. },
  870. {
  871. .procname = "hung_task_warnings",
  872. .data = &sysctl_hung_task_warnings,
  873. .maxlen = sizeof(unsigned long),
  874. .mode = 0644,
  875. .proc_handler = proc_doulongvec_minmax,
  876. },
  877. #endif
  878. #ifdef CONFIG_COMPAT
  879. {
  880. .procname = "compat-log",
  881. .data = &compat_log,
  882. .maxlen = sizeof (int),
  883. .mode = 0644,
  884. .proc_handler = proc_dointvec,
  885. },
  886. #endif
  887. #ifdef CONFIG_RT_MUTEXES
  888. {
  889. .procname = "max_lock_depth",
  890. .data = &max_lock_depth,
  891. .maxlen = sizeof(int),
  892. .mode = 0644,
  893. .proc_handler = proc_dointvec,
  894. },
  895. #endif
  896. {
  897. .procname = "poweroff_cmd",
  898. .data = &poweroff_cmd,
  899. .maxlen = POWEROFF_CMD_PATH_LEN,
  900. .mode = 0644,
  901. .proc_handler = proc_dostring,
  902. },
  903. #ifdef CONFIG_KEYS
  904. {
  905. .procname = "keys",
  906. .mode = 0555,
  907. .child = key_sysctls,
  908. },
  909. #endif
  910. #ifdef CONFIG_RCU_TORTURE_TEST
  911. {
  912. .procname = "rcutorture_runnable",
  913. .data = &rcutorture_runnable,
  914. .maxlen = sizeof(int),
  915. .mode = 0644,
  916. .proc_handler = proc_dointvec,
  917. },
  918. #endif
  919. #ifdef CONFIG_PERF_EVENTS
  920. /*
  921. * User-space scripts rely on the existence of this file
  922. * as a feature check for perf_events being enabled.
  923. *
  924. * So it's an ABI, do not remove!
  925. */
  926. {
  927. .procname = "perf_event_paranoid",
  928. .data = &sysctl_perf_event_paranoid,
  929. .maxlen = sizeof(sysctl_perf_event_paranoid),
  930. .mode = 0644,
  931. .proc_handler = proc_dointvec,
  932. },
  933. {
  934. .procname = "perf_event_mlock_kb",
  935. .data = &sysctl_perf_event_mlock,
  936. .maxlen = sizeof(sysctl_perf_event_mlock),
  937. .mode = 0644,
  938. .proc_handler = proc_dointvec,
  939. },
  940. {
  941. .procname = "perf_event_max_sample_rate",
  942. .data = &sysctl_perf_event_sample_rate,
  943. .maxlen = sizeof(sysctl_perf_event_sample_rate),
  944. .mode = 0644,
  945. .proc_handler = perf_proc_update_handler,
  946. },
  947. #endif
  948. #ifdef CONFIG_KMEMCHECK
  949. {
  950. .procname = "kmemcheck",
  951. .data = &kmemcheck_enabled,
  952. .maxlen = sizeof(int),
  953. .mode = 0644,
  954. .proc_handler = proc_dointvec,
  955. },
  956. #endif
  957. #ifdef CONFIG_BLOCK
  958. {
  959. .procname = "blk_iopoll",
  960. .data = &blk_iopoll_enabled,
  961. .maxlen = sizeof(int),
  962. .mode = 0644,
  963. .proc_handler = proc_dointvec,
  964. },
  965. #endif
  966. { }
  967. };
  968. static struct ctl_table vm_table[] = {
  969. {
  970. .procname = "overcommit_memory",
  971. .data = &sysctl_overcommit_memory,
  972. .maxlen = sizeof(sysctl_overcommit_memory),
  973. .mode = 0644,
  974. .proc_handler = proc_dointvec_minmax,
  975. .extra1 = &zero,
  976. .extra2 = &two,
  977. },
  978. {
  979. .procname = "panic_on_oom",
  980. .data = &sysctl_panic_on_oom,
  981. .maxlen = sizeof(sysctl_panic_on_oom),
  982. .mode = 0644,
  983. .proc_handler = proc_dointvec_minmax,
  984. .extra1 = &zero,
  985. .extra2 = &two,
  986. },
  987. {
  988. .procname = "oom_kill_allocating_task",
  989. .data = &sysctl_oom_kill_allocating_task,
  990. .maxlen = sizeof(sysctl_oom_kill_allocating_task),
  991. .mode = 0644,
  992. .proc_handler = proc_dointvec,
  993. },
  994. {
  995. .procname = "oom_dump_tasks",
  996. .data = &sysctl_oom_dump_tasks,
  997. .maxlen = sizeof(sysctl_oom_dump_tasks),
  998. .mode = 0644,
  999. .proc_handler = proc_dointvec,
  1000. },
  1001. {
  1002. .procname = "overcommit_ratio",
  1003. .data = &sysctl_overcommit_ratio,
  1004. .maxlen = sizeof(sysctl_overcommit_ratio),
  1005. .mode = 0644,
  1006. .proc_handler = proc_dointvec,
  1007. },
  1008. {
  1009. .procname = "page-cluster",
  1010. .data = &page_cluster,
  1011. .maxlen = sizeof(int),
  1012. .mode = 0644,
  1013. .proc_handler = proc_dointvec_minmax,
  1014. .extra1 = &zero,
  1015. },
  1016. {
  1017. .procname = "dirty_background_ratio",
  1018. .data = &dirty_background_ratio,
  1019. .maxlen = sizeof(dirty_background_ratio),
  1020. .mode = 0644,
  1021. .proc_handler = dirty_background_ratio_handler,
  1022. .extra1 = &zero,
  1023. .extra2 = &one_hundred,
  1024. },
  1025. {
  1026. .procname = "dirty_background_bytes",
  1027. .data = &dirty_background_bytes,
  1028. .maxlen = sizeof(dirty_background_bytes),
  1029. .mode = 0644,
  1030. .proc_handler = dirty_background_bytes_handler,
  1031. .extra1 = &one_ul,
  1032. },
  1033. {
  1034. .procname = "dirty_ratio",
  1035. .data = &vm_dirty_ratio,
  1036. .maxlen = sizeof(vm_dirty_ratio),
  1037. .mode = 0644,
  1038. .proc_handler = dirty_ratio_handler,
  1039. .extra1 = &zero,
  1040. .extra2 = &one_hundred,
  1041. },
  1042. {
  1043. .procname = "dirty_bytes",
  1044. .data = &vm_dirty_bytes,
  1045. .maxlen = sizeof(vm_dirty_bytes),
  1046. .mode = 0644,
  1047. .proc_handler = dirty_bytes_handler,
  1048. .extra1 = &dirty_bytes_min,
  1049. },
  1050. {
  1051. .procname = "dirty_writeback_centisecs",
  1052. .data = &dirty_writeback_interval,
  1053. .maxlen = sizeof(dirty_writeback_interval),
  1054. .mode = 0644,
  1055. .proc_handler = dirty_writeback_centisecs_handler,
  1056. },
  1057. {
  1058. .procname = "dirty_expire_centisecs",
  1059. .data = &dirty_expire_interval,
  1060. .maxlen = sizeof(dirty_expire_interval),
  1061. .mode = 0644,
  1062. .proc_handler = proc_dointvec_minmax,
  1063. .extra1 = &zero,
  1064. },
  1065. {
  1066. .procname = "nr_pdflush_threads",
  1067. .data = &nr_pdflush_threads,
  1068. .maxlen = sizeof nr_pdflush_threads,
  1069. .mode = 0444 /* read-only*/,
  1070. .proc_handler = proc_dointvec,
  1071. },
  1072. {
  1073. .procname = "swappiness",
  1074. .data = &vm_swappiness,
  1075. .maxlen = sizeof(vm_swappiness),
  1076. .mode = 0644,
  1077. .proc_handler = proc_dointvec_minmax,
  1078. .extra1 = &zero,
  1079. .extra2 = &one_hundred,
  1080. },
  1081. #ifdef CONFIG_HUGETLB_PAGE
  1082. {
  1083. .procname = "nr_hugepages",
  1084. .data = NULL,
  1085. .maxlen = sizeof(unsigned long),
  1086. .mode = 0644,
  1087. .proc_handler = hugetlb_sysctl_handler,
  1088. .extra1 = (void *)&hugetlb_zero,
  1089. .extra2 = (void *)&hugetlb_infinity,
  1090. },
  1091. #ifdef CONFIG_NUMA
  1092. {
  1093. .procname = "nr_hugepages_mempolicy",
  1094. .data = NULL,
  1095. .maxlen = sizeof(unsigned long),
  1096. .mode = 0644,
  1097. .proc_handler = &hugetlb_mempolicy_sysctl_handler,
  1098. .extra1 = (void *)&hugetlb_zero,
  1099. .extra2 = (void *)&hugetlb_infinity,
  1100. },
  1101. #endif
  1102. {
  1103. .procname = "hugetlb_shm_group",
  1104. .data = &sysctl_hugetlb_shm_group,
  1105. .maxlen = sizeof(gid_t),
  1106. .mode = 0644,
  1107. .proc_handler = proc_dointvec,
  1108. },
  1109. {
  1110. .procname = "hugepages_treat_as_movable",
  1111. .data = &hugepages_treat_as_movable,
  1112. .maxlen = sizeof(int),
  1113. .mode = 0644,
  1114. .proc_handler = hugetlb_treat_movable_handler,
  1115. },
  1116. {
  1117. .procname = "nr_overcommit_hugepages",
  1118. .data = NULL,
  1119. .maxlen = sizeof(unsigned long),
  1120. .mode = 0644,
  1121. .proc_handler = hugetlb_overcommit_handler,
  1122. .extra1 = (void *)&hugetlb_zero,
  1123. .extra2 = (void *)&hugetlb_infinity,
  1124. },
  1125. #endif
  1126. {
  1127. .procname = "lowmem_reserve_ratio",
  1128. .data = &sysctl_lowmem_reserve_ratio,
  1129. .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
  1130. .mode = 0644,
  1131. .proc_handler = lowmem_reserve_ratio_sysctl_handler,
  1132. },
  1133. {
  1134. .procname = "drop_caches",
  1135. .data = &sysctl_drop_caches,
  1136. .maxlen = sizeof(int),
  1137. .mode = 0644,
  1138. .proc_handler = drop_caches_sysctl_handler,
  1139. .extra1 = &one,
  1140. .extra2 = &three,
  1141. },
  1142. #ifdef CONFIG_COMPACTION
  1143. {
  1144. .procname = "compact_memory",
  1145. .data = &sysctl_compact_memory,
  1146. .maxlen = sizeof(int),
  1147. .mode = 0200,
  1148. .proc_handler = sysctl_compaction_handler,
  1149. },
  1150. {
  1151. .procname = "extfrag_threshold",
  1152. .data = &sysctl_extfrag_threshold,
  1153. .maxlen = sizeof(int),
  1154. .mode = 0644,
  1155. .proc_handler = sysctl_extfrag_handler,
  1156. .extra1 = &min_extfrag_threshold,
  1157. .extra2 = &max_extfrag_threshold,
  1158. },
  1159. #endif /* CONFIG_COMPACTION */
  1160. {
  1161. .procname = "min_free_kbytes",
  1162. .data = &min_free_kbytes,
  1163. .maxlen = sizeof(min_free_kbytes),
  1164. .mode = 0644,
  1165. .proc_handler = min_free_kbytes_sysctl_handler,
  1166. .extra1 = &zero,
  1167. },
  1168. {
  1169. .procname = "percpu_pagelist_fraction",
  1170. .data = &percpu_pagelist_fraction,
  1171. .maxlen = sizeof(percpu_pagelist_fraction),
  1172. .mode = 0644,
  1173. .proc_handler = percpu_pagelist_fraction_sysctl_handler,
  1174. .extra1 = &min_percpu_pagelist_fract,
  1175. },
  1176. #ifdef CONFIG_MMU
  1177. {
  1178. .procname = "max_map_count",
  1179. .data = &sysctl_max_map_count,
  1180. .maxlen = sizeof(sysctl_max_map_count),
  1181. .mode = 0644,
  1182. .proc_handler = proc_dointvec_minmax,
  1183. .extra1 = &zero,
  1184. },
  1185. #else
  1186. {
  1187. .procname = "nr_trim_pages",
  1188. .data = &sysctl_nr_trim_pages,
  1189. .maxlen = sizeof(sysctl_nr_trim_pages),
  1190. .mode = 0644,
  1191. .proc_handler = proc_dointvec_minmax,
  1192. .extra1 = &zero,
  1193. },
  1194. #endif
  1195. {
  1196. .procname = "laptop_mode",
  1197. .data = &laptop_mode,
  1198. .maxlen = sizeof(laptop_mode),
  1199. .mode = 0644,
  1200. .proc_handler = proc_dointvec_jiffies,
  1201. },
  1202. {
  1203. .procname = "block_dump",
  1204. .data = &block_dump,
  1205. .maxlen = sizeof(block_dump),
  1206. .mode = 0644,
  1207. .proc_handler = proc_dointvec,
  1208. .extra1 = &zero,
  1209. },
  1210. {
  1211. .procname = "vfs_cache_pressure",
  1212. .data = &sysctl_vfs_cache_pressure,
  1213. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  1214. .mode = 0644,
  1215. .proc_handler = proc_dointvec,
  1216. .extra1 = &zero,
  1217. },
  1218. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  1219. {
  1220. .procname = "legacy_va_layout",
  1221. .data = &sysctl_legacy_va_layout,
  1222. .maxlen = sizeof(sysctl_legacy_va_layout),
  1223. .mode = 0644,
  1224. .proc_handler = proc_dointvec,
  1225. .extra1 = &zero,
  1226. },
  1227. #endif
  1228. #ifdef CONFIG_NUMA
  1229. {
  1230. .procname = "zone_reclaim_mode",
  1231. .data = &zone_reclaim_mode,
  1232. .maxlen = sizeof(zone_reclaim_mode),
  1233. .mode = 0644,
  1234. .proc_handler = proc_dointvec,
  1235. .extra1 = &zero,
  1236. },
  1237. {
  1238. .procname = "min_unmapped_ratio",
  1239. .data = &sysctl_min_unmapped_ratio,
  1240. .maxlen = sizeof(sysctl_min_unmapped_ratio),
  1241. .mode = 0644,
  1242. .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
  1243. .extra1 = &zero,
  1244. .extra2 = &one_hundred,
  1245. },
  1246. {
  1247. .procname = "min_slab_ratio",
  1248. .data = &sysctl_min_slab_ratio,
  1249. .maxlen = sizeof(sysctl_min_slab_ratio),
  1250. .mode = 0644,
  1251. .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
  1252. .extra1 = &zero,
  1253. .extra2 = &one_hundred,
  1254. },
  1255. #endif
  1256. #ifdef CONFIG_SMP
  1257. {
  1258. .procname = "stat_interval",
  1259. .data = &sysctl_stat_interval,
  1260. .maxlen = sizeof(sysctl_stat_interval),
  1261. .mode = 0644,
  1262. .proc_handler = proc_dointvec_jiffies,
  1263. },
  1264. #endif
  1265. #ifdef CONFIG_MMU
  1266. {
  1267. .procname = "mmap_min_addr",
  1268. .data = &dac_mmap_min_addr,
  1269. .maxlen = sizeof(unsigned long),
  1270. .mode = 0644,
  1271. .proc_handler = mmap_min_addr_handler,
  1272. },
  1273. #endif
  1274. #ifdef CONFIG_NUMA
  1275. {
  1276. .procname = "numa_zonelist_order",
  1277. .data = &numa_zonelist_order,
  1278. .maxlen = NUMA_ZONELIST_ORDER_LEN,
  1279. .mode = 0644,
  1280. .proc_handler = numa_zonelist_order_handler,
  1281. },
  1282. #endif
  1283. #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
  1284. (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
  1285. {
  1286. .procname = "vdso_enabled",
  1287. .data = &vdso_enabled,
  1288. .maxlen = sizeof(vdso_enabled),
  1289. .mode = 0644,
  1290. .proc_handler = proc_dointvec,
  1291. .extra1 = &zero,
  1292. },
  1293. #endif
  1294. #ifdef CONFIG_HIGHMEM
  1295. {
  1296. .procname = "highmem_is_dirtyable",
  1297. .data = &vm_highmem_is_dirtyable,
  1298. .maxlen = sizeof(vm_highmem_is_dirtyable),
  1299. .mode = 0644,
  1300. .proc_handler = proc_dointvec_minmax,
  1301. .extra1 = &zero,
  1302. .extra2 = &one,
  1303. },
  1304. #endif
  1305. {
  1306. .procname = "scan_unevictable_pages",
  1307. .data = &scan_unevictable_pages,
  1308. .maxlen = sizeof(scan_unevictable_pages),
  1309. .mode = 0644,
  1310. .proc_handler = scan_unevictable_handler,
  1311. },
  1312. #ifdef CONFIG_MEMORY_FAILURE
  1313. {
  1314. .procname = "memory_failure_early_kill",
  1315. .data = &sysctl_memory_failure_early_kill,
  1316. .maxlen = sizeof(sysctl_memory_failure_early_kill),
  1317. .mode = 0644,
  1318. .proc_handler = proc_dointvec_minmax,
  1319. .extra1 = &zero,
  1320. .extra2 = &one,
  1321. },
  1322. {
  1323. .procname = "memory_failure_recovery",
  1324. .data = &sysctl_memory_failure_recovery,
  1325. .maxlen = sizeof(sysctl_memory_failure_recovery),
  1326. .mode = 0644,
  1327. .proc_handler = proc_dointvec_minmax,
  1328. .extra1 = &zero,
  1329. .extra2 = &one,
  1330. },
  1331. #endif
  1332. { }
  1333. };
  1334. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1335. static struct ctl_table binfmt_misc_table[] = {
  1336. { }
  1337. };
  1338. #endif
  1339. static struct ctl_table fs_table[] = {
  1340. {
  1341. .procname = "inode-nr",
  1342. .data = &inodes_stat,
  1343. .maxlen = 2*sizeof(int),
  1344. .mode = 0444,
  1345. .proc_handler = proc_nr_inodes,
  1346. },
  1347. {
  1348. .procname = "inode-state",
  1349. .data = &inodes_stat,
  1350. .maxlen = 7*sizeof(int),
  1351. .mode = 0444,
  1352. .proc_handler = proc_nr_inodes,
  1353. },
  1354. {
  1355. .procname = "file-nr",
  1356. .data = &files_stat,
  1357. .maxlen = sizeof(files_stat),
  1358. .mode = 0444,
  1359. .proc_handler = proc_nr_files,
  1360. },
  1361. {
  1362. .procname = "file-max",
  1363. .data = &files_stat.max_files,
  1364. .maxlen = sizeof(files_stat.max_files),
  1365. .mode = 0644,
  1366. .proc_handler = proc_doulongvec_minmax,
  1367. },
  1368. {
  1369. .procname = "nr_open",
  1370. .data = &sysctl_nr_open,
  1371. .maxlen = sizeof(int),
  1372. .mode = 0644,
  1373. .proc_handler = proc_dointvec_minmax,
  1374. .extra1 = &sysctl_nr_open_min,
  1375. .extra2 = &sysctl_nr_open_max,
  1376. },
  1377. {
  1378. .procname = "dentry-state",
  1379. .data = &dentry_stat,
  1380. .maxlen = 6*sizeof(int),
  1381. .mode = 0444,
  1382. .proc_handler = proc_nr_dentry,
  1383. },
  1384. {
  1385. .procname = "overflowuid",
  1386. .data = &fs_overflowuid,
  1387. .maxlen = sizeof(int),
  1388. .mode = 0644,
  1389. .proc_handler = proc_dointvec_minmax,
  1390. .extra1 = &minolduid,
  1391. .extra2 = &maxolduid,
  1392. },
  1393. {
  1394. .procname = "overflowgid",
  1395. .data = &fs_overflowgid,
  1396. .maxlen = sizeof(int),
  1397. .mode = 0644,
  1398. .proc_handler = proc_dointvec_minmax,
  1399. .extra1 = &minolduid,
  1400. .extra2 = &maxolduid,
  1401. },
  1402. #ifdef CONFIG_FILE_LOCKING
  1403. {
  1404. .procname = "leases-enable",
  1405. .data = &leases_enable,
  1406. .maxlen = sizeof(int),
  1407. .mode = 0644,
  1408. .proc_handler = proc_dointvec,
  1409. },
  1410. #endif
  1411. #ifdef CONFIG_DNOTIFY
  1412. {
  1413. .procname = "dir-notify-enable",
  1414. .data = &dir_notify_enable,
  1415. .maxlen = sizeof(int),
  1416. .mode = 0644,
  1417. .proc_handler = proc_dointvec,
  1418. },
  1419. #endif
  1420. #ifdef CONFIG_MMU
  1421. #ifdef CONFIG_FILE_LOCKING
  1422. {
  1423. .procname = "lease-break-time",
  1424. .data = &lease_break_time,
  1425. .maxlen = sizeof(int),
  1426. .mode = 0644,
  1427. .proc_handler = proc_dointvec,
  1428. },
  1429. #endif
  1430. #ifdef CONFIG_AIO
  1431. {
  1432. .procname = "aio-nr",
  1433. .data = &aio_nr,
  1434. .maxlen = sizeof(aio_nr),
  1435. .mode = 0444,
  1436. .proc_handler = proc_doulongvec_minmax,
  1437. },
  1438. {
  1439. .procname = "aio-max-nr",
  1440. .data = &aio_max_nr,
  1441. .maxlen = sizeof(aio_max_nr),
  1442. .mode = 0644,
  1443. .proc_handler = proc_doulongvec_minmax,
  1444. },
  1445. #endif /* CONFIG_AIO */
  1446. #ifdef CONFIG_INOTIFY_USER
  1447. {
  1448. .procname = "inotify",
  1449. .mode = 0555,
  1450. .child = inotify_table,
  1451. },
  1452. #endif
  1453. #ifdef CONFIG_EPOLL
  1454. {
  1455. .procname = "epoll",
  1456. .mode = 0555,
  1457. .child = epoll_table,
  1458. },
  1459. #endif
  1460. #endif
  1461. {
  1462. .procname = "suid_dumpable",
  1463. .data = &suid_dumpable,
  1464. .maxlen = sizeof(int),
  1465. .mode = 0644,
  1466. .proc_handler = proc_dointvec_minmax,
  1467. .extra1 = &zero,
  1468. .extra2 = &two,
  1469. },
  1470. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1471. {
  1472. .procname = "binfmt_misc",
  1473. .mode = 0555,
  1474. .child = binfmt_misc_table,
  1475. },
  1476. #endif
  1477. {
  1478. .procname = "pipe-max-size",
  1479. .data = &pipe_max_size,
  1480. .maxlen = sizeof(int),
  1481. .mode = 0644,
  1482. .proc_handler = &pipe_proc_fn,
  1483. .extra1 = &pipe_min_size,
  1484. },
  1485. { }
  1486. };
  1487. static struct ctl_table debug_table[] = {
  1488. #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
  1489. defined(CONFIG_S390) || defined(CONFIG_TILE)
  1490. {
  1491. .procname = "exception-trace",
  1492. .data = &show_unhandled_signals,
  1493. .maxlen = sizeof(int),
  1494. .mode = 0644,
  1495. .proc_handler = proc_dointvec
  1496. },
  1497. #endif
  1498. #if defined(CONFIG_OPTPROBES)
  1499. {
  1500. .procname = "kprobes-optimization",
  1501. .data = &sysctl_kprobes_optimization,
  1502. .maxlen = sizeof(int),
  1503. .mode = 0644,
  1504. .proc_handler = proc_kprobes_optimization_handler,
  1505. .extra1 = &zero,
  1506. .extra2 = &one,
  1507. },
  1508. #endif
  1509. { }
  1510. };
  1511. static struct ctl_table dev_table[] = {
  1512. { }
  1513. };
  1514. static DEFINE_SPINLOCK(sysctl_lock);
  1515. /* called under sysctl_lock */
  1516. static int use_table(struct ctl_table_header *p)
  1517. {
  1518. if (unlikely(p->unregistering))
  1519. return 0;
  1520. p->used++;
  1521. return 1;
  1522. }
  1523. /* called under sysctl_lock */
  1524. static void unuse_table(struct ctl_table_header *p)
  1525. {
  1526. if (!--p->used)
  1527. if (unlikely(p->unregistering))
  1528. complete(p->unregistering);
  1529. }
  1530. /* called under sysctl_lock, will reacquire if has to wait */
  1531. static void start_unregistering(struct ctl_table_header *p)
  1532. {
  1533. /*
  1534. * if p->used is 0, nobody will ever touch that entry again;
  1535. * we'll eliminate all paths to it before dropping sysctl_lock
  1536. */
  1537. if (unlikely(p->used)) {
  1538. struct completion wait;
  1539. init_completion(&wait);
  1540. p->unregistering = &wait;
  1541. spin_unlock(&sysctl_lock);
  1542. wait_for_completion(&wait);
  1543. spin_lock(&sysctl_lock);
  1544. } else {
  1545. /* anything non-NULL; we'll never dereference it */
  1546. p->unregistering = ERR_PTR(-EINVAL);
  1547. }
  1548. /*
  1549. * do not remove from the list until nobody holds it; walking the
  1550. * list in do_sysctl() relies on that.
  1551. */
  1552. list_del_init(&p->ctl_entry);
  1553. }
  1554. void sysctl_head_get(struct ctl_table_header *head)
  1555. {
  1556. spin_lock(&sysctl_lock);
  1557. head->count++;
  1558. spin_unlock(&sysctl_lock);
  1559. }
  1560. void sysctl_head_put(struct ctl_table_header *head)
  1561. {
  1562. spin_lock(&sysctl_lock);
  1563. if (!--head->count)
  1564. kfree_rcu(head, rcu);
  1565. spin_unlock(&sysctl_lock);
  1566. }
  1567. struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
  1568. {
  1569. if (!head)
  1570. BUG();
  1571. spin_lock(&sysctl_lock);
  1572. if (!use_table(head))
  1573. head = ERR_PTR(-ENOENT);
  1574. spin_unlock(&sysctl_lock);
  1575. return head;
  1576. }
  1577. void sysctl_head_finish(struct ctl_table_header *head)
  1578. {
  1579. if (!head)
  1580. return;
  1581. spin_lock(&sysctl_lock);
  1582. unuse_table(head);
  1583. spin_unlock(&sysctl_lock);
  1584. }
  1585. static struct ctl_table_set *
  1586. lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
  1587. {
  1588. struct ctl_table_set *set = &root->default_set;
  1589. if (root->lookup)
  1590. set = root->lookup(root, namespaces);
  1591. return set;
  1592. }
  1593. static struct list_head *
  1594. lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
  1595. {
  1596. struct ctl_table_set *set = lookup_header_set(root, namespaces);
  1597. return &set->list;
  1598. }
  1599. struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
  1600. struct ctl_table_header *prev)
  1601. {
  1602. struct ctl_table_root *root;
  1603. struct list_head *header_list;
  1604. struct ctl_table_header *head;
  1605. struct list_head *tmp;
  1606. spin_lock(&sysctl_lock);
  1607. if (prev) {
  1608. head = prev;
  1609. tmp = &prev->ctl_entry;
  1610. unuse_table(prev);
  1611. goto next;
  1612. }
  1613. tmp = &root_table_header.ctl_entry;
  1614. for (;;) {
  1615. head = list_entry(tmp, struct ctl_table_header, ctl_entry);
  1616. if (!use_table(head))
  1617. goto next;
  1618. spin_unlock(&sysctl_lock);
  1619. return head;
  1620. next:
  1621. root = head->root;
  1622. tmp = tmp->next;
  1623. header_list = lookup_header_list(root, namespaces);
  1624. if (tmp != header_list)
  1625. continue;
  1626. do {
  1627. root = list_entry(root->root_list.next,
  1628. struct ctl_table_root, root_list);
  1629. if (root == &sysctl_table_root)
  1630. goto out;
  1631. header_list = lookup_header_list(root, namespaces);
  1632. } while (list_empty(header_list));
  1633. tmp = header_list->next;
  1634. }
  1635. out:
  1636. spin_unlock(&sysctl_lock);
  1637. return NULL;
  1638. }
  1639. struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
  1640. {
  1641. return __sysctl_head_next(current->nsproxy, prev);
  1642. }
  1643. void register_sysctl_root(struct ctl_table_root *root)
  1644. {
  1645. spin_lock(&sysctl_lock);
  1646. list_add_tail(&root->root_list, &sysctl_table_root.root_list);
  1647. spin_unlock(&sysctl_lock);
  1648. }
  1649. /*
  1650. * sysctl_perm does NOT grant the superuser all rights automatically, because
  1651. * some sysctl variables are readonly even to root.
  1652. */
  1653. static int test_perm(int mode, int op)
  1654. {
  1655. if (!current_euid())
  1656. mode >>= 6;
  1657. else if (in_egroup_p(0))
  1658. mode >>= 3;
  1659. if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
  1660. return 0;
  1661. return -EACCES;
  1662. }
  1663. int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
  1664. {
  1665. int mode;
  1666. if (root->permissions)
  1667. mode = root->permissions(root, current->nsproxy, table);
  1668. else
  1669. mode = table->mode;
  1670. return test_perm(mode, op);
  1671. }
  1672. static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
  1673. {
  1674. for (; table->procname; table++) {
  1675. table->parent = parent;
  1676. if (table->child)
  1677. sysctl_set_parent(table, table->child);
  1678. }
  1679. }
  1680. static __init int sysctl_init(void)
  1681. {
  1682. sysctl_set_parent(NULL, root_table);
  1683. #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
  1684. sysctl_check_table(current->nsproxy, root_table);
  1685. #endif
  1686. return 0;
  1687. }
  1688. core_initcall(sysctl_init);
  1689. static struct ctl_table *is_branch_in(struct ctl_table *branch,
  1690. struct ctl_table *table)
  1691. {
  1692. struct ctl_table *p;
  1693. const char *s = branch->procname;
  1694. /* branch should have named subdirectory as its first element */
  1695. if (!s || !branch->child)
  1696. return NULL;
  1697. /* ... and nothing else */
  1698. if (branch[1].procname)
  1699. return NULL;
  1700. /* table should contain subdirectory with the same name */
  1701. for (p = table; p->procname; p++) {
  1702. if (!p->child)
  1703. continue;
  1704. if (p->procname && strcmp(p->procname, s) == 0)
  1705. return p;
  1706. }
  1707. return NULL;
  1708. }
  1709. /* see if attaching q to p would be an improvement */
  1710. static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
  1711. {
  1712. struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
  1713. struct ctl_table *next;
  1714. int is_better = 0;
  1715. int not_in_parent = !p->attached_by;
  1716. while ((next = is_branch_in(by, to)) != NULL) {
  1717. if (by == q->attached_by)
  1718. is_better = 1;
  1719. if (to == p->attached_by)
  1720. not_in_parent = 1;
  1721. by = by->child;
  1722. to = next->child;
  1723. }
  1724. if (is_better && not_in_parent) {
  1725. q->attached_by = by;
  1726. q->attached_to = to;
  1727. q->parent = p;
  1728. }
  1729. }
  1730. /**
  1731. * __register_sysctl_paths - register a sysctl hierarchy
  1732. * @root: List of sysctl headers to register on
  1733. * @namespaces: Data to compute which lists of sysctl entries are visible
  1734. * @path: The path to the directory the sysctl table is in.
  1735. * @table: the top-level table structure
  1736. *
  1737. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1738. * array. A completely 0 filled entry terminates the table.
  1739. *
  1740. * The members of the &struct ctl_table structure are used as follows:
  1741. *
  1742. * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
  1743. * enter a sysctl file
  1744. *
  1745. * data - a pointer to data for use by proc_handler
  1746. *
  1747. * maxlen - the maximum size in bytes of the data
  1748. *
  1749. * mode - the file permissions for the /proc/sys file, and for sysctl(2)
  1750. *
  1751. * child - a pointer to the child sysctl table if this entry is a directory, or
  1752. * %NULL.
  1753. *
  1754. * proc_handler - the text handler routine (described below)
  1755. *
  1756. * de - for internal use by the sysctl routines
  1757. *
  1758. * extra1, extra2 - extra pointers usable by the proc handler routines
  1759. *
  1760. * Leaf nodes in the sysctl tree will be represented by a single file
  1761. * under /proc; non-leaf nodes will be represented by directories.
  1762. *
  1763. * sysctl(2) can automatically manage read and write requests through
  1764. * the sysctl table. The data and maxlen fields of the ctl_table
  1765. * struct enable minimal validation of the values being written to be
  1766. * performed, and the mode field allows minimal authentication.
  1767. *
  1768. * There must be a proc_handler routine for any terminal nodes
  1769. * mirrored under /proc/sys (non-terminals are handled by a built-in
  1770. * directory handler). Several default handlers are available to
  1771. * cover common cases -
  1772. *
  1773. * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
  1774. * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
  1775. * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
  1776. *
  1777. * It is the handler's job to read the input buffer from user memory
  1778. * and process it. The handler should return 0 on success.
  1779. *
  1780. * This routine returns %NULL on a failure to register, and a pointer
  1781. * to the table header on success.
  1782. */
  1783. struct ctl_table_header *__register_sysctl_paths(
  1784. struct ctl_table_root *root,
  1785. struct nsproxy *namespaces,
  1786. const struct ctl_path *path, struct ctl_table *table)
  1787. {
  1788. struct ctl_table_header *header;
  1789. struct ctl_table *new, **prevp;
  1790. unsigned int n, npath;
  1791. struct ctl_table_set *set;
  1792. /* Count the path components */
  1793. for (npath = 0; path[npath].procname; ++npath)
  1794. ;
  1795. /*
  1796. * For each path component, allocate a 2-element ctl_table array.
  1797. * The first array element will be filled with the sysctl entry
  1798. * for this, the second will be the sentinel (procname == 0).
  1799. *
  1800. * We allocate everything in one go so that we don't have to
  1801. * worry about freeing additional memory in unregister_sysctl_table.
  1802. */
  1803. header = kzalloc(sizeof(struct ctl_table_header) +
  1804. (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
  1805. if (!header)
  1806. return NULL;
  1807. new = (struct ctl_table *) (header + 1);
  1808. /* Now connect the dots */
  1809. prevp = &header->ctl_table;
  1810. for (n = 0; n < npath; ++n, ++path) {
  1811. /* Copy the procname */
  1812. new->procname = path->procname;
  1813. new->mode = 0555;
  1814. *prevp = new;
  1815. prevp = &new->child;
  1816. new += 2;
  1817. }
  1818. *prevp = table;
  1819. header->ctl_table_arg = table;
  1820. INIT_LIST_HEAD(&header->ctl_entry);
  1821. header->used = 0;
  1822. header->unregistering = NULL;
  1823. header->root = root;
  1824. sysctl_set_parent(NULL, header->ctl_table);
  1825. header->count = 1;
  1826. #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
  1827. if (sysctl_check_table(namespaces, header->ctl_table)) {
  1828. kfree(header);
  1829. return NULL;
  1830. }
  1831. #endif
  1832. spin_lock(&sysctl_lock);
  1833. header->set = lookup_header_set(root, namespaces);
  1834. header->attached_by = header->ctl_table;
  1835. header->attached_to = root_table;
  1836. header->parent = &root_table_header;
  1837. for (set = header->set; set; set = set->parent) {
  1838. struct ctl_table_header *p;
  1839. list_for_each_entry(p, &set->list, ctl_entry) {
  1840. if (p->unregistering)
  1841. continue;
  1842. try_attach(p, header);
  1843. }
  1844. }
  1845. header->parent->count++;
  1846. list_add_tail(&header->ctl_entry, &header->set->list);
  1847. spin_unlock(&sysctl_lock);
  1848. return header;
  1849. }
  1850. /**
  1851. * register_sysctl_table_path - register a sysctl table hierarchy
  1852. * @path: The path to the directory the sysctl table is in.
  1853. * @table: the top-level table structure
  1854. *
  1855. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1856. * array. A completely 0 filled entry terminates the table.
  1857. *
  1858. * See __register_sysctl_paths for more details.
  1859. */
  1860. struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
  1861. struct ctl_table *table)
  1862. {
  1863. return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
  1864. path, table);
  1865. }
  1866. /**
  1867. * register_sysctl_table - register a sysctl table hierarchy
  1868. * @table: the top-level table structure
  1869. *
  1870. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1871. * array. A completely 0 filled entry terminates the table.
  1872. *
  1873. * See register_sysctl_paths for more details.
  1874. */
  1875. struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
  1876. {
  1877. static const struct ctl_path null_path[] = { {} };
  1878. return register_sysctl_paths(null_path, table);
  1879. }
  1880. /**
  1881. * unregister_sysctl_table - unregister a sysctl table hierarchy
  1882. * @header: the header returned from register_sysctl_table
  1883. *
  1884. * Unregisters the sysctl table and all children. proc entries may not
  1885. * actually be removed until they are no longer used by anyone.
  1886. */
  1887. void unregister_sysctl_table(struct ctl_table_header * header)
  1888. {
  1889. might_sleep();
  1890. if (header == NULL)
  1891. return;
  1892. spin_lock(&sysctl_lock);
  1893. start_unregistering(header);
  1894. if (!--header->parent->count) {
  1895. WARN_ON(1);
  1896. kfree_rcu(header->parent, rcu);
  1897. }
  1898. if (!--header->count)
  1899. kfree_rcu(header, rcu);
  1900. spin_unlock(&sysctl_lock);
  1901. }
  1902. int sysctl_is_seen(struct ctl_table_header *p)
  1903. {
  1904. struct ctl_table_set *set = p->set;
  1905. int res;
  1906. spin_lock(&sysctl_lock);
  1907. if (p->unregistering)
  1908. res = 0;
  1909. else if (!set->is_seen)
  1910. res = 1;
  1911. else
  1912. res = set->is_seen(set);
  1913. spin_unlock(&sysctl_lock);
  1914. return res;
  1915. }
  1916. void setup_sysctl_set(struct ctl_table_set *p,
  1917. struct ctl_table_set *parent,
  1918. int (*is_seen)(struct ctl_table_set *))
  1919. {
  1920. INIT_LIST_HEAD(&p->list);
  1921. p->parent = parent ? parent : &sysctl_table_root.default_set;
  1922. p->is_seen = is_seen;
  1923. }
  1924. #else /* !CONFIG_SYSCTL */
  1925. struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
  1926. {
  1927. return NULL;
  1928. }
  1929. struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
  1930. struct ctl_table *table)
  1931. {
  1932. return NULL;
  1933. }
  1934. void unregister_sysctl_table(struct ctl_table_header * table)
  1935. {
  1936. }
  1937. void setup_sysctl_set(struct ctl_table_set *p,
  1938. struct ctl_table_set *parent,
  1939. int (*is_seen)(struct ctl_table_set *))
  1940. {
  1941. }
  1942. void sysctl_head_put(struct ctl_table_header *head)
  1943. {
  1944. }
  1945. #endif /* CONFIG_SYSCTL */
  1946. /*
  1947. * /proc/sys support
  1948. */
  1949. #ifdef CONFIG_PROC_SYSCTL
  1950. static int _proc_do_string(void* data, int maxlen, int write,
  1951. void __user *buffer,
  1952. size_t *lenp, loff_t *ppos)
  1953. {
  1954. size_t len;
  1955. char __user *p;
  1956. char c;
  1957. if (!data || !maxlen || !*lenp) {
  1958. *lenp = 0;
  1959. return 0;
  1960. }
  1961. if (write) {
  1962. len = 0;
  1963. p = buffer;
  1964. while (len < *lenp) {
  1965. if (get_user(c, p++))
  1966. return -EFAULT;
  1967. if (c == 0 || c == '\n')
  1968. break;
  1969. len++;
  1970. }
  1971. if (len >= maxlen)
  1972. len = maxlen-1;
  1973. if(copy_from_user(data, buffer, len))
  1974. return -EFAULT;
  1975. ((char *) data)[len] = 0;
  1976. *ppos += *lenp;
  1977. } else {
  1978. len = strlen(data);
  1979. if (len > maxlen)
  1980. len = maxlen;
  1981. if (*ppos > len) {
  1982. *lenp = 0;
  1983. return 0;
  1984. }
  1985. data += *ppos;
  1986. len -= *ppos;
  1987. if (len > *lenp)
  1988. len = *lenp;
  1989. if (len)
  1990. if(copy_to_user(buffer, data, len))
  1991. return -EFAULT;
  1992. if (len < *lenp) {
  1993. if(put_user('\n', ((char __user *) buffer) + len))
  1994. return -EFAULT;
  1995. len++;
  1996. }
  1997. *lenp = len;
  1998. *ppos += len;
  1999. }
  2000. return 0;
  2001. }
  2002. /**
  2003. * proc_dostring - read a string sysctl
  2004. * @table: the sysctl table
  2005. * @write: %TRUE if this is a write to the sysctl file
  2006. * @buffer: the user buffer
  2007. * @lenp: the size of the user buffer
  2008. * @ppos: file position
  2009. *
  2010. * Reads/writes a string from/to the user buffer. If the kernel
  2011. * buffer provided is not large enough to hold the string, the
  2012. * string is truncated. The copied string is %NULL-terminated.
  2013. * If the string is being read by the user process, it is copied
  2014. * and a newline '\n' is added. It is truncated if the buffer is
  2015. * not large enough.
  2016. *
  2017. * Returns 0 on success.
  2018. */
  2019. int proc_dostring(struct ctl_table *table, int write,
  2020. void __user *buffer, size_t *lenp, loff_t *ppos)
  2021. {
  2022. return _proc_do_string(table->data, table->maxlen, write,
  2023. buffer, lenp, ppos);
  2024. }
  2025. static size_t proc_skip_spaces(char **buf)
  2026. {
  2027. size_t ret;
  2028. char *tmp = skip_spaces(*buf);
  2029. ret = tmp - *buf;
  2030. *buf = tmp;
  2031. return ret;
  2032. }
  2033. static void proc_skip_char(char **buf, size_t *size, const char v)
  2034. {
  2035. while (*size) {
  2036. if (**buf != v)
  2037. break;
  2038. (*size)--;
  2039. (*buf)++;
  2040. }
  2041. }
  2042. #define TMPBUFLEN 22
  2043. /**
  2044. * proc_get_long - reads an ASCII formatted integer from a user buffer
  2045. *
  2046. * @buf: a kernel buffer
  2047. * @size: size of the kernel buffer
  2048. * @val: this is where the number will be stored
  2049. * @neg: set to %TRUE if number is negative
  2050. * @perm_tr: a vector which contains the allowed trailers
  2051. * @perm_tr_len: size of the perm_tr vector
  2052. * @tr: pointer to store the trailer character
  2053. *
  2054. * In case of success %0 is returned and @buf and @size are updated with
  2055. * the amount of bytes read. If @tr is non-NULL and a trailing
  2056. * character exists (size is non-zero after returning from this
  2057. * function), @tr is updated with the trailing character.
  2058. */
  2059. static int proc_get_long(char **buf, size_t *size,
  2060. unsigned long *val, bool *neg,
  2061. const char *perm_tr, unsigned perm_tr_len, char *tr)
  2062. {
  2063. int len;
  2064. char *p, tmp[TMPBUFLEN];
  2065. if (!*size)
  2066. return -EINVAL;
  2067. len = *size;
  2068. if (len > TMPBUFLEN - 1)
  2069. len = TMPBUFLEN - 1;
  2070. memcpy(tmp, *buf, len);
  2071. tmp[len] = 0;
  2072. p = tmp;
  2073. if (*p == '-' && *size > 1) {
  2074. *neg = true;
  2075. p++;
  2076. } else
  2077. *neg = false;
  2078. if (!isdigit(*p))
  2079. return -EINVAL;
  2080. *val = simple_strtoul(p, &p, 0);
  2081. len = p - tmp;
  2082. /* We don't know if the next char is whitespace thus we may accept
  2083. * invalid integers (e.g. 1234...a) or two integers instead of one
  2084. * (e.g. 123...1). So lets not allow such large numbers. */
  2085. if (len == TMPBUFLEN - 1)
  2086. return -EINVAL;
  2087. if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
  2088. return -EINVAL;
  2089. if (tr && (len < *size))
  2090. *tr = *p;
  2091. *buf += len;
  2092. *size -= len;
  2093. return 0;
  2094. }
  2095. /**
  2096. * proc_put_long - converts an integer to a decimal ASCII formatted string
  2097. *
  2098. * @buf: the user buffer
  2099. * @size: the size of the user buffer
  2100. * @val: the integer to be converted
  2101. * @neg: sign of the number, %TRUE for negative
  2102. *
  2103. * In case of success %0 is returned and @buf and @size are updated with
  2104. * the amount of bytes written.
  2105. */
  2106. static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
  2107. bool neg)
  2108. {
  2109. int len;
  2110. char tmp[TMPBUFLEN], *p = tmp;
  2111. sprintf(p, "%s%lu", neg ? "-" : "", val);
  2112. len = strlen(tmp);
  2113. if (len > *size)
  2114. len = *size;
  2115. if (copy_to_user(*buf, tmp, len))
  2116. return -EFAULT;
  2117. *size -= len;
  2118. *buf += len;
  2119. return 0;
  2120. }
  2121. #undef TMPBUFLEN
  2122. static int proc_put_char(void __user **buf, size_t *size, char c)
  2123. {
  2124. if (*size) {
  2125. char __user **buffer = (char __user **)buf;
  2126. if (put_user(c, *buffer))
  2127. return -EFAULT;
  2128. (*size)--, (*buffer)++;
  2129. *buf = *buffer;
  2130. }
  2131. return 0;
  2132. }
  2133. static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
  2134. int *valp,
  2135. int write, void *data)
  2136. {
  2137. if (write) {
  2138. *valp = *negp ? -*lvalp : *lvalp;
  2139. } else {
  2140. int val = *valp;
  2141. if (val < 0) {
  2142. *negp = true;
  2143. *lvalp = (unsigned long)-val;
  2144. } else {
  2145. *negp = false;
  2146. *lvalp = (unsigned long)val;
  2147. }
  2148. }
  2149. return 0;
  2150. }
  2151. static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
  2152. static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
  2153. int write, void __user *buffer,
  2154. size_t *lenp, loff_t *ppos,
  2155. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  2156. int write, void *data),
  2157. void *data)
  2158. {
  2159. int *i, vleft, first = 1, err = 0;
  2160. unsigned long page = 0;
  2161. size_t left;
  2162. char *kbuf;
  2163. if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
  2164. *lenp = 0;
  2165. return 0;
  2166. }
  2167. i = (int *) tbl_data;
  2168. vleft = table->maxlen / sizeof(*i);
  2169. left = *lenp;
  2170. if (!conv)
  2171. conv = do_proc_dointvec_conv;
  2172. if (write) {
  2173. if (left > PAGE_SIZE - 1)
  2174. left = PAGE_SIZE - 1;
  2175. page = __get_free_page(GFP_TEMPORARY);
  2176. kbuf = (char *) page;
  2177. if (!kbuf)
  2178. return -ENOMEM;
  2179. if (copy_from_user(kbuf, buffer, left)) {
  2180. err = -EFAULT;
  2181. goto free;
  2182. }
  2183. kbuf[left] = 0;
  2184. }
  2185. for (; left && vleft--; i++, first=0) {
  2186. unsigned long lval;
  2187. bool neg;
  2188. if (write) {
  2189. left -= proc_skip_spaces(&kbuf);
  2190. if (!left)
  2191. break;
  2192. err = proc_get_long(&kbuf, &left, &lval, &neg,
  2193. proc_wspace_sep,
  2194. sizeof(proc_wspace_sep), NULL);
  2195. if (err)
  2196. break;
  2197. if (conv(&neg, &lval, i, 1, data)) {
  2198. err = -EINVAL;
  2199. break;
  2200. }
  2201. } else {
  2202. if (conv(&neg, &lval, i, 0, data)) {
  2203. err = -EINVAL;
  2204. break;
  2205. }
  2206. if (!first)
  2207. err = proc_put_char(&buffer, &left, '\t');
  2208. if (err)
  2209. break;
  2210. err = proc_put_long(&buffer, &left, lval, neg);
  2211. if (err)
  2212. break;
  2213. }
  2214. }
  2215. if (!write && !first && left && !err)
  2216. err = proc_put_char(&buffer, &left, '\n');
  2217. if (write && !err && left)
  2218. left -= proc_skip_spaces(&kbuf);
  2219. free:
  2220. if (write) {
  2221. free_page(page);
  2222. if (first)
  2223. return err ? : -EINVAL;
  2224. }
  2225. *lenp -= left;
  2226. *ppos += *lenp;
  2227. return err;
  2228. }
  2229. static int do_proc_dointvec(struct ctl_table *table, int write,
  2230. void __user *buffer, size_t *lenp, loff_t *ppos,
  2231. int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
  2232. int write, void *data),
  2233. void *data)
  2234. {
  2235. return __do_proc_dointvec(table->data, table, write,
  2236. buffer, lenp, ppos, conv, data);
  2237. }
  2238. /**
  2239. * proc_dointvec - read a vector of integers
  2240. * @table: the sysctl table
  2241. * @write: %TRUE if this is a write to the sysctl file
  2242. * @buffer: the user buffer
  2243. * @lenp: the size of the user buffer
  2244. * @ppos: file position
  2245. *
  2246. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2247. * values from/to the user buffer, treated as an ASCII string.
  2248. *
  2249. * Returns 0 on success.
  2250. */
  2251. int proc_dointvec(struct ctl_table *table, int write,
  2252. void __user *buffer, size_t *lenp, loff_t *ppos)
  2253. {
  2254. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  2255. NULL,NULL);
  2256. }
  2257. /*
  2258. * Taint values can only be increased
  2259. * This means we can safely use a temporary.
  2260. */
  2261. static int proc_taint(struct ctl_table *table, int write,
  2262. void __user *buffer, size_t *lenp, loff_t *ppos)
  2263. {
  2264. struct ctl_table t;
  2265. unsigned long tmptaint = get_taint();
  2266. int err;
  2267. if (write && !capable(CAP_SYS_ADMIN))
  2268. return -EPERM;
  2269. t = *table;
  2270. t.data = &tmptaint;
  2271. err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
  2272. if (err < 0)
  2273. return err;
  2274. if (write) {
  2275. /*
  2276. * Poor man's atomic or. Not worth adding a primitive
  2277. * to everyone's atomic.h for this
  2278. */
  2279. int i;
  2280. for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
  2281. if ((tmptaint >> i) & 1)
  2282. add_taint(i);
  2283. }
  2284. }
  2285. return err;
  2286. }
  2287. #ifdef CONFIG_PRINTK
  2288. static int proc_dmesg_restrict(struct ctl_table *table, int write,
  2289. void __user *buffer, size_t *lenp, loff_t *ppos)
  2290. {
  2291. if (write && !capable(CAP_SYS_ADMIN))
  2292. return -EPERM;
  2293. return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
  2294. }
  2295. #endif
  2296. struct do_proc_dointvec_minmax_conv_param {
  2297. int *min;
  2298. int *max;
  2299. };
  2300. static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
  2301. int *valp,
  2302. int write, void *data)
  2303. {
  2304. struct do_proc_dointvec_minmax_conv_param *param = data;
  2305. if (write) {
  2306. int val = *negp ? -*lvalp : *lvalp;
  2307. if ((param->min && *param->min > val) ||
  2308. (param->max && *param->max < val))
  2309. return -EINVAL;
  2310. *valp = val;
  2311. } else {
  2312. int val = *valp;
  2313. if (val < 0) {
  2314. *negp = true;
  2315. *lvalp = (unsigned long)-val;
  2316. } else {
  2317. *negp = false;
  2318. *lvalp = (unsigned long)val;
  2319. }
  2320. }
  2321. return 0;
  2322. }
  2323. /**
  2324. * proc_dointvec_minmax - read a vector of integers with min/max values
  2325. * @table: the sysctl table
  2326. * @write: %TRUE if this is a write to the sysctl file
  2327. * @buffer: the user buffer
  2328. * @lenp: the size of the user buffer
  2329. * @ppos: file position
  2330. *
  2331. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2332. * values from/to the user buffer, treated as an ASCII string.
  2333. *
  2334. * This routine will ensure the values are within the range specified by
  2335. * table->extra1 (min) and table->extra2 (max).
  2336. *
  2337. * Returns 0 on success.
  2338. */
  2339. int proc_dointvec_minmax(struct ctl_table *table, int write,
  2340. void __user *buffer, size_t *lenp, loff_t *ppos)
  2341. {
  2342. struct do_proc_dointvec_minmax_conv_param param = {
  2343. .min = (int *) table->extra1,
  2344. .max = (int *) table->extra2,
  2345. };
  2346. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  2347. do_proc_dointvec_minmax_conv, &param);
  2348. }
  2349. static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
  2350. void __user *buffer,
  2351. size_t *lenp, loff_t *ppos,
  2352. unsigned long convmul,
  2353. unsigned long convdiv)
  2354. {
  2355. unsigned long *i, *min, *max;
  2356. int vleft, first = 1, err = 0;
  2357. unsigned long page = 0;
  2358. size_t left;
  2359. char *kbuf;
  2360. if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
  2361. *lenp = 0;
  2362. return 0;
  2363. }
  2364. i = (unsigned long *) data;
  2365. min = (unsigned long *) table->extra1;
  2366. max = (unsigned long *) table->extra2;
  2367. vleft = table->maxlen / sizeof(unsigned long);
  2368. left = *lenp;
  2369. if (write) {
  2370. if (left > PAGE_SIZE - 1)
  2371. left = PAGE_SIZE - 1;
  2372. page = __get_free_page(GFP_TEMPORARY);
  2373. kbuf = (char *) page;
  2374. if (!kbuf)
  2375. return -ENOMEM;
  2376. if (copy_from_user(kbuf, buffer, left)) {
  2377. err = -EFAULT;
  2378. goto free;
  2379. }
  2380. kbuf[left] = 0;
  2381. }
  2382. for (; left && vleft--; i++, first = 0) {
  2383. unsigned long val;
  2384. if (write) {
  2385. bool neg;
  2386. left -= proc_skip_spaces(&kbuf);
  2387. err = proc_get_long(&kbuf, &left, &val, &neg,
  2388. proc_wspace_sep,
  2389. sizeof(proc_wspace_sep), NULL);
  2390. if (err)
  2391. break;
  2392. if (neg)
  2393. continue;
  2394. if ((min && val < *min) || (max && val > *max))
  2395. continue;
  2396. *i = val;
  2397. } else {
  2398. val = convdiv * (*i) / convmul;
  2399. if (!first)
  2400. err = proc_put_char(&buffer, &left, '\t');
  2401. err = proc_put_long(&buffer, &left, val, false);
  2402. if (err)
  2403. break;
  2404. }
  2405. }
  2406. if (!write && !first && left && !err)
  2407. err = proc_put_char(&buffer, &left, '\n');
  2408. if (write && !err)
  2409. left -= proc_skip_spaces(&kbuf);
  2410. free:
  2411. if (write) {
  2412. free_page(page);
  2413. if (first)
  2414. return err ? : -EINVAL;
  2415. }
  2416. *lenp -= left;
  2417. *ppos += *lenp;
  2418. return err;
  2419. }
  2420. static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
  2421. void __user *buffer,
  2422. size_t *lenp, loff_t *ppos,
  2423. unsigned long convmul,
  2424. unsigned long convdiv)
  2425. {
  2426. return __do_proc_doulongvec_minmax(table->data, table, write,
  2427. buffer, lenp, ppos, convmul, convdiv);
  2428. }
  2429. /**
  2430. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  2431. * @table: the sysctl table
  2432. * @write: %TRUE if this is a write to the sysctl file
  2433. * @buffer: the user buffer
  2434. * @lenp: the size of the user buffer
  2435. * @ppos: file position
  2436. *
  2437. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2438. * values from/to the user buffer, treated as an ASCII string.
  2439. *
  2440. * This routine will ensure the values are within the range specified by
  2441. * table->extra1 (min) and table->extra2 (max).
  2442. *
  2443. * Returns 0 on success.
  2444. */
  2445. int proc_doulongvec_minmax(struct ctl_table *table, int write,
  2446. void __user *buffer, size_t *lenp, loff_t *ppos)
  2447. {
  2448. return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
  2449. }
  2450. /**
  2451. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  2452. * @table: the sysctl table
  2453. * @write: %TRUE if this is a write to the sysctl file
  2454. * @buffer: the user buffer
  2455. * @lenp: the size of the user buffer
  2456. * @ppos: file position
  2457. *
  2458. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  2459. * values from/to the user buffer, treated as an ASCII string. The values
  2460. * are treated as milliseconds, and converted to jiffies when they are stored.
  2461. *
  2462. * This routine will ensure the values are within the range specified by
  2463. * table->extra1 (min) and table->extra2 (max).
  2464. *
  2465. * Returns 0 on success.
  2466. */
  2467. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  2468. void __user *buffer,
  2469. size_t *lenp, loff_t *ppos)
  2470. {
  2471. return do_proc_doulongvec_minmax(table, write, buffer,
  2472. lenp, ppos, HZ, 1000l);
  2473. }
  2474. static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
  2475. int *valp,
  2476. int write, void *data)
  2477. {
  2478. if (write) {
  2479. if (*lvalp > LONG_MAX / HZ)
  2480. return 1;
  2481. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  2482. } else {
  2483. int val = *valp;
  2484. unsigned long lval;
  2485. if (val < 0) {
  2486. *negp = true;
  2487. lval = (unsigned long)-val;
  2488. } else {
  2489. *negp = false;
  2490. lval = (unsigned long)val;
  2491. }
  2492. *lvalp = lval / HZ;
  2493. }
  2494. return 0;
  2495. }
  2496. static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
  2497. int *valp,
  2498. int write, void *data)
  2499. {
  2500. if (write) {
  2501. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  2502. return 1;
  2503. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  2504. } else {
  2505. int val = *valp;
  2506. unsigned long lval;
  2507. if (val < 0) {
  2508. *negp = true;
  2509. lval = (unsigned long)-val;
  2510. } else {
  2511. *negp = false;
  2512. lval = (unsigned long)val;
  2513. }
  2514. *lvalp = jiffies_to_clock_t(lval);
  2515. }
  2516. return 0;
  2517. }
  2518. static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
  2519. int *valp,
  2520. int write, void *data)
  2521. {
  2522. if (write) {
  2523. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  2524. } else {
  2525. int val = *valp;
  2526. unsigned long lval;
  2527. if (val < 0) {
  2528. *negp = true;
  2529. lval = (unsigned long)-val;
  2530. } else {
  2531. *negp = false;
  2532. lval = (unsigned long)val;
  2533. }
  2534. *lvalp = jiffies_to_msecs(lval);
  2535. }
  2536. return 0;
  2537. }
  2538. /**
  2539. * proc_dointvec_jiffies - read a vector of integers as seconds
  2540. * @table: the sysctl table
  2541. * @write: %TRUE if this is a write to the sysctl file
  2542. * @buffer: the user buffer
  2543. * @lenp: the size of the user buffer
  2544. * @ppos: file position
  2545. *
  2546. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2547. * values from/to the user buffer, treated as an ASCII string.
  2548. * The values read are assumed to be in seconds, and are converted into
  2549. * jiffies.
  2550. *
  2551. * Returns 0 on success.
  2552. */
  2553. int proc_dointvec_jiffies(struct ctl_table *table, int write,
  2554. void __user *buffer, size_t *lenp, loff_t *ppos)
  2555. {
  2556. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  2557. do_proc_dointvec_jiffies_conv,NULL);
  2558. }
  2559. /**
  2560. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  2561. * @table: the sysctl table
  2562. * @write: %TRUE if this is a write to the sysctl file
  2563. * @buffer: the user buffer
  2564. * @lenp: the size of the user buffer
  2565. * @ppos: pointer to the file position
  2566. *
  2567. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2568. * values from/to the user buffer, treated as an ASCII string.
  2569. * The values read are assumed to be in 1/USER_HZ seconds, and
  2570. * are converted into jiffies.
  2571. *
  2572. * Returns 0 on success.
  2573. */
  2574. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
  2575. void __user *buffer, size_t *lenp, loff_t *ppos)
  2576. {
  2577. return do_proc_dointvec(table,write,buffer,lenp,ppos,
  2578. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2579. }
  2580. /**
  2581. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2582. * @table: the sysctl table
  2583. * @write: %TRUE if this is a write to the sysctl file
  2584. * @buffer: the user buffer
  2585. * @lenp: the size of the user buffer
  2586. * @ppos: file position
  2587. * @ppos: the current position in the file
  2588. *
  2589. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2590. * values from/to the user buffer, treated as an ASCII string.
  2591. * The values read are assumed to be in 1/1000 seconds, and
  2592. * are converted into jiffies.
  2593. *
  2594. * Returns 0 on success.
  2595. */
  2596. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
  2597. void __user *buffer, size_t *lenp, loff_t *ppos)
  2598. {
  2599. return do_proc_dointvec(table, write, buffer, lenp, ppos,
  2600. do_proc_dointvec_ms_jiffies_conv, NULL);
  2601. }
  2602. static int proc_do_cad_pid(struct ctl_table *table, int write,
  2603. void __user *buffer, size_t *lenp, loff_t *ppos)
  2604. {
  2605. struct pid *new_pid;
  2606. pid_t tmp;
  2607. int r;
  2608. tmp = pid_vnr(cad_pid);
  2609. r = __do_proc_dointvec(&tmp, table, write, buffer,
  2610. lenp, ppos, NULL, NULL);
  2611. if (r || !write)
  2612. return r;
  2613. new_pid = find_get_pid(tmp);
  2614. if (!new_pid)
  2615. return -ESRCH;
  2616. put_pid(xchg(&cad_pid, new_pid));
  2617. return 0;
  2618. }
  2619. /**
  2620. * proc_do_large_bitmap - read/write from/to a large bitmap
  2621. * @table: the sysctl table
  2622. * @write: %TRUE if this is a write to the sysctl file
  2623. * @buffer: the user buffer
  2624. * @lenp: the size of the user buffer
  2625. * @ppos: file position
  2626. *
  2627. * The bitmap is stored at table->data and the bitmap length (in bits)
  2628. * in table->maxlen.
  2629. *
  2630. * We use a range comma separated format (e.g. 1,3-4,10-10) so that
  2631. * large bitmaps may be represented in a compact manner. Writing into
  2632. * the file will clear the bitmap then update it with the given input.
  2633. *
  2634. * Returns 0 on success.
  2635. */
  2636. int proc_do_large_bitmap(struct ctl_table *table, int write,
  2637. void __user *buffer, size_t *lenp, loff_t *ppos)
  2638. {
  2639. int err = 0;
  2640. bool first = 1;
  2641. size_t left = *lenp;
  2642. unsigned long bitmap_len = table->maxlen;
  2643. unsigned long *bitmap = (unsigned long *) table->data;
  2644. unsigned long *tmp_bitmap = NULL;
  2645. char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
  2646. if (!bitmap_len || !left || (*ppos && !write)) {
  2647. *lenp = 0;
  2648. return 0;
  2649. }
  2650. if (write) {
  2651. unsigned long page = 0;
  2652. char *kbuf;
  2653. if (left > PAGE_SIZE - 1)
  2654. left = PAGE_SIZE - 1;
  2655. page = __get_free_page(GFP_TEMPORARY);
  2656. kbuf = (char *) page;
  2657. if (!kbuf)
  2658. return -ENOMEM;
  2659. if (copy_from_user(kbuf, buffer, left)) {
  2660. free_page(page);
  2661. return -EFAULT;
  2662. }
  2663. kbuf[left] = 0;
  2664. tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
  2665. GFP_KERNEL);
  2666. if (!tmp_bitmap) {
  2667. free_page(page);
  2668. return -ENOMEM;
  2669. }
  2670. proc_skip_char(&kbuf, &left, '\n');
  2671. while (!err && left) {
  2672. unsigned long val_a, val_b;
  2673. bool neg;
  2674. err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
  2675. sizeof(tr_a), &c);
  2676. if (err)
  2677. break;
  2678. if (val_a >= bitmap_len || neg) {
  2679. err = -EINVAL;
  2680. break;
  2681. }
  2682. val_b = val_a;
  2683. if (left) {
  2684. kbuf++;
  2685. left--;
  2686. }
  2687. if (c == '-') {
  2688. err = proc_get_long(&kbuf, &left, &val_b,
  2689. &neg, tr_b, sizeof(tr_b),
  2690. &c);
  2691. if (err)
  2692. break;
  2693. if (val_b >= bitmap_len || neg ||
  2694. val_a > val_b) {
  2695. err = -EINVAL;
  2696. break;
  2697. }
  2698. if (left) {
  2699. kbuf++;
  2700. left--;
  2701. }
  2702. }
  2703. while (val_a <= val_b)
  2704. set_bit(val_a++, tmp_bitmap);
  2705. first = 0;
  2706. proc_skip_char(&kbuf, &left, '\n');
  2707. }
  2708. free_page(page);
  2709. } else {
  2710. unsigned long bit_a, bit_b = 0;
  2711. while (left) {
  2712. bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
  2713. if (bit_a >= bitmap_len)
  2714. break;
  2715. bit_b = find_next_zero_bit(bitmap, bitmap_len,
  2716. bit_a + 1) - 1;
  2717. if (!first) {
  2718. err = proc_put_char(&buffer, &left, ',');
  2719. if (err)
  2720. break;
  2721. }
  2722. err = proc_put_long(&buffer, &left, bit_a, false);
  2723. if (err)
  2724. break;
  2725. if (bit_a != bit_b) {
  2726. err = proc_put_char(&buffer, &left, '-');
  2727. if (err)
  2728. break;
  2729. err = proc_put_long(&buffer, &left, bit_b, false);
  2730. if (err)
  2731. break;
  2732. }
  2733. first = 0; bit_b++;
  2734. }
  2735. if (!err)
  2736. err = proc_put_char(&buffer, &left, '\n');
  2737. }
  2738. if (!err) {
  2739. if (write) {
  2740. if (*ppos)
  2741. bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
  2742. else
  2743. memcpy(bitmap, tmp_bitmap,
  2744. BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
  2745. }
  2746. kfree(tmp_bitmap);
  2747. *lenp -= left;
  2748. *ppos += *lenp;
  2749. return 0;
  2750. } else {
  2751. kfree(tmp_bitmap);
  2752. return err;
  2753. }
  2754. }
  2755. #else /* CONFIG_PROC_SYSCTL */
  2756. int proc_dostring(struct ctl_table *table, int write,
  2757. void __user *buffer, size_t *lenp, loff_t *ppos)
  2758. {
  2759. return -ENOSYS;
  2760. }
  2761. int proc_dointvec(struct ctl_table *table, int write,
  2762. void __user *buffer, size_t *lenp, loff_t *ppos)
  2763. {
  2764. return -ENOSYS;
  2765. }
  2766. int proc_dointvec_minmax(struct ctl_table *table, int write,
  2767. void __user *buffer, size_t *lenp, loff_t *ppos)
  2768. {
  2769. return -ENOSYS;
  2770. }
  2771. int proc_dointvec_jiffies(struct ctl_table *table, int write,
  2772. void __user *buffer, size_t *lenp, loff_t *ppos)
  2773. {
  2774. return -ENOSYS;
  2775. }
  2776. int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
  2777. void __user *buffer, size_t *lenp, loff_t *ppos)
  2778. {
  2779. return -ENOSYS;
  2780. }
  2781. int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
  2782. void __user *buffer, size_t *lenp, loff_t *ppos)
  2783. {
  2784. return -ENOSYS;
  2785. }
  2786. int proc_doulongvec_minmax(struct ctl_table *table, int write,
  2787. void __user *buffer, size_t *lenp, loff_t *ppos)
  2788. {
  2789. return -ENOSYS;
  2790. }
  2791. int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
  2792. void __user *buffer,
  2793. size_t *lenp, loff_t *ppos)
  2794. {
  2795. return -ENOSYS;
  2796. }
  2797. #endif /* CONFIG_PROC_SYSCTL */
  2798. /*
  2799. * No sense putting this after each symbol definition, twice,
  2800. * exception granted :-)
  2801. */
  2802. EXPORT_SYMBOL(proc_dointvec);
  2803. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2804. EXPORT_SYMBOL(proc_dointvec_minmax);
  2805. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2806. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2807. EXPORT_SYMBOL(proc_dostring);
  2808. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2809. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2810. EXPORT_SYMBOL(register_sysctl_table);
  2811. EXPORT_SYMBOL(register_sysctl_paths);
  2812. EXPORT_SYMBOL(unregister_sysctl_table);