sysctl.c 73 KB

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