sysctl.c 68 KB

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