sysctl.c 67 KB

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