sysctl.c 73 KB

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