summaryrefslogtreecommitdiffstats
path: root/sys/dev/md
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2010-10-18 04:26:32 +0000
committermarcel <marcel@FreeBSD.org>2010-10-18 04:26:32 +0000
commit9d3ef80ee12e175421aac7858c17ebf6affe796b (patch)
tree62c1ef8c69475cc1a0ea89894c21e2993fbfb1db /sys/dev/md
parenta21eca04b43605792bf4059778d888f7d1542be6 (diff)
downloadFreeBSD-src-9d3ef80ee12e175421aac7858c17ebf6affe796b.zip
FreeBSD-src-9d3ef80ee12e175421aac7858c17ebf6affe796b.tar.gz
Allow the MDIOCATTACH ioctl operation to originate from within the kernel.
To protect against malicious software, we demand that the file name is at a particular location (i.e. appended to the mdio structure) for it to be treated as in-kernel.
Diffstat (limited to 'sys/dev/md')
-rw-r--r--sys/dev/md/md.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c
index 47aa751..6c3484e 100644
--- a/sys/dev/md/md.c
+++ b/sys/dev/md/md.c
@@ -909,18 +909,26 @@ mdcreate_vnode(struct md_s *sc, struct md_ioctl *mdio, struct thread *td)
{
struct vattr vattr;
struct nameidata nd;
+ char *fname;
int error, flags, vfslocked;
- error = copyinstr(mdio->md_file, sc->file, sizeof(sc->file), NULL);
- if (error != 0)
- return (error);
- flags = FREAD|FWRITE;
/*
- * If the user specified that this is a read only device, unset the
- * FWRITE mask before trying to open the backing store.
+ * Kernel-originated requests must have the filename appended
+ * to the mdio structure to protect against malicious software.
+ */
+ fname = mdio->md_file;
+ if ((void *)fname != (void *)(mdio + 1)) {
+ error = copyinstr(fname, sc->file, sizeof(sc->file), NULL);
+ if (error != 0)
+ return (error);
+ } else
+ strlcpy(sc->file, fname, sizeof(sc->file));
+
+ /*
+ * If the user specified that this is a read only device, don't
+ * set the FWRITE mask before trying to open the backing store.
*/
- if ((mdio->md_options & MD_READONLY) != 0)
- flags &= ~FWRITE;
+ flags = FREAD | ((mdio->md_options & MD_READONLY) ? 0 : FWRITE);
NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, sc->file, td);
error = vn_open(&nd, &flags, 0, NULL);
if (error != 0)
OpenPOWER on IntegriCloud