diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -93,6 +93,7 @@ #include #include #include +#include #include #include @@ -1777,6 +1778,9 @@ sc = mdfind(mdr->md_unit); if (sc == NULL) return (ENOENT); + if (priv_check(td, PRIV_VFS_ADMIN) != 0) + if (!sc->cred || cr_cansee(td->td_ucred, sc->cred)) + return (EPERM); if (sc->opencount != 0 && !(sc->flags & MD_FORCE) && !(mdr->md_options & MD_FORCE)) return (EBUSY); @@ -1795,7 +1799,7 @@ } static int -kern_mdresize_locked(struct md_req *mdr) +kern_mdresize_locked(struct thread *td, struct md_req *mdr) { struct md_s *sc; @@ -1807,6 +1811,9 @@ sc = mdfind(mdr->md_unit); if (sc == NULL) return (ENOENT); + if (priv_check(td, PRIV_VFS_ADMIN) != 0) + if (!sc->cred || cr_cansee(td->td_ucred, sc->cred)) + return (EPERM); if (mdr->md_mediasize < sc->sectorsize) return (EINVAL); mdr->md_mediasize -= mdr->md_mediasize % sc->sectorsize; @@ -1818,12 +1825,12 @@ } static int -kern_mdresize(struct md_req *mdr) +kern_mdresize(struct thread *td, struct md_req *mdr) { int error; sx_xlock(&md_sx); - error = kern_mdresize_locked(mdr); + error = kern_mdresize_locked(td, mdr); sx_xunlock(&md_sx); return (error); } @@ -1959,7 +1966,7 @@ #ifdef COMPAT_FREEBSD32 case MDIOCRESIZE_32: #endif - error = kern_mdresize(&mdr); + error = kern_mdresize(td, &mdr); break; case MDIOCQUERY: #ifdef COMPAT_FREEBSD32