sysctl.c 70 KB

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