[patch] md(4) and preloaded memory disks
Jaakko Heinonen
jh at FreeBSD.org
Tue Nov 6 18:28:04 UTC 2012
Hi,
I plan to commit the patch below to disallow attaching preloaded memory
disks via ioctl. I didn't find anything that would really use this
undocumented feature.
---
Disallow attaching preloaded memory disks via ioctl.
- The feature is dangerous because the kernel code doesn't check
validity of the memory address provided from user space.
- It seems that mdconfig(8) never really supported attaching preloaded
memory disks.
- Preloaded memory disks are automatically attached during md(4)
initialization. Thus there shouldn't be much use for the feature.
PR: kern/169683
%%%
Index: sbin/mdconfig/mdconfig.c
===================================================================
--- sbin/mdconfig/mdconfig.c (revision 242608)
+++ sbin/mdconfig/mdconfig.c (working copy)
@@ -84,7 +84,7 @@ usage(void)
" mdconfig -r -u unit -s size [-o [no]force]\n"
" mdconfig -l [-v] [-n] [-u unit]\n"
" mdconfig file\n");
- fprintf(stderr, "\t\ttype = {malloc, preload, vnode, swap}\n");
+ fprintf(stderr, "\t\ttype = {malloc, vnode, swap}\n");
fprintf(stderr, "\t\toption = {cluster, compress, reserve}\n");
fprintf(stderr, "\t\tsize = %%d (512 byte blocks), %%db (B),\n");
fprintf(stderr, "\t\t %%dk (kB), %%dm (MB), %%dg (GB) or\n");
@@ -148,8 +148,6 @@ main(int argc, char **argv)
if (!strcmp(optarg, "malloc")) {
mdio.md_type = MD_MALLOC;
mdio.md_options |= MD_AUTOUNIT | MD_COMPRESS;
- } else if (!strcmp(optarg, "preload")) {
- mdio.md_type = MD_PRELOAD;
} else if (!strcmp(optarg, "vnode")) {
mdio.md_type = MD_VNODE;
mdio.md_options |= MD_CLUSTER | MD_AUTOUNIT | MD_COMPRESS;
Index: sys/dev/md/md.c
===================================================================
--- sys/dev/md/md.c (revision 242608)
+++ sys/dev/md/md.c (working copy)
@@ -845,15 +845,20 @@ mdinit(struct md_s *sc)
DEVSTAT_ALL_SUPPORTED, DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX);
}
-/*
- * XXX: we should check that the range they feed us is mapped.
- * XXX: we should implement read-only.
- */
-
static int
mdcreate_preload(struct md_s *sc, struct md_ioctl *mdio)
{
+ /*
+ * Currently we disallow attaching preloaded memory disks via ioctl.
+ * Preloaded memory disks are automatically attached in mdinit().
+ */
+#if 0
+ /*
+ * XXX: We should check that the range they feed us is mapped and
+ * a valid memory disk.
+ * XXX: We should implement read-only.
+ */
if (mdio->md_options & ~(MD_AUTOUNIT | MD_FORCE))
return (EINVAL);
if (mdio->md_base == 0)
@@ -863,6 +868,9 @@ mdcreate_preload(struct md_s *sc, struct
sc->pl_ptr = (u_char *)(uintptr_t)mdio->md_base;
sc->pl_len = (size_t)sc->mediasize;
return (0);
+#else
+ return (EOPNOTSUPP);
+#endif
}
%%%
--
Jaakko
More information about the freebsd-hackers
mailing list