sysctl.c 71 KB

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