sysctl.c 67 KB

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