sysctl.c 67 KB

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