sysctl.c 71 KB

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