sysctl.c 55 KB

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