*_mountfs() (if the filesystem mounts from a device) needs devvp to be

locked, so lock it.

Glanced at by:	phk
MFC after:	3 days
This commit is contained in:
ssouhlal 2005-09-02 15:27:23 +00:00
parent 912d183e0b
commit f8217f350b
6 changed files with 26 additions and 39 deletions

View File

@ -161,7 +161,7 @@ hpfs_mount (
* Not an update, or updating the name: look up the name
* and verify that it refers to a sensible block device.
*/
NDINIT(&ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, from, td);
NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, from, td);
err = namei(&ndp);
if (err) {
/* can't get devvp!*/
@ -170,8 +170,10 @@ hpfs_mount (
devvp = ndp.ni_vp;
if (!vn_isdisk(devvp, &err))
goto error_2;
if (!vn_isdisk(devvp, &err)) {
vput(devvp);
return (err);
}
/*
********************
@ -197,12 +199,6 @@ hpfs_mount (
goto success;
error_2: /* error with devvp held*/
/* release devvp before failing*/
vrele(devvp);
error_1: /* no state to back out*/
/* XXX: Missing NDFREE(&ndp, ...) */

View File

@ -336,7 +336,7 @@ msdosfs_mount(struct mount *mp, struct thread *td)
*/
if (vfs_getopt(mp->mnt_optnew, "from", (void **)&from, NULL))
return (EINVAL);
NDINIT(&ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, from, td);
NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, from, td);
error = namei(&ndp);
if (error)
return (error);
@ -344,7 +344,7 @@ msdosfs_mount(struct mount *mp, struct thread *td)
NDFREE(&ndp, NDF_ONLY_PNBUF);
if (!vn_isdisk(devvp, &error)) {
vrele(devvp);
vput(devvp);
return (error);
}
/*
@ -355,13 +355,11 @@ msdosfs_mount(struct mount *mp, struct thread *td)
accessmode = VREAD;
if ((mp->mnt_flag & MNT_RDONLY) == 0)
accessmode |= VWRITE;
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
error = VOP_ACCESS(devvp, accessmode, td->td_ucred, td);
if (error) {
vput(devvp);
return (error);
}
VOP_UNLOCK(devvp, 0, td);
}
if ((mp->mnt_flag & MNT_UPDATE) == 0) {
error = mountmsdosfs(devvp, mp, td);
@ -372,7 +370,7 @@ msdosfs_mount(struct mount *mp, struct thread *td)
if (devvp != pmp->pm_devvp)
error = EINVAL; /* XXX needs translation */
else
vrele(devvp);
vput(devvp);
}
if (error) {
vrele(devvp);

View File

@ -191,7 +191,7 @@ ntfs_mount (
* Not an update, or updating the name: look up the name
* and verify that it refers to a sensible block device.
*/
NDINIT(&ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, from, td);
NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, from, td);
err = namei(&ndp);
if (err) {
/* can't get devvp!*/
@ -200,8 +200,11 @@ ntfs_mount (
NDFREE(&ndp, NDF_ONLY_PNBUF);
devvp = ndp.ni_vp;
if (!vn_isdisk(devvp, &err))
goto error_2;
if (!vn_isdisk(devvp, &err)) {
vput(devvp);
return (err);
}
if (mp->mnt_flag & MNT_UPDATE) {
#if 0
/*
@ -212,8 +215,9 @@ ntfs_mount (
if (devvp != ntmp->um_devvp)
err = EINVAL; /* needs translation */
else
vrele(devvp);
vput(devvp);
if (err)
return (err);
#endif
} else {
/*
@ -237,17 +241,12 @@ ntfs_mount (
err = ntfs_mountfs(devvp, mp, td);
}
if (err) {
goto error_2;
vrele(devvp);
return (err);
}
goto success;
error_2: /* error with devvp held*/
/* release devvp before failing*/
vrele(devvp);
error_1: /* no state to back out*/
/* XXX: missing NDFREE(&ndp, ...) */

View File

@ -228,19 +228,18 @@ udf_mount(struct mount *mp, struct thread *td)
/* Check that the mount device exists */
if (fspec == NULL)
return (EINVAL);
NDINIT(ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, fspec, td);
NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspec, td);
if ((error = namei(ndp)))
return (error);
NDFREE(ndp, NDF_ONLY_PNBUF);
devvp = ndp->ni_vp;
if (vn_isdisk(devvp, &error) == 0) {
vrele(devvp);
vput(devvp);
return (error);
}
/* Check the access rights on the mount device */
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
error = VOP_ACCESS(devvp, VREAD, td->td_ucred, td);
if (error)
error = suser(td);
@ -248,7 +247,6 @@ udf_mount(struct mount *mp, struct thread *td)
vput(devvp);
return (error);
}
VOP_UNLOCK(devvp, 0, td);
if ((error = udf_mountfs(devvp, mp, td))) {
vrele(devvp);

View File

@ -248,14 +248,14 @@ ext2_mount(mp, td)
*/
if (fspec == NULL)
return (EINVAL);
NDINIT(ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, fspec, td);
NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspec, td);
if ((error = namei(ndp)) != 0)
return (error);
NDFREE(ndp, NDF_ONLY_PNBUF);
devvp = ndp->ni_vp;
if (!vn_isdisk(devvp, &error)) {
vrele(devvp);
vput(devvp);
return (error);
}
@ -267,12 +267,10 @@ ext2_mount(mp, td)
accessmode = VREAD;
if ((mp->mnt_flag & MNT_RDONLY) == 0)
accessmode |= VWRITE;
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
if ((error = VOP_ACCESS(devvp, accessmode, td->td_ucred, td)) != 0) {
vput(devvp);
return (error);
}
VOP_UNLOCK(devvp, 0, td);
}
if ((mp->mnt_flag & MNT_UPDATE) == 0) {
@ -281,7 +279,7 @@ ext2_mount(mp, td)
if (devvp != ump->um_devvp)
error = EINVAL; /* needs translation */
else
vrele(devvp);
vput(devvp);
}
if (error) {
vrele(devvp);

View File

@ -114,14 +114,14 @@ reiserfs_mount(struct mount *mp, struct thread *td)
if (fspec == NULL)
return (EINVAL);
NDINIT(ndp, LOOKUP, FOLLOW, UIO_SYSSPACE, fspec, td);
NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspec, td);
if ((error = namei(ndp)) != 0)
return (error);
NDFREE(ndp, NDF_ONLY_PNBUF);
devvp = ndp->ni_vp;
if (!vn_isdisk(devvp, &error)) {
vrele(devvp);
vput(devvp);
return (error);
}
@ -131,13 +131,11 @@ reiserfs_mount(struct mount *mp, struct thread *td)
accessmode = VREAD;
if ((mp->mnt_flag & MNT_RDONLY) == 0)
accessmode |= VWRITE;
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, td);
if ((error = VOP_ACCESS(devvp,
accessmode, td->td_ucred, td)) != 0) {
vput(devvp);
return (error);
}
VOP_UNLOCK(devvp, 0, td);
}
if ((mp->mnt_flag & MNT_UPDATE) == 0) {