sysctl.c 64 KB

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