sysctl.c 76 KB

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