sysctl.c 71 KB

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