1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-30 08:19:09 +00:00

Disallow attaching preloaded memory disks via ioctl.

- The feature is dangerous because the kernel code didn'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
Discussed on:	freebsd-hackers
This commit is contained in:
Jaakko Heinonen 2012-11-21 16:56:47 +00:00
parent aef8ef5168
commit 734e78dfcb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=243372
2 changed files with 7 additions and 26 deletions

View File

@ -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;

View File

@ -854,27 +854,6 @@ 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)
{
if (mdio->md_options & ~(MD_AUTOUNIT | MD_FORCE))
return (EINVAL);
if (mdio->md_base == 0)
return (EINVAL);
sc->flags = mdio->md_options & MD_FORCE;
/* Cast to pointer size, then to pointer to avoid warning */
sc->pl_ptr = (u_char *)(uintptr_t)mdio->md_base;
sc->pl_len = (size_t)sc->mediasize;
return (0);
}
static int
mdcreate_malloc(struct md_s *sc, struct md_ioctl *mdio)
{
@ -1238,8 +1217,12 @@ xmdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread
error = mdcreate_malloc(sc, mdio);
break;
case MD_PRELOAD:
sc->start = mdstart_preload;
error = mdcreate_preload(sc, mdio);
/*
* We disallow attaching preloaded memory disks via
* ioctl. Preloaded memory disks are automatically
* attached in g_md_init().
*/
error = EOPNOTSUPP;
break;
case MD_VNODE:
sc->start = mdstart_vnode;