sysctl.c 60 KB

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