sysctl.c 68 KB

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