sysctl.c 73 KB

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