sysctl.c 67 KB

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