sysctl.c 57 KB

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