sysctl.c 64 KB

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