sysctl.c 72 KB

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