sysctl.c 71 KB

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