sysctl.c 67 KB

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