sysctl.c 73 KB

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