sysctl.c 67 KB

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