sysctl.c 71 KB

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