sysctl.c 76 KB

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