sysctl.c 62 KB

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