sysctl.c 59 KB

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