sysctl.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491
  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/config.h>
  21. #include <linux/module.h>
  22. #include <linux/mm.h>
  23. #include <linux/swap.h>
  24. #include <linux/slab.h>
  25. #include <linux/sysctl.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/capability.h>
  28. #include <linux/ctype.h>
  29. #include <linux/utsname.h>
  30. #include <linux/capability.h>
  31. #include <linux/smp_lock.h>
  32. #include <linux/init.h>
  33. #include <linux/kernel.h>
  34. #include <linux/kobject.h>
  35. #include <linux/net.h>
  36. #include <linux/sysrq.h>
  37. #include <linux/highuid.h>
  38. #include <linux/writeback.h>
  39. #include <linux/hugetlb.h>
  40. #include <linux/security.h>
  41. #include <linux/initrd.h>
  42. #include <linux/times.h>
  43. #include <linux/limits.h>
  44. #include <linux/dcache.h>
  45. #include <linux/syscalls.h>
  46. #include <asm/uaccess.h>
  47. #include <asm/processor.h>
  48. #ifdef CONFIG_ROOT_NFS
  49. #include <linux/nfs_fs.h>
  50. #endif
  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 max_threads;
  57. extern int sysrq_enabled;
  58. extern int core_uses_pid;
  59. extern int suid_dumpable;
  60. extern char core_pattern[];
  61. extern int cad_pid;
  62. extern int pid_max;
  63. extern int min_free_kbytes;
  64. extern int printk_ratelimit_jiffies;
  65. extern int printk_ratelimit_burst;
  66. extern int pid_max_min, pid_max_max;
  67. extern int sysctl_drop_caches;
  68. extern int percpu_pagelist_fraction;
  69. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
  70. int unknown_nmi_panic;
  71. extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
  72. void __user *, size_t *, loff_t *);
  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. int randomize_va_space = 1;
  115. static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
  116. ctl_table *, void **);
  117. static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
  118. void __user *buffer, size_t *lenp, loff_t *ppos);
  119. static ctl_table root_table[];
  120. static struct ctl_table_header root_table_header =
  121. { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
  122. static ctl_table kern_table[];
  123. static ctl_table vm_table[];
  124. static ctl_table proc_table[];
  125. static ctl_table fs_table[];
  126. static ctl_table debug_table[];
  127. static ctl_table dev_table[];
  128. extern ctl_table random_table[];
  129. #ifdef CONFIG_UNIX98_PTYS
  130. extern ctl_table pty_table[];
  131. #endif
  132. #ifdef CONFIG_INOTIFY
  133. extern ctl_table inotify_table[];
  134. #endif
  135. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  136. int sysctl_legacy_va_layout;
  137. #endif
  138. /* /proc declarations: */
  139. #ifdef CONFIG_PROC_FS
  140. static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
  141. static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
  142. static int proc_opensys(struct inode *, struct file *);
  143. struct file_operations proc_sys_file_operations = {
  144. .open = proc_opensys,
  145. .read = proc_readsys,
  146. .write = proc_writesys,
  147. };
  148. extern struct proc_dir_entry *proc_sys_root;
  149. static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
  150. static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
  151. #endif
  152. /* The default sysctl tables: */
  153. static ctl_table root_table[] = {
  154. {
  155. .ctl_name = CTL_KERN,
  156. .procname = "kernel",
  157. .mode = 0555,
  158. .child = kern_table,
  159. },
  160. {
  161. .ctl_name = CTL_VM,
  162. .procname = "vm",
  163. .mode = 0555,
  164. .child = vm_table,
  165. },
  166. #ifdef CONFIG_NET
  167. {
  168. .ctl_name = CTL_NET,
  169. .procname = "net",
  170. .mode = 0555,
  171. .child = net_table,
  172. },
  173. #endif
  174. {
  175. .ctl_name = CTL_PROC,
  176. .procname = "proc",
  177. .mode = 0555,
  178. .child = proc_table,
  179. },
  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 = 64,
  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. #ifdef CONFIG_HOTPLUG
  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_unknown_nmi_panic,
  602. },
  603. #endif
  604. #if defined(CONFIG_X86)
  605. {
  606. .ctl_name = KERN_BOOTLOADER_TYPE,
  607. .procname = "bootloader_type",
  608. .data = &bootloader_type,
  609. .maxlen = sizeof (int),
  610. .mode = 0444,
  611. .proc_handler = &proc_dointvec,
  612. },
  613. #endif
  614. {
  615. .ctl_name = KERN_RANDOMIZE,
  616. .procname = "randomize_va_space",
  617. .data = &randomize_va_space,
  618. .maxlen = sizeof(int),
  619. .mode = 0644,
  620. .proc_handler = &proc_dointvec,
  621. },
  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. { .ctl_name = 0 }
  633. };
  634. /* Constants for minimum and maximum testing in vm_table.
  635. We use these as one-element integer vectors. */
  636. static int zero;
  637. static int one_hundred = 100;
  638. static ctl_table vm_table[] = {
  639. {
  640. .ctl_name = VM_OVERCOMMIT_MEMORY,
  641. .procname = "overcommit_memory",
  642. .data = &sysctl_overcommit_memory,
  643. .maxlen = sizeof(sysctl_overcommit_memory),
  644. .mode = 0644,
  645. .proc_handler = &proc_dointvec,
  646. },
  647. {
  648. .ctl_name = VM_OVERCOMMIT_RATIO,
  649. .procname = "overcommit_ratio",
  650. .data = &sysctl_overcommit_ratio,
  651. .maxlen = sizeof(sysctl_overcommit_ratio),
  652. .mode = 0644,
  653. .proc_handler = &proc_dointvec,
  654. },
  655. {
  656. .ctl_name = VM_PAGE_CLUSTER,
  657. .procname = "page-cluster",
  658. .data = &page_cluster,
  659. .maxlen = sizeof(int),
  660. .mode = 0644,
  661. .proc_handler = &proc_dointvec,
  662. },
  663. {
  664. .ctl_name = VM_DIRTY_BACKGROUND,
  665. .procname = "dirty_background_ratio",
  666. .data = &dirty_background_ratio,
  667. .maxlen = sizeof(dirty_background_ratio),
  668. .mode = 0644,
  669. .proc_handler = &proc_dointvec_minmax,
  670. .strategy = &sysctl_intvec,
  671. .extra1 = &zero,
  672. .extra2 = &one_hundred,
  673. },
  674. {
  675. .ctl_name = VM_DIRTY_RATIO,
  676. .procname = "dirty_ratio",
  677. .data = &vm_dirty_ratio,
  678. .maxlen = sizeof(vm_dirty_ratio),
  679. .mode = 0644,
  680. .proc_handler = &proc_dointvec_minmax,
  681. .strategy = &sysctl_intvec,
  682. .extra1 = &zero,
  683. .extra2 = &one_hundred,
  684. },
  685. {
  686. .ctl_name = VM_DIRTY_WB_CS,
  687. .procname = "dirty_writeback_centisecs",
  688. .data = &dirty_writeback_centisecs,
  689. .maxlen = sizeof(dirty_writeback_centisecs),
  690. .mode = 0644,
  691. .proc_handler = &dirty_writeback_centisecs_handler,
  692. },
  693. {
  694. .ctl_name = VM_DIRTY_EXPIRE_CS,
  695. .procname = "dirty_expire_centisecs",
  696. .data = &dirty_expire_centisecs,
  697. .maxlen = sizeof(dirty_expire_centisecs),
  698. .mode = 0644,
  699. .proc_handler = &proc_dointvec,
  700. },
  701. {
  702. .ctl_name = VM_NR_PDFLUSH_THREADS,
  703. .procname = "nr_pdflush_threads",
  704. .data = &nr_pdflush_threads,
  705. .maxlen = sizeof nr_pdflush_threads,
  706. .mode = 0444 /* read-only*/,
  707. .proc_handler = &proc_dointvec,
  708. },
  709. {
  710. .ctl_name = VM_SWAPPINESS,
  711. .procname = "swappiness",
  712. .data = &vm_swappiness,
  713. .maxlen = sizeof(vm_swappiness),
  714. .mode = 0644,
  715. .proc_handler = &proc_dointvec_minmax,
  716. .strategy = &sysctl_intvec,
  717. .extra1 = &zero,
  718. .extra2 = &one_hundred,
  719. },
  720. #ifdef CONFIG_HUGETLB_PAGE
  721. {
  722. .ctl_name = VM_HUGETLB_PAGES,
  723. .procname = "nr_hugepages",
  724. .data = &max_huge_pages,
  725. .maxlen = sizeof(unsigned long),
  726. .mode = 0644,
  727. .proc_handler = &hugetlb_sysctl_handler,
  728. .extra1 = (void *)&hugetlb_zero,
  729. .extra2 = (void *)&hugetlb_infinity,
  730. },
  731. {
  732. .ctl_name = VM_HUGETLB_GROUP,
  733. .procname = "hugetlb_shm_group",
  734. .data = &sysctl_hugetlb_shm_group,
  735. .maxlen = sizeof(gid_t),
  736. .mode = 0644,
  737. .proc_handler = &proc_dointvec,
  738. },
  739. #endif
  740. {
  741. .ctl_name = VM_LOWMEM_RESERVE_RATIO,
  742. .procname = "lowmem_reserve_ratio",
  743. .data = &sysctl_lowmem_reserve_ratio,
  744. .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
  745. .mode = 0644,
  746. .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
  747. .strategy = &sysctl_intvec,
  748. },
  749. {
  750. .ctl_name = VM_DROP_PAGECACHE,
  751. .procname = "drop_caches",
  752. .data = &sysctl_drop_caches,
  753. .maxlen = sizeof(int),
  754. .mode = 0644,
  755. .proc_handler = drop_caches_sysctl_handler,
  756. .strategy = &sysctl_intvec,
  757. },
  758. {
  759. .ctl_name = VM_MIN_FREE_KBYTES,
  760. .procname = "min_free_kbytes",
  761. .data = &min_free_kbytes,
  762. .maxlen = sizeof(min_free_kbytes),
  763. .mode = 0644,
  764. .proc_handler = &min_free_kbytes_sysctl_handler,
  765. .strategy = &sysctl_intvec,
  766. .extra1 = &zero,
  767. },
  768. {
  769. .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
  770. .procname = "percpu_pagelist_fraction",
  771. .data = &percpu_pagelist_fraction,
  772. .maxlen = sizeof(percpu_pagelist_fraction),
  773. .mode = 0644,
  774. .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
  775. .strategy = &sysctl_intvec,
  776. .extra1 = &min_percpu_pagelist_fract,
  777. },
  778. #ifdef CONFIG_MMU
  779. {
  780. .ctl_name = VM_MAX_MAP_COUNT,
  781. .procname = "max_map_count",
  782. .data = &sysctl_max_map_count,
  783. .maxlen = sizeof(sysctl_max_map_count),
  784. .mode = 0644,
  785. .proc_handler = &proc_dointvec
  786. },
  787. #endif
  788. {
  789. .ctl_name = VM_LAPTOP_MODE,
  790. .procname = "laptop_mode",
  791. .data = &laptop_mode,
  792. .maxlen = sizeof(laptop_mode),
  793. .mode = 0644,
  794. .proc_handler = &proc_dointvec,
  795. .strategy = &sysctl_intvec,
  796. .extra1 = &zero,
  797. },
  798. {
  799. .ctl_name = VM_BLOCK_DUMP,
  800. .procname = "block_dump",
  801. .data = &block_dump,
  802. .maxlen = sizeof(block_dump),
  803. .mode = 0644,
  804. .proc_handler = &proc_dointvec,
  805. .strategy = &sysctl_intvec,
  806. .extra1 = &zero,
  807. },
  808. {
  809. .ctl_name = VM_VFS_CACHE_PRESSURE,
  810. .procname = "vfs_cache_pressure",
  811. .data = &sysctl_vfs_cache_pressure,
  812. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  813. .mode = 0644,
  814. .proc_handler = &proc_dointvec,
  815. .strategy = &sysctl_intvec,
  816. .extra1 = &zero,
  817. },
  818. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  819. {
  820. .ctl_name = VM_LEGACY_VA_LAYOUT,
  821. .procname = "legacy_va_layout",
  822. .data = &sysctl_legacy_va_layout,
  823. .maxlen = sizeof(sysctl_legacy_va_layout),
  824. .mode = 0644,
  825. .proc_handler = &proc_dointvec,
  826. .strategy = &sysctl_intvec,
  827. .extra1 = &zero,
  828. },
  829. #endif
  830. #ifdef CONFIG_SWAP
  831. {
  832. .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
  833. .procname = "swap_token_timeout",
  834. .data = &swap_token_default_timeout,
  835. .maxlen = sizeof(swap_token_default_timeout),
  836. .mode = 0644,
  837. .proc_handler = &proc_dointvec_jiffies,
  838. .strategy = &sysctl_jiffies,
  839. },
  840. #endif
  841. #ifdef CONFIG_NUMA
  842. {
  843. .ctl_name = VM_ZONE_RECLAIM_MODE,
  844. .procname = "zone_reclaim_mode",
  845. .data = &zone_reclaim_mode,
  846. .maxlen = sizeof(zone_reclaim_mode),
  847. .mode = 0644,
  848. .proc_handler = &proc_dointvec,
  849. .strategy = &sysctl_intvec,
  850. .extra1 = &zero,
  851. },
  852. {
  853. .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
  854. .procname = "zone_reclaim_interval",
  855. .data = &zone_reclaim_interval,
  856. .maxlen = sizeof(zone_reclaim_interval),
  857. .mode = 0644,
  858. .proc_handler = &proc_dointvec_jiffies,
  859. .strategy = &sysctl_jiffies,
  860. },
  861. #endif
  862. { .ctl_name = 0 }
  863. };
  864. static ctl_table proc_table[] = {
  865. { .ctl_name = 0 }
  866. };
  867. static ctl_table fs_table[] = {
  868. {
  869. .ctl_name = FS_NRINODE,
  870. .procname = "inode-nr",
  871. .data = &inodes_stat,
  872. .maxlen = 2*sizeof(int),
  873. .mode = 0444,
  874. .proc_handler = &proc_dointvec,
  875. },
  876. {
  877. .ctl_name = FS_STATINODE,
  878. .procname = "inode-state",
  879. .data = &inodes_stat,
  880. .maxlen = 7*sizeof(int),
  881. .mode = 0444,
  882. .proc_handler = &proc_dointvec,
  883. },
  884. {
  885. .ctl_name = FS_NRFILE,
  886. .procname = "file-nr",
  887. .data = &files_stat,
  888. .maxlen = 3*sizeof(int),
  889. .mode = 0444,
  890. .proc_handler = &proc_dointvec,
  891. },
  892. {
  893. .ctl_name = FS_MAXFILE,
  894. .procname = "file-max",
  895. .data = &files_stat.max_files,
  896. .maxlen = sizeof(int),
  897. .mode = 0644,
  898. .proc_handler = &proc_dointvec,
  899. },
  900. {
  901. .ctl_name = FS_DENTRY,
  902. .procname = "dentry-state",
  903. .data = &dentry_stat,
  904. .maxlen = 6*sizeof(int),
  905. .mode = 0444,
  906. .proc_handler = &proc_dointvec,
  907. },
  908. {
  909. .ctl_name = FS_OVERFLOWUID,
  910. .procname = "overflowuid",
  911. .data = &fs_overflowuid,
  912. .maxlen = sizeof(int),
  913. .mode = 0644,
  914. .proc_handler = &proc_dointvec_minmax,
  915. .strategy = &sysctl_intvec,
  916. .extra1 = &minolduid,
  917. .extra2 = &maxolduid,
  918. },
  919. {
  920. .ctl_name = FS_OVERFLOWGID,
  921. .procname = "overflowgid",
  922. .data = &fs_overflowgid,
  923. .maxlen = sizeof(int),
  924. .mode = 0644,
  925. .proc_handler = &proc_dointvec_minmax,
  926. .strategy = &sysctl_intvec,
  927. .extra1 = &minolduid,
  928. .extra2 = &maxolduid,
  929. },
  930. {
  931. .ctl_name = FS_LEASES,
  932. .procname = "leases-enable",
  933. .data = &leases_enable,
  934. .maxlen = sizeof(int),
  935. .mode = 0644,
  936. .proc_handler = &proc_dointvec,
  937. },
  938. #ifdef CONFIG_DNOTIFY
  939. {
  940. .ctl_name = FS_DIR_NOTIFY,
  941. .procname = "dir-notify-enable",
  942. .data = &dir_notify_enable,
  943. .maxlen = sizeof(int),
  944. .mode = 0644,
  945. .proc_handler = &proc_dointvec,
  946. },
  947. #endif
  948. #ifdef CONFIG_MMU
  949. {
  950. .ctl_name = FS_LEASE_TIME,
  951. .procname = "lease-break-time",
  952. .data = &lease_break_time,
  953. .maxlen = sizeof(int),
  954. .mode = 0644,
  955. .proc_handler = &proc_dointvec,
  956. },
  957. {
  958. .ctl_name = FS_AIO_NR,
  959. .procname = "aio-nr",
  960. .data = &aio_nr,
  961. .maxlen = sizeof(aio_nr),
  962. .mode = 0444,
  963. .proc_handler = &proc_doulongvec_minmax,
  964. },
  965. {
  966. .ctl_name = FS_AIO_MAX_NR,
  967. .procname = "aio-max-nr",
  968. .data = &aio_max_nr,
  969. .maxlen = sizeof(aio_max_nr),
  970. .mode = 0644,
  971. .proc_handler = &proc_doulongvec_minmax,
  972. },
  973. #ifdef CONFIG_INOTIFY
  974. {
  975. .ctl_name = FS_INOTIFY,
  976. .procname = "inotify",
  977. .mode = 0555,
  978. .child = inotify_table,
  979. },
  980. #endif
  981. #endif
  982. {
  983. .ctl_name = KERN_SETUID_DUMPABLE,
  984. .procname = "suid_dumpable",
  985. .data = &suid_dumpable,
  986. .maxlen = sizeof(int),
  987. .mode = 0644,
  988. .proc_handler = &proc_dointvec,
  989. },
  990. { .ctl_name = 0 }
  991. };
  992. static ctl_table debug_table[] = {
  993. { .ctl_name = 0 }
  994. };
  995. static ctl_table dev_table[] = {
  996. { .ctl_name = 0 }
  997. };
  998. extern void init_irq_proc (void);
  999. static DEFINE_SPINLOCK(sysctl_lock);
  1000. /* called under sysctl_lock */
  1001. static int use_table(struct ctl_table_header *p)
  1002. {
  1003. if (unlikely(p->unregistering))
  1004. return 0;
  1005. p->used++;
  1006. return 1;
  1007. }
  1008. /* called under sysctl_lock */
  1009. static void unuse_table(struct ctl_table_header *p)
  1010. {
  1011. if (!--p->used)
  1012. if (unlikely(p->unregistering))
  1013. complete(p->unregistering);
  1014. }
  1015. /* called under sysctl_lock, will reacquire if has to wait */
  1016. static void start_unregistering(struct ctl_table_header *p)
  1017. {
  1018. /*
  1019. * if p->used is 0, nobody will ever touch that entry again;
  1020. * we'll eliminate all paths to it before dropping sysctl_lock
  1021. */
  1022. if (unlikely(p->used)) {
  1023. struct completion wait;
  1024. init_completion(&wait);
  1025. p->unregistering = &wait;
  1026. spin_unlock(&sysctl_lock);
  1027. wait_for_completion(&wait);
  1028. spin_lock(&sysctl_lock);
  1029. }
  1030. /*
  1031. * do not remove from the list until nobody holds it; walking the
  1032. * list in do_sysctl() relies on that.
  1033. */
  1034. list_del_init(&p->ctl_entry);
  1035. }
  1036. void __init sysctl_init(void)
  1037. {
  1038. #ifdef CONFIG_PROC_FS
  1039. register_proc_table(root_table, proc_sys_root, &root_table_header);
  1040. init_irq_proc();
  1041. #endif
  1042. }
  1043. int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
  1044. void __user *newval, size_t newlen)
  1045. {
  1046. struct list_head *tmp;
  1047. int error = -ENOTDIR;
  1048. if (nlen <= 0 || nlen >= CTL_MAXNAME)
  1049. return -ENOTDIR;
  1050. if (oldval) {
  1051. int old_len;
  1052. if (!oldlenp || get_user(old_len, oldlenp))
  1053. return -EFAULT;
  1054. }
  1055. spin_lock(&sysctl_lock);
  1056. tmp = &root_table_header.ctl_entry;
  1057. do {
  1058. struct ctl_table_header *head =
  1059. list_entry(tmp, struct ctl_table_header, ctl_entry);
  1060. void *context = NULL;
  1061. if (!use_table(head))
  1062. continue;
  1063. spin_unlock(&sysctl_lock);
  1064. error = parse_table(name, nlen, oldval, oldlenp,
  1065. newval, newlen, head->ctl_table,
  1066. &context);
  1067. kfree(context);
  1068. spin_lock(&sysctl_lock);
  1069. unuse_table(head);
  1070. if (error != -ENOTDIR)
  1071. break;
  1072. } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
  1073. spin_unlock(&sysctl_lock);
  1074. return error;
  1075. }
  1076. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  1077. {
  1078. struct __sysctl_args tmp;
  1079. int error;
  1080. if (copy_from_user(&tmp, args, sizeof(tmp)))
  1081. return -EFAULT;
  1082. lock_kernel();
  1083. error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
  1084. tmp.newval, tmp.newlen);
  1085. unlock_kernel();
  1086. return error;
  1087. }
  1088. /*
  1089. * ctl_perm does NOT grant the superuser all rights automatically, because
  1090. * some sysctl variables are readonly even to root.
  1091. */
  1092. static int test_perm(int mode, int op)
  1093. {
  1094. if (!current->euid)
  1095. mode >>= 6;
  1096. else if (in_egroup_p(0))
  1097. mode >>= 3;
  1098. if ((mode & op & 0007) == op)
  1099. return 0;
  1100. return -EACCES;
  1101. }
  1102. static inline int ctl_perm(ctl_table *table, int op)
  1103. {
  1104. int error;
  1105. error = security_sysctl(table, op);
  1106. if (error)
  1107. return error;
  1108. return test_perm(table->mode, op);
  1109. }
  1110. static int parse_table(int __user *name, int nlen,
  1111. void __user *oldval, size_t __user *oldlenp,
  1112. void __user *newval, size_t newlen,
  1113. ctl_table *table, void **context)
  1114. {
  1115. int n;
  1116. repeat:
  1117. if (!nlen)
  1118. return -ENOTDIR;
  1119. if (get_user(n, name))
  1120. return -EFAULT;
  1121. for ( ; table->ctl_name; table++) {
  1122. if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
  1123. int error;
  1124. if (table->child) {
  1125. if (ctl_perm(table, 001))
  1126. return -EPERM;
  1127. if (table->strategy) {
  1128. error = table->strategy(
  1129. table, name, nlen,
  1130. oldval, oldlenp,
  1131. newval, newlen, context);
  1132. if (error)
  1133. return error;
  1134. }
  1135. name++;
  1136. nlen--;
  1137. table = table->child;
  1138. goto repeat;
  1139. }
  1140. error = do_sysctl_strategy(table, name, nlen,
  1141. oldval, oldlenp,
  1142. newval, newlen, context);
  1143. return error;
  1144. }
  1145. }
  1146. return -ENOTDIR;
  1147. }
  1148. /* Perform the actual read/write of a sysctl table entry. */
  1149. int do_sysctl_strategy (ctl_table *table,
  1150. int __user *name, int nlen,
  1151. void __user *oldval, size_t __user *oldlenp,
  1152. void __user *newval, size_t newlen, void **context)
  1153. {
  1154. int op = 0, rc;
  1155. size_t len;
  1156. if (oldval)
  1157. op |= 004;
  1158. if (newval)
  1159. op |= 002;
  1160. if (ctl_perm(table, op))
  1161. return -EPERM;
  1162. if (table->strategy) {
  1163. rc = table->strategy(table, name, nlen, oldval, oldlenp,
  1164. newval, newlen, context);
  1165. if (rc < 0)
  1166. return rc;
  1167. if (rc > 0)
  1168. return 0;
  1169. }
  1170. /* If there is no strategy routine, or if the strategy returns
  1171. * zero, proceed with automatic r/w */
  1172. if (table->data && table->maxlen) {
  1173. if (oldval && oldlenp) {
  1174. if (get_user(len, oldlenp))
  1175. return -EFAULT;
  1176. if (len) {
  1177. if (len > table->maxlen)
  1178. len = table->maxlen;
  1179. if(copy_to_user(oldval, table->data, len))
  1180. return -EFAULT;
  1181. if(put_user(len, oldlenp))
  1182. return -EFAULT;
  1183. }
  1184. }
  1185. if (newval && newlen) {
  1186. len = newlen;
  1187. if (len > table->maxlen)
  1188. len = table->maxlen;
  1189. if(copy_from_user(table->data, newval, len))
  1190. return -EFAULT;
  1191. }
  1192. }
  1193. return 0;
  1194. }
  1195. /**
  1196. * register_sysctl_table - register a sysctl hierarchy
  1197. * @table: the top-level table structure
  1198. * @insert_at_head: whether the entry should be inserted in front or at the end
  1199. *
  1200. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1201. * array. An entry with a ctl_name of 0 terminates the table.
  1202. *
  1203. * The members of the &ctl_table structure are used as follows:
  1204. *
  1205. * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
  1206. * must be unique within that level of sysctl
  1207. *
  1208. * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
  1209. * enter a sysctl file
  1210. *
  1211. * data - a pointer to data for use by proc_handler
  1212. *
  1213. * maxlen - the maximum size in bytes of the data
  1214. *
  1215. * mode - the file permissions for the /proc/sys file, and for sysctl(2)
  1216. *
  1217. * child - a pointer to the child sysctl table if this entry is a directory, or
  1218. * %NULL.
  1219. *
  1220. * proc_handler - the text handler routine (described below)
  1221. *
  1222. * strategy - the strategy routine (described below)
  1223. *
  1224. * de - for internal use by the sysctl routines
  1225. *
  1226. * extra1, extra2 - extra pointers usable by the proc handler routines
  1227. *
  1228. * Leaf nodes in the sysctl tree will be represented by a single file
  1229. * under /proc; non-leaf nodes will be represented by directories.
  1230. *
  1231. * sysctl(2) can automatically manage read and write requests through
  1232. * the sysctl table. The data and maxlen fields of the ctl_table
  1233. * struct enable minimal validation of the values being written to be
  1234. * performed, and the mode field allows minimal authentication.
  1235. *
  1236. * More sophisticated management can be enabled by the provision of a
  1237. * strategy routine with the table entry. This will be called before
  1238. * any automatic read or write of the data is performed.
  1239. *
  1240. * The strategy routine may return
  1241. *
  1242. * < 0 - Error occurred (error is passed to user process)
  1243. *
  1244. * 0 - OK - proceed with automatic read or write.
  1245. *
  1246. * > 0 - OK - read or write has been done by the strategy routine, so
  1247. * return immediately.
  1248. *
  1249. * There must be a proc_handler routine for any terminal nodes
  1250. * mirrored under /proc/sys (non-terminals are handled by a built-in
  1251. * directory handler). Several default handlers are available to
  1252. * cover common cases -
  1253. *
  1254. * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
  1255. * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
  1256. * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
  1257. *
  1258. * It is the handler's job to read the input buffer from user memory
  1259. * and process it. The handler should return 0 on success.
  1260. *
  1261. * This routine returns %NULL on a failure to register, and a pointer
  1262. * to the table header on success.
  1263. */
  1264. struct ctl_table_header *register_sysctl_table(ctl_table * table,
  1265. int insert_at_head)
  1266. {
  1267. struct ctl_table_header *tmp;
  1268. tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
  1269. if (!tmp)
  1270. return NULL;
  1271. tmp->ctl_table = table;
  1272. INIT_LIST_HEAD(&tmp->ctl_entry);
  1273. tmp->used = 0;
  1274. tmp->unregistering = NULL;
  1275. spin_lock(&sysctl_lock);
  1276. if (insert_at_head)
  1277. list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1278. else
  1279. list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1280. spin_unlock(&sysctl_lock);
  1281. #ifdef CONFIG_PROC_FS
  1282. register_proc_table(table, proc_sys_root, tmp);
  1283. #endif
  1284. return tmp;
  1285. }
  1286. /**
  1287. * unregister_sysctl_table - unregister a sysctl table hierarchy
  1288. * @header: the header returned from register_sysctl_table
  1289. *
  1290. * Unregisters the sysctl table and all children. proc entries may not
  1291. * actually be removed until they are no longer used by anyone.
  1292. */
  1293. void unregister_sysctl_table(struct ctl_table_header * header)
  1294. {
  1295. might_sleep();
  1296. spin_lock(&sysctl_lock);
  1297. start_unregistering(header);
  1298. #ifdef CONFIG_PROC_FS
  1299. unregister_proc_table(header->ctl_table, proc_sys_root);
  1300. #endif
  1301. spin_unlock(&sysctl_lock);
  1302. kfree(header);
  1303. }
  1304. /*
  1305. * /proc/sys support
  1306. */
  1307. #ifdef CONFIG_PROC_FS
  1308. /* Scan the sysctl entries in table and add them all into /proc */
  1309. static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
  1310. {
  1311. struct proc_dir_entry *de;
  1312. int len;
  1313. mode_t mode;
  1314. for (; table->ctl_name; table++) {
  1315. /* Can't do anything without a proc name. */
  1316. if (!table->procname)
  1317. continue;
  1318. /* Maybe we can't do anything with it... */
  1319. if (!table->proc_handler && !table->child) {
  1320. printk(KERN_WARNING "SYSCTL: Can't register %s\n",
  1321. table->procname);
  1322. continue;
  1323. }
  1324. len = strlen(table->procname);
  1325. mode = table->mode;
  1326. de = NULL;
  1327. if (table->proc_handler)
  1328. mode |= S_IFREG;
  1329. else {
  1330. mode |= S_IFDIR;
  1331. for (de = root->subdir; de; de = de->next) {
  1332. if (proc_match(len, table->procname, de))
  1333. break;
  1334. }
  1335. /* If the subdir exists already, de is non-NULL */
  1336. }
  1337. if (!de) {
  1338. de = create_proc_entry(table->procname, mode, root);
  1339. if (!de)
  1340. continue;
  1341. de->set = set;
  1342. de->data = (void *) table;
  1343. if (table->proc_handler)
  1344. de->proc_fops = &proc_sys_file_operations;
  1345. }
  1346. table->de = de;
  1347. if (de->mode & S_IFDIR)
  1348. register_proc_table(table->child, de, set);
  1349. }
  1350. }
  1351. /*
  1352. * Unregister a /proc sysctl table and any subdirectories.
  1353. */
  1354. static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
  1355. {
  1356. struct proc_dir_entry *de;
  1357. for (; table->ctl_name; table++) {
  1358. if (!(de = table->de))
  1359. continue;
  1360. if (de->mode & S_IFDIR) {
  1361. if (!table->child) {
  1362. printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
  1363. continue;
  1364. }
  1365. unregister_proc_table(table->child, de);
  1366. /* Don't unregister directories which still have entries.. */
  1367. if (de->subdir)
  1368. continue;
  1369. }
  1370. /*
  1371. * In any case, mark the entry as goner; we'll keep it
  1372. * around if it's busy, but we'll know to do nothing with
  1373. * its fields. We are under sysctl_lock here.
  1374. */
  1375. de->data = NULL;
  1376. /* Don't unregister proc entries that are still being used.. */
  1377. if (atomic_read(&de->count))
  1378. continue;
  1379. table->de = NULL;
  1380. remove_proc_entry(table->procname, root);
  1381. }
  1382. }
  1383. static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
  1384. size_t count, loff_t *ppos)
  1385. {
  1386. int op;
  1387. struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
  1388. struct ctl_table *table;
  1389. size_t res;
  1390. ssize_t error = -ENOTDIR;
  1391. spin_lock(&sysctl_lock);
  1392. if (de && de->data && use_table(de->set)) {
  1393. /*
  1394. * at that point we know that sysctl was not unregistered
  1395. * and won't be until we finish
  1396. */
  1397. spin_unlock(&sysctl_lock);
  1398. table = (struct ctl_table *) de->data;
  1399. if (!table || !table->proc_handler)
  1400. goto out;
  1401. error = -EPERM;
  1402. op = (write ? 002 : 004);
  1403. if (ctl_perm(table, op))
  1404. goto out;
  1405. /* careful: calling conventions are nasty here */
  1406. res = count;
  1407. error = (*table->proc_handler)(table, write, file,
  1408. buf, &res, ppos);
  1409. if (!error)
  1410. error = res;
  1411. out:
  1412. spin_lock(&sysctl_lock);
  1413. unuse_table(de->set);
  1414. }
  1415. spin_unlock(&sysctl_lock);
  1416. return error;
  1417. }
  1418. static int proc_opensys(struct inode *inode, struct file *file)
  1419. {
  1420. if (file->f_mode & FMODE_WRITE) {
  1421. /*
  1422. * sysctl entries that are not writable,
  1423. * are _NOT_ writable, capabilities or not.
  1424. */
  1425. if (!(inode->i_mode & S_IWUSR))
  1426. return -EPERM;
  1427. }
  1428. return 0;
  1429. }
  1430. static ssize_t proc_readsys(struct file * file, char __user * buf,
  1431. size_t count, loff_t *ppos)
  1432. {
  1433. return do_rw_proc(0, file, buf, count, ppos);
  1434. }
  1435. static ssize_t proc_writesys(struct file * file, const char __user * buf,
  1436. size_t count, loff_t *ppos)
  1437. {
  1438. return do_rw_proc(1, file, (char __user *) buf, count, ppos);
  1439. }
  1440. /**
  1441. * proc_dostring - read a string sysctl
  1442. * @table: the sysctl table
  1443. * @write: %TRUE if this is a write to the sysctl file
  1444. * @filp: the file structure
  1445. * @buffer: the user buffer
  1446. * @lenp: the size of the user buffer
  1447. * @ppos: file position
  1448. *
  1449. * Reads/writes a string from/to the user buffer. If the kernel
  1450. * buffer provided is not large enough to hold the string, the
  1451. * string is truncated. The copied string is %NULL-terminated.
  1452. * If the string is being read by the user process, it is copied
  1453. * and a newline '\n' is added. It is truncated if the buffer is
  1454. * not large enough.
  1455. *
  1456. * Returns 0 on success.
  1457. */
  1458. int proc_dostring(ctl_table *table, int write, struct file *filp,
  1459. void __user *buffer, size_t *lenp, loff_t *ppos)
  1460. {
  1461. size_t len;
  1462. char __user *p;
  1463. char c;
  1464. if (!table->data || !table->maxlen || !*lenp ||
  1465. (*ppos && !write)) {
  1466. *lenp = 0;
  1467. return 0;
  1468. }
  1469. if (write) {
  1470. len = 0;
  1471. p = buffer;
  1472. while (len < *lenp) {
  1473. if (get_user(c, p++))
  1474. return -EFAULT;
  1475. if (c == 0 || c == '\n')
  1476. break;
  1477. len++;
  1478. }
  1479. if (len >= table->maxlen)
  1480. len = table->maxlen-1;
  1481. if(copy_from_user(table->data, buffer, len))
  1482. return -EFAULT;
  1483. ((char *) table->data)[len] = 0;
  1484. *ppos += *lenp;
  1485. } else {
  1486. len = strlen(table->data);
  1487. if (len > table->maxlen)
  1488. len = table->maxlen;
  1489. if (len > *lenp)
  1490. len = *lenp;
  1491. if (len)
  1492. if(copy_to_user(buffer, table->data, len))
  1493. return -EFAULT;
  1494. if (len < *lenp) {
  1495. if(put_user('\n', ((char __user *) buffer) + len))
  1496. return -EFAULT;
  1497. len++;
  1498. }
  1499. *lenp = len;
  1500. *ppos += len;
  1501. }
  1502. return 0;
  1503. }
  1504. /*
  1505. * Special case of dostring for the UTS structure. This has locks
  1506. * to observe. Should this be in kernel/sys.c ????
  1507. */
  1508. static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
  1509. void __user *buffer, size_t *lenp, loff_t *ppos)
  1510. {
  1511. int r;
  1512. if (!write) {
  1513. down_read(&uts_sem);
  1514. r=proc_dostring(table,0,filp,buffer,lenp, ppos);
  1515. up_read(&uts_sem);
  1516. } else {
  1517. down_write(&uts_sem);
  1518. r=proc_dostring(table,1,filp,buffer,lenp, ppos);
  1519. up_write(&uts_sem);
  1520. }
  1521. return r;
  1522. }
  1523. static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
  1524. int *valp,
  1525. int write, void *data)
  1526. {
  1527. if (write) {
  1528. *valp = *negp ? -*lvalp : *lvalp;
  1529. } else {
  1530. int val = *valp;
  1531. if (val < 0) {
  1532. *negp = -1;
  1533. *lvalp = (unsigned long)-val;
  1534. } else {
  1535. *negp = 0;
  1536. *lvalp = (unsigned long)val;
  1537. }
  1538. }
  1539. return 0;
  1540. }
  1541. static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
  1542. void __user *buffer, size_t *lenp, loff_t *ppos,
  1543. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1544. int write, void *data),
  1545. void *data)
  1546. {
  1547. #define TMPBUFLEN 21
  1548. int *i, vleft, first=1, neg, val;
  1549. unsigned long lval;
  1550. size_t left, len;
  1551. char buf[TMPBUFLEN], *p;
  1552. char __user *s = buffer;
  1553. if (!table->data || !table->maxlen || !*lenp ||
  1554. (*ppos && !write)) {
  1555. *lenp = 0;
  1556. return 0;
  1557. }
  1558. i = (int *) table->data;
  1559. vleft = table->maxlen / sizeof(*i);
  1560. left = *lenp;
  1561. if (!conv)
  1562. conv = do_proc_dointvec_conv;
  1563. for (; left && vleft--; i++, first=0) {
  1564. if (write) {
  1565. while (left) {
  1566. char c;
  1567. if (get_user(c, s))
  1568. return -EFAULT;
  1569. if (!isspace(c))
  1570. break;
  1571. left--;
  1572. s++;
  1573. }
  1574. if (!left)
  1575. break;
  1576. neg = 0;
  1577. len = left;
  1578. if (len > sizeof(buf) - 1)
  1579. len = sizeof(buf) - 1;
  1580. if (copy_from_user(buf, s, len))
  1581. return -EFAULT;
  1582. buf[len] = 0;
  1583. p = buf;
  1584. if (*p == '-' && left > 1) {
  1585. neg = 1;
  1586. left--, p++;
  1587. }
  1588. if (*p < '0' || *p > '9')
  1589. break;
  1590. lval = simple_strtoul(p, &p, 0);
  1591. len = p-buf;
  1592. if ((len < left) && *p && !isspace(*p))
  1593. break;
  1594. if (neg)
  1595. val = -val;
  1596. s += len;
  1597. left -= len;
  1598. if (conv(&neg, &lval, i, 1, data))
  1599. break;
  1600. } else {
  1601. p = buf;
  1602. if (!first)
  1603. *p++ = '\t';
  1604. if (conv(&neg, &lval, i, 0, data))
  1605. break;
  1606. sprintf(p, "%s%lu", neg ? "-" : "", lval);
  1607. len = strlen(buf);
  1608. if (len > left)
  1609. len = left;
  1610. if(copy_to_user(s, buf, len))
  1611. return -EFAULT;
  1612. left -= len;
  1613. s += len;
  1614. }
  1615. }
  1616. if (!write && !first && left) {
  1617. if(put_user('\n', s))
  1618. return -EFAULT;
  1619. left--, s++;
  1620. }
  1621. if (write) {
  1622. while (left) {
  1623. char c;
  1624. if (get_user(c, s++))
  1625. return -EFAULT;
  1626. if (!isspace(c))
  1627. break;
  1628. left--;
  1629. }
  1630. }
  1631. if (write && first)
  1632. return -EINVAL;
  1633. *lenp -= left;
  1634. *ppos += *lenp;
  1635. return 0;
  1636. #undef TMPBUFLEN
  1637. }
  1638. /**
  1639. * proc_dointvec - read a vector of integers
  1640. * @table: the sysctl table
  1641. * @write: %TRUE if this is a write to the sysctl file
  1642. * @filp: the file structure
  1643. * @buffer: the user buffer
  1644. * @lenp: the size of the user buffer
  1645. * @ppos: file position
  1646. *
  1647. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1648. * values from/to the user buffer, treated as an ASCII string.
  1649. *
  1650. * Returns 0 on success.
  1651. */
  1652. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  1653. void __user *buffer, size_t *lenp, loff_t *ppos)
  1654. {
  1655. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1656. NULL,NULL);
  1657. }
  1658. #define OP_SET 0
  1659. #define OP_AND 1
  1660. #define OP_OR 2
  1661. #define OP_MAX 3
  1662. #define OP_MIN 4
  1663. static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
  1664. int *valp,
  1665. int write, void *data)
  1666. {
  1667. int op = *(int *)data;
  1668. if (write) {
  1669. int val = *negp ? -*lvalp : *lvalp;
  1670. switch(op) {
  1671. case OP_SET: *valp = val; break;
  1672. case OP_AND: *valp &= val; break;
  1673. case OP_OR: *valp |= val; break;
  1674. case OP_MAX: if(*valp < val)
  1675. *valp = val;
  1676. break;
  1677. case OP_MIN: if(*valp > val)
  1678. *valp = val;
  1679. break;
  1680. }
  1681. } else {
  1682. int val = *valp;
  1683. if (val < 0) {
  1684. *negp = -1;
  1685. *lvalp = (unsigned long)-val;
  1686. } else {
  1687. *negp = 0;
  1688. *lvalp = (unsigned long)val;
  1689. }
  1690. }
  1691. return 0;
  1692. }
  1693. /*
  1694. * init may raise the set.
  1695. */
  1696. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  1697. void __user *buffer, size_t *lenp, loff_t *ppos)
  1698. {
  1699. int op;
  1700. if (!capable(CAP_SYS_MODULE)) {
  1701. return -EPERM;
  1702. }
  1703. op = (current->pid == 1) ? OP_SET : OP_AND;
  1704. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1705. do_proc_dointvec_bset_conv,&op);
  1706. }
  1707. struct do_proc_dointvec_minmax_conv_param {
  1708. int *min;
  1709. int *max;
  1710. };
  1711. static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
  1712. int *valp,
  1713. int write, void *data)
  1714. {
  1715. struct do_proc_dointvec_minmax_conv_param *param = data;
  1716. if (write) {
  1717. int val = *negp ? -*lvalp : *lvalp;
  1718. if ((param->min && *param->min > val) ||
  1719. (param->max && *param->max < val))
  1720. return -EINVAL;
  1721. *valp = val;
  1722. } else {
  1723. int val = *valp;
  1724. if (val < 0) {
  1725. *negp = -1;
  1726. *lvalp = (unsigned long)-val;
  1727. } else {
  1728. *negp = 0;
  1729. *lvalp = (unsigned long)val;
  1730. }
  1731. }
  1732. return 0;
  1733. }
  1734. /**
  1735. * proc_dointvec_minmax - read a vector of integers with min/max values
  1736. * @table: the sysctl table
  1737. * @write: %TRUE if this is a write to the sysctl file
  1738. * @filp: the file structure
  1739. * @buffer: the user buffer
  1740. * @lenp: the size of the user buffer
  1741. * @ppos: file position
  1742. *
  1743. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1744. * values from/to the user buffer, treated as an ASCII string.
  1745. *
  1746. * This routine will ensure the values are within the range specified by
  1747. * table->extra1 (min) and table->extra2 (max).
  1748. *
  1749. * Returns 0 on success.
  1750. */
  1751. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  1752. void __user *buffer, size_t *lenp, loff_t *ppos)
  1753. {
  1754. struct do_proc_dointvec_minmax_conv_param param = {
  1755. .min = (int *) table->extra1,
  1756. .max = (int *) table->extra2,
  1757. };
  1758. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  1759. do_proc_dointvec_minmax_conv, &param);
  1760. }
  1761. static int do_proc_doulongvec_minmax(ctl_table *table, int write,
  1762. struct file *filp,
  1763. void __user *buffer,
  1764. size_t *lenp, loff_t *ppos,
  1765. unsigned long convmul,
  1766. unsigned long convdiv)
  1767. {
  1768. #define TMPBUFLEN 21
  1769. unsigned long *i, *min, *max, val;
  1770. int vleft, first=1, neg;
  1771. size_t len, left;
  1772. char buf[TMPBUFLEN], *p;
  1773. char __user *s = buffer;
  1774. if (!table->data || !table->maxlen || !*lenp ||
  1775. (*ppos && !write)) {
  1776. *lenp = 0;
  1777. return 0;
  1778. }
  1779. i = (unsigned long *) table->data;
  1780. min = (unsigned long *) table->extra1;
  1781. max = (unsigned long *) table->extra2;
  1782. vleft = table->maxlen / sizeof(unsigned long);
  1783. left = *lenp;
  1784. for (; left && vleft--; i++, min++, max++, first=0) {
  1785. if (write) {
  1786. while (left) {
  1787. char c;
  1788. if (get_user(c, s))
  1789. return -EFAULT;
  1790. if (!isspace(c))
  1791. break;
  1792. left--;
  1793. s++;
  1794. }
  1795. if (!left)
  1796. break;
  1797. neg = 0;
  1798. len = left;
  1799. if (len > TMPBUFLEN-1)
  1800. len = TMPBUFLEN-1;
  1801. if (copy_from_user(buf, s, len))
  1802. return -EFAULT;
  1803. buf[len] = 0;
  1804. p = buf;
  1805. if (*p == '-' && left > 1) {
  1806. neg = 1;
  1807. left--, p++;
  1808. }
  1809. if (*p < '0' || *p > '9')
  1810. break;
  1811. val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
  1812. len = p-buf;
  1813. if ((len < left) && *p && !isspace(*p))
  1814. break;
  1815. if (neg)
  1816. val = -val;
  1817. s += len;
  1818. left -= len;
  1819. if(neg)
  1820. continue;
  1821. if ((min && val < *min) || (max && val > *max))
  1822. continue;
  1823. *i = val;
  1824. } else {
  1825. p = buf;
  1826. if (!first)
  1827. *p++ = '\t';
  1828. sprintf(p, "%lu", convdiv * (*i) / convmul);
  1829. len = strlen(buf);
  1830. if (len > left)
  1831. len = left;
  1832. if(copy_to_user(s, buf, len))
  1833. return -EFAULT;
  1834. left -= len;
  1835. s += len;
  1836. }
  1837. }
  1838. if (!write && !first && left) {
  1839. if(put_user('\n', s))
  1840. return -EFAULT;
  1841. left--, s++;
  1842. }
  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. }
  1852. }
  1853. if (write && first)
  1854. return -EINVAL;
  1855. *lenp -= left;
  1856. *ppos += *lenp;
  1857. return 0;
  1858. #undef TMPBUFLEN
  1859. }
  1860. /**
  1861. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  1862. * @table: the sysctl table
  1863. * @write: %TRUE if this is a write to the sysctl file
  1864. * @filp: the file structure
  1865. * @buffer: the user buffer
  1866. * @lenp: the size of the user buffer
  1867. * @ppos: file position
  1868. *
  1869. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1870. * values from/to the user buffer, treated as an ASCII string.
  1871. *
  1872. * This routine will ensure the values are within the range specified by
  1873. * table->extra1 (min) and table->extra2 (max).
  1874. *
  1875. * Returns 0 on success.
  1876. */
  1877. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  1878. void __user *buffer, size_t *lenp, loff_t *ppos)
  1879. {
  1880. return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
  1881. }
  1882. /**
  1883. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  1884. * @table: the sysctl table
  1885. * @write: %TRUE if this is a write to the sysctl file
  1886. * @filp: the file structure
  1887. * @buffer: the user buffer
  1888. * @lenp: the size of the user buffer
  1889. * @ppos: file position
  1890. *
  1891. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1892. * values from/to the user buffer, treated as an ASCII string. The values
  1893. * are treated as milliseconds, and converted to jiffies when they are stored.
  1894. *
  1895. * This routine will ensure the values are within the range specified by
  1896. * table->extra1 (min) and table->extra2 (max).
  1897. *
  1898. * Returns 0 on success.
  1899. */
  1900. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  1901. struct file *filp,
  1902. void __user *buffer,
  1903. size_t *lenp, loff_t *ppos)
  1904. {
  1905. return do_proc_doulongvec_minmax(table, write, filp, buffer,
  1906. lenp, ppos, HZ, 1000l);
  1907. }
  1908. static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
  1909. int *valp,
  1910. int write, void *data)
  1911. {
  1912. if (write) {
  1913. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  1914. } else {
  1915. int val = *valp;
  1916. unsigned long lval;
  1917. if (val < 0) {
  1918. *negp = -1;
  1919. lval = (unsigned long)-val;
  1920. } else {
  1921. *negp = 0;
  1922. lval = (unsigned long)val;
  1923. }
  1924. *lvalp = lval / HZ;
  1925. }
  1926. return 0;
  1927. }
  1928. static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
  1929. int *valp,
  1930. int write, void *data)
  1931. {
  1932. if (write) {
  1933. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  1934. } else {
  1935. int val = *valp;
  1936. unsigned long lval;
  1937. if (val < 0) {
  1938. *negp = -1;
  1939. lval = (unsigned long)-val;
  1940. } else {
  1941. *negp = 0;
  1942. lval = (unsigned long)val;
  1943. }
  1944. *lvalp = jiffies_to_clock_t(lval);
  1945. }
  1946. return 0;
  1947. }
  1948. static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
  1949. int *valp,
  1950. int write, void *data)
  1951. {
  1952. if (write) {
  1953. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  1954. } else {
  1955. int val = *valp;
  1956. unsigned long lval;
  1957. if (val < 0) {
  1958. *negp = -1;
  1959. lval = (unsigned long)-val;
  1960. } else {
  1961. *negp = 0;
  1962. lval = (unsigned long)val;
  1963. }
  1964. *lvalp = jiffies_to_msecs(lval);
  1965. }
  1966. return 0;
  1967. }
  1968. /**
  1969. * proc_dointvec_jiffies - read a vector of integers as seconds
  1970. * @table: the sysctl table
  1971. * @write: %TRUE if this is a write to the sysctl file
  1972. * @filp: the file structure
  1973. * @buffer: the user buffer
  1974. * @lenp: the size of the user buffer
  1975. * @ppos: file position
  1976. *
  1977. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1978. * values from/to the user buffer, treated as an ASCII string.
  1979. * The values read are assumed to be in seconds, and are converted into
  1980. * jiffies.
  1981. *
  1982. * Returns 0 on success.
  1983. */
  1984. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  1985. void __user *buffer, size_t *lenp, loff_t *ppos)
  1986. {
  1987. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1988. do_proc_dointvec_jiffies_conv,NULL);
  1989. }
  1990. /**
  1991. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  1992. * @table: the sysctl table
  1993. * @write: %TRUE if this is a write to the sysctl file
  1994. * @filp: the file structure
  1995. * @buffer: the user buffer
  1996. * @lenp: the size of the user buffer
  1997. * @ppos: pointer to the file position
  1998. *
  1999. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2000. * values from/to the user buffer, treated as an ASCII string.
  2001. * The values read are assumed to be in 1/USER_HZ seconds, and
  2002. * are converted into jiffies.
  2003. *
  2004. * Returns 0 on success.
  2005. */
  2006. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2007. void __user *buffer, size_t *lenp, loff_t *ppos)
  2008. {
  2009. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2010. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2011. }
  2012. /**
  2013. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2014. * @table: the sysctl table
  2015. * @write: %TRUE if this is a write to the sysctl file
  2016. * @filp: the file structure
  2017. * @buffer: the user buffer
  2018. * @lenp: the size of the user buffer
  2019. * @ppos: file position
  2020. * @ppos: the current position in the file
  2021. *
  2022. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2023. * values from/to the user buffer, treated as an ASCII string.
  2024. * The values read are assumed to be in 1/1000 seconds, and
  2025. * are converted into jiffies.
  2026. *
  2027. * Returns 0 on success.
  2028. */
  2029. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2030. void __user *buffer, size_t *lenp, loff_t *ppos)
  2031. {
  2032. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  2033. do_proc_dointvec_ms_jiffies_conv, NULL);
  2034. }
  2035. #else /* CONFIG_PROC_FS */
  2036. int proc_dostring(ctl_table *table, int write, struct file *filp,
  2037. void __user *buffer, size_t *lenp, loff_t *ppos)
  2038. {
  2039. return -ENOSYS;
  2040. }
  2041. static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
  2042. void __user *buffer, size_t *lenp, loff_t *ppos)
  2043. {
  2044. return -ENOSYS;
  2045. }
  2046. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2047. void __user *buffer, size_t *lenp, loff_t *ppos)
  2048. {
  2049. return -ENOSYS;
  2050. }
  2051. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2052. void __user *buffer, size_t *lenp, loff_t *ppos)
  2053. {
  2054. return -ENOSYS;
  2055. }
  2056. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2057. void __user *buffer, size_t *lenp, loff_t *ppos)
  2058. {
  2059. return -ENOSYS;
  2060. }
  2061. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2062. void __user *buffer, size_t *lenp, loff_t *ppos)
  2063. {
  2064. return -ENOSYS;
  2065. }
  2066. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2067. void __user *buffer, size_t *lenp, loff_t *ppos)
  2068. {
  2069. return -ENOSYS;
  2070. }
  2071. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2072. void __user *buffer, size_t *lenp, loff_t *ppos)
  2073. {
  2074. return -ENOSYS;
  2075. }
  2076. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2077. void __user *buffer, size_t *lenp, loff_t *ppos)
  2078. {
  2079. return -ENOSYS;
  2080. }
  2081. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2082. struct file *filp,
  2083. void __user *buffer,
  2084. size_t *lenp, loff_t *ppos)
  2085. {
  2086. return -ENOSYS;
  2087. }
  2088. #endif /* CONFIG_PROC_FS */
  2089. /*
  2090. * General sysctl support routines
  2091. */
  2092. /* The generic string strategy routine: */
  2093. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2094. void __user *oldval, size_t __user *oldlenp,
  2095. void __user *newval, size_t newlen, void **context)
  2096. {
  2097. if (!table->data || !table->maxlen)
  2098. return -ENOTDIR;
  2099. if (oldval && oldlenp) {
  2100. size_t bufsize;
  2101. if (get_user(bufsize, oldlenp))
  2102. return -EFAULT;
  2103. if (bufsize) {
  2104. size_t len = strlen(table->data), copied;
  2105. /* This shouldn't trigger for a well-formed sysctl */
  2106. if (len > table->maxlen)
  2107. len = table->maxlen;
  2108. /* Copy up to a max of bufsize-1 bytes of the string */
  2109. copied = (len >= bufsize) ? bufsize - 1 : len;
  2110. if (copy_to_user(oldval, table->data, copied) ||
  2111. put_user(0, (char __user *)(oldval + copied)))
  2112. return -EFAULT;
  2113. if (put_user(len, oldlenp))
  2114. return -EFAULT;
  2115. }
  2116. }
  2117. if (newval && newlen) {
  2118. size_t len = newlen;
  2119. if (len > table->maxlen)
  2120. len = table->maxlen;
  2121. if(copy_from_user(table->data, newval, len))
  2122. return -EFAULT;
  2123. if (len == table->maxlen)
  2124. len--;
  2125. ((char *) table->data)[len] = 0;
  2126. }
  2127. return 1;
  2128. }
  2129. /*
  2130. * This function makes sure that all of the integers in the vector
  2131. * are between the minimum and maximum values given in the arrays
  2132. * table->extra1 and table->extra2, respectively.
  2133. */
  2134. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2135. void __user *oldval, size_t __user *oldlenp,
  2136. void __user *newval, size_t newlen, void **context)
  2137. {
  2138. if (newval && newlen) {
  2139. int __user *vec = (int __user *) newval;
  2140. int *min = (int *) table->extra1;
  2141. int *max = (int *) table->extra2;
  2142. size_t length;
  2143. int i;
  2144. if (newlen % sizeof(int) != 0)
  2145. return -EINVAL;
  2146. if (!table->extra1 && !table->extra2)
  2147. return 0;
  2148. if (newlen > table->maxlen)
  2149. newlen = table->maxlen;
  2150. length = newlen / sizeof(int);
  2151. for (i = 0; i < length; i++) {
  2152. int value;
  2153. if (get_user(value, vec + i))
  2154. return -EFAULT;
  2155. if (min && value < min[i])
  2156. return -EINVAL;
  2157. if (max && value > max[i])
  2158. return -EINVAL;
  2159. }
  2160. }
  2161. return 0;
  2162. }
  2163. /* Strategy function to convert jiffies to seconds */
  2164. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2165. void __user *oldval, size_t __user *oldlenp,
  2166. void __user *newval, size_t newlen, void **context)
  2167. {
  2168. if (oldval) {
  2169. size_t olen;
  2170. if (oldlenp) {
  2171. if (get_user(olen, oldlenp))
  2172. return -EFAULT;
  2173. if (olen!=sizeof(int))
  2174. return -EINVAL;
  2175. }
  2176. if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
  2177. (oldlenp && put_user(sizeof(int),oldlenp)))
  2178. return -EFAULT;
  2179. }
  2180. if (newval && newlen) {
  2181. int new;
  2182. if (newlen != sizeof(int))
  2183. return -EINVAL;
  2184. if (get_user(new, (int __user *)newval))
  2185. return -EFAULT;
  2186. *(int *)(table->data) = new*HZ;
  2187. }
  2188. return 1;
  2189. }
  2190. /* Strategy function to convert jiffies to seconds */
  2191. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2192. void __user *oldval, size_t __user *oldlenp,
  2193. void __user *newval, size_t newlen, void **context)
  2194. {
  2195. if (oldval) {
  2196. size_t olen;
  2197. if (oldlenp) {
  2198. if (get_user(olen, oldlenp))
  2199. return -EFAULT;
  2200. if (olen!=sizeof(int))
  2201. return -EINVAL;
  2202. }
  2203. if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
  2204. (oldlenp && put_user(sizeof(int),oldlenp)))
  2205. return -EFAULT;
  2206. }
  2207. if (newval && newlen) {
  2208. int new;
  2209. if (newlen != sizeof(int))
  2210. return -EINVAL;
  2211. if (get_user(new, (int __user *)newval))
  2212. return -EFAULT;
  2213. *(int *)(table->data) = msecs_to_jiffies(new);
  2214. }
  2215. return 1;
  2216. }
  2217. #else /* CONFIG_SYSCTL */
  2218. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  2219. {
  2220. return -ENOSYS;
  2221. }
  2222. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2223. void __user *oldval, size_t __user *oldlenp,
  2224. void __user *newval, size_t newlen, void **context)
  2225. {
  2226. return -ENOSYS;
  2227. }
  2228. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2229. void __user *oldval, size_t __user *oldlenp,
  2230. void __user *newval, size_t newlen, void **context)
  2231. {
  2232. return -ENOSYS;
  2233. }
  2234. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2235. void __user *oldval, size_t __user *oldlenp,
  2236. void __user *newval, size_t newlen, void **context)
  2237. {
  2238. return -ENOSYS;
  2239. }
  2240. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2241. void __user *oldval, size_t __user *oldlenp,
  2242. void __user *newval, size_t newlen, void **context)
  2243. {
  2244. return -ENOSYS;
  2245. }
  2246. int proc_dostring(ctl_table *table, int write, struct file *filp,
  2247. void __user *buffer, size_t *lenp, loff_t *ppos)
  2248. {
  2249. return -ENOSYS;
  2250. }
  2251. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2252. void __user *buffer, size_t *lenp, loff_t *ppos)
  2253. {
  2254. return -ENOSYS;
  2255. }
  2256. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2257. void __user *buffer, size_t *lenp, loff_t *ppos)
  2258. {
  2259. return -ENOSYS;
  2260. }
  2261. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2262. void __user *buffer, size_t *lenp, loff_t *ppos)
  2263. {
  2264. return -ENOSYS;
  2265. }
  2266. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2267. void __user *buffer, size_t *lenp, loff_t *ppos)
  2268. {
  2269. return -ENOSYS;
  2270. }
  2271. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2272. void __user *buffer, size_t *lenp, loff_t *ppos)
  2273. {
  2274. return -ENOSYS;
  2275. }
  2276. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2277. void __user *buffer, size_t *lenp, loff_t *ppos)
  2278. {
  2279. return -ENOSYS;
  2280. }
  2281. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2282. void __user *buffer, size_t *lenp, loff_t *ppos)
  2283. {
  2284. return -ENOSYS;
  2285. }
  2286. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2287. struct file *filp,
  2288. void __user *buffer,
  2289. size_t *lenp, loff_t *ppos)
  2290. {
  2291. return -ENOSYS;
  2292. }
  2293. struct ctl_table_header * register_sysctl_table(ctl_table * table,
  2294. int insert_at_head)
  2295. {
  2296. return NULL;
  2297. }
  2298. void unregister_sysctl_table(struct ctl_table_header * table)
  2299. {
  2300. }
  2301. #endif /* CONFIG_SYSCTL */
  2302. /*
  2303. * No sense putting this after each symbol definition, twice,
  2304. * exception granted :-)
  2305. */
  2306. EXPORT_SYMBOL(proc_dointvec);
  2307. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2308. EXPORT_SYMBOL(proc_dointvec_minmax);
  2309. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2310. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2311. EXPORT_SYMBOL(proc_dostring);
  2312. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2313. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2314. EXPORT_SYMBOL(register_sysctl_table);
  2315. EXPORT_SYMBOL(sysctl_intvec);
  2316. EXPORT_SYMBOL(sysctl_jiffies);
  2317. EXPORT_SYMBOL(sysctl_ms_jiffies);
  2318. EXPORT_SYMBOL(sysctl_string);
  2319. EXPORT_SYMBOL(unregister_sysctl_table);