sysctl.c 73 KB

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