summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2018-06-07 13:37:29 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2018-06-07 13:37:29 +0000
commit380a152a55a793d5891fd063c5856fe955061263 (patch)
tree2a642715663fa28e52eb1702f889ef1cf10d584f
parentfad718c914c60261c1c08c7123d69239f348d8ae (diff)
Make callers of VOP_CREATE(9) and VOP_MKNOD(9) responsible for
unlocking the directory vnode. OK mpi@, helg@
-rw-r--r--share/man/man9/VOP_LOOKUP.99
-rw-r--r--sys/kern/uipc_usrreq.c3
-rw-r--r--sys/kern/vfs_syscalls.c3
-rw-r--r--sys/kern/vfs_vnops.c3
-rw-r--r--sys/miscfs/fuse/fuse_vnops.c44
-rw-r--r--sys/msdosfs/msdosfs_vnops.c5
-rw-r--r--sys/nfs/nfs_serv.c9
-rw-r--r--sys/nfs/nfs_vnops.c11
-rw-r--r--sys/tmpfs/tmpfs_vnops.c20
-rw-r--r--sys/ufs/ext2fs/ext2fs_vnops.c11
-rw-r--r--sys/ufs/ufs/ufs_vnops.c8
11 files changed, 45 insertions, 81 deletions
diff --git a/share/man/man9/VOP_LOOKUP.9 b/share/man/man9/VOP_LOOKUP.9
index 49357b336a3..ce8286978c8 100644
--- a/share/man/man9/VOP_LOOKUP.9
+++ b/share/man/man9/VOP_LOOKUP.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: VOP_LOOKUP.9,v 1.42 2018/06/04 19:42:54 kn Exp $
+.\" $OpenBSD: VOP_LOOKUP.9,v 1.43 2018/06/07 13:37:27 visa Exp $
.\"
.\" Copyright (c) 2003 Ted Unangst
.\" Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -24,7 +24,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: June 4 2018 $
+.Dd $Mdocdate: June 7 2018 $
.Dt VOP_LOOKUP 9
.Os
.Sh NAME
@@ -472,6 +472,8 @@ The file name is in
.Fa cnp
and its permissions will be
.Fa vap .
+.Fa dvp
+must be locked.
.Pp
.It Fn VOP_FSYNC vp cred waitfor p
Flush any dirty buffers associated with
@@ -675,9 +677,6 @@ and attributes
.Fa vap
in the directory associated with the locked vnode
.Fa dvp .
-.Fa dvp
-will be unlocked on return (see
-.Xr vput 9 ) .
A pointer to the new, locked vnode will be returned in
.Fa *vpp
if
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 94395f8bc0a..44eff61a8a0 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_usrreq.c,v 1.127 2018/06/06 06:55:22 mpi Exp $ */
+/* $OpenBSD: uipc_usrreq.c,v 1.128 2018/06/07 13:37:27 visa Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */
/*
@@ -456,6 +456,7 @@ unp_bind(struct unpcb *unp, struct mbuf *nam, struct proc *p)
vattr.va_type = VSOCK;
vattr.va_mode = ACCESSPERMS &~ p->p_fd->fd_cmask;
error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
+ vput(nd.ni_dvp);
if (error) {
m_freem(nam2);
return (error);
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 6d3878a1d0f..477da52ee9b 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.286 2018/06/05 09:29:05 mpi Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.287 2018/06/07 13:37:27 visa Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -1337,6 +1337,7 @@ domknodat(struct proc *p, int fd, const char *path, mode_t mode, dev_t dev)
out:
if (!error) {
error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr);
+ vput(nd.ni_dvp);
} else {
VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
if (nd.ni_dvp == vp)
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 948306ce7aa..03fe499734c 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_vnops.c,v 1.92 2018/05/02 02:24:56 visa Exp $ */
+/* $OpenBSD: vfs_vnops.c,v 1.93 2018/06/07 13:37:27 visa Exp $ */
/* $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $ */
/*
@@ -109,6 +109,7 @@ vn_open(struct nameidata *ndp, int fmode, int cmode)
va.va_vaflags |= VA_EXCLUSIVE;
error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp,
&ndp->ni_cnd, &va);
+ vput(ndp->ni_dvp);
if (error)
return (error);
fmode &= ~O_TRUNC;
diff --git a/sys/miscfs/fuse/fuse_vnops.c b/sys/miscfs/fuse/fuse_vnops.c
index 7b4cd3d772f..613d444fb37 100644
--- a/sys/miscfs/fuse/fuse_vnops.c
+++ b/sys/miscfs/fuse/fuse_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fuse_vnops.c,v 1.43 2018/05/21 13:06:00 helg Exp $ */
+/* $OpenBSD: fuse_vnops.c,v 1.44 2018/06/07 13:37:28 visa Exp $ */
/*
* Copyright (c) 2012-2013 Sylvestre Gallon <ccna.syl@gmail.com>
*
@@ -932,15 +932,11 @@ fusefs_create(void *v)
fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
mode = MAKEIMODE(vap->va_type, vap->va_mode);
- if (!fmp->sess_init) {
- error = ENXIO;
- goto out;
- }
+ if (!fmp->sess_init)
+ return (ENXIO);
- if (fmp->undef_op & UNDEF_MKNOD) {
- error = ENOSYS;
- goto out;
- }
+ if (fmp->undef_op & UNDEF_MKNOD)
+ return (ENOSYS);
fbuf = fb_setup(cnp->cn_namelen + 1, ip->ufs_ino.i_number,
FBT_MKNOD, p);
@@ -955,22 +951,18 @@ fusefs_create(void *v)
if (error == ENOSYS)
fmp->undef_op |= UNDEF_MKNOD;
- fb_delete(fbuf);
goto out;
}
- if ((error = VFS_VGET(fmp->mp, fbuf->fb_ino, &tdp))) {
- fb_delete(fbuf);
+ if ((error = VFS_VGET(fmp->mp, fbuf->fb_ino, &tdp)))
goto out;
- }
tdp->v_type = IFTOVT(fbuf->fb_io_mode);
*vpp = tdp;
VN_KNOTE(ap->a_dvp, NOTE_WRITE);
- fb_delete(fbuf);
out:
- vput(ap->a_dvp);
+ fb_delete(fbuf);
return (error);
}
@@ -992,15 +984,11 @@ fusefs_mknod(void *v)
ip = VTOI(dvp);
fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
- if (!fmp->sess_init) {
- error = ENXIO;
- goto out;
- }
+ if (!fmp->sess_init)
+ return (ENXIO);
- if (fmp->undef_op & UNDEF_MKNOD) {
- error = ENOSYS;
- goto out;
- }
+ if (fmp->undef_op & UNDEF_MKNOD)
+ return (ENOSYS);
fbuf = fb_setup(cnp->cn_namelen + 1, ip->ufs_ino.i_number,
FBT_MKNOD, p);
@@ -1017,21 +1005,16 @@ fusefs_mknod(void *v)
if (error == ENOSYS)
fmp->undef_op |= UNDEF_MKNOD;
- fb_delete(fbuf);
goto out;
}
- if ((error = VFS_VGET(fmp->mp, fbuf->fb_ino, &tdp))) {
- fb_delete(fbuf);
+ if ((error = VFS_VGET(fmp->mp, fbuf->fb_ino, &tdp)))
goto out;
- }
tdp->v_type = IFTOVT(fbuf->fb_io_mode);
*vpp = tdp;
VN_KNOTE(ap->a_dvp, NOTE_WRITE);
- fb_delete(fbuf);
- vput(ap->a_dvp);
/* Remove inode so that it will be reloaded by VFS_VGET and
* checked to see if it is an alias of an existing entry in
@@ -1041,9 +1024,8 @@ fusefs_mknod(void *v)
(*vpp)->v_type = VNON;
vgone(*vpp);
*vpp = NULL;
- return (0);
out:
- vput(ap->a_dvp);
+ fb_delete(fbuf);
return (error);
}
diff --git a/sys/msdosfs/msdosfs_vnops.c b/sys/msdosfs/msdosfs_vnops.c
index a1e9e50365e..fd86ca4e84e 100644
--- a/sys/msdosfs/msdosfs_vnops.c
+++ b/sys/msdosfs/msdosfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: msdosfs_vnops.c,v 1.120 2018/05/07 14:43:01 mpi Exp $ */
+/* $OpenBSD: msdosfs_vnops.c,v 1.121 2018/06/07 13:37:28 visa Exp $ */
/* $NetBSD: msdosfs_vnops.c,v 1.63 1997/10/17 11:24:19 ws Exp $ */
/*-
@@ -164,13 +164,11 @@ msdosfs_create(void *v)
if ((cnp->cn_flags & SAVESTART) == 0)
pool_put(&namei_pool, cnp->cn_pnbuf);
VN_KNOTE(ap->a_dvp, NOTE_WRITE);
- vput(ap->a_dvp);
*ap->a_vpp = DETOV(dep);
return (0);
bad:
pool_put(&namei_pool, cnp->cn_pnbuf);
- vput(ap->a_dvp);
return (error);
}
@@ -181,7 +179,6 @@ msdosfs_mknod(void *v)
pool_put(&namei_pool, ap->a_cnp->cn_pnbuf);
VN_KNOTE(ap->a_dvp, NOTE_WRITE);
- vput(ap->a_dvp);
return (EINVAL);
}
diff --git a/sys/nfs/nfs_serv.c b/sys/nfs/nfs_serv.c
index 4bcff919c76..3fd59472076 100644
--- a/sys/nfs/nfs_serv.c
+++ b/sys/nfs/nfs_serv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nfs_serv.c,v 1.114 2018/05/02 02:24:56 visa Exp $ */
+/* $OpenBSD: nfs_serv.c,v 1.115 2018/06/07 13:37:28 visa Exp $ */
/* $NetBSD: nfs_serv.c,v 1.34 1997/05/12 23:37:12 fvdl Exp $ */
/*
@@ -961,7 +961,9 @@ nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
if (nd.ni_vp == NULL) {
if (va.va_type == VREG || va.va_type == VSOCK) {
vrele(nd.ni_startdir);
- error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &va);
+ error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd,
+ &va);
+ vput(nd.ni_dvp);
if (!error) {
pool_put(&namei_pool, nd.ni_cnd.cn_pnbuf);
if (exclusive_flag) {
@@ -993,6 +995,7 @@ nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
va.va_rdev = (dev_t)rdev;
error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd,
&va);
+ vput(nd.ni_dvp);
if (error) {
vrele(nd.ni_startdir);
if (nd.ni_cnd.cn_flags & HASBUF) {
@@ -1202,6 +1205,7 @@ nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
if (vtyp == VSOCK) {
vrele(nd.ni_startdir);
error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &va);
+ vput(nd.ni_dvp);
if (!error)
pool_put(&namei_pool, nd.ni_cnd.cn_pnbuf);
} else {
@@ -1214,6 +1218,7 @@ nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
goto out;
}
error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &va);
+ vput(nd.ni_dvp);
if (error) {
vrele(nd.ni_startdir);
goto out;
diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c
index 52cac997131..956a6f4a5d9 100644
--- a/sys/nfs/nfs_vnops.c
+++ b/sys/nfs/nfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nfs_vnops.c,v 1.176 2018/05/05 11:54:11 mpi Exp $ */
+/* $OpenBSD: nfs_vnops.c,v 1.177 2018/06/07 13:37:28 visa Exp $ */
/* $NetBSD: nfs_vnops.c,v 1.62.4.1 1996/07/08 20:26:52 jtc Exp $ */
/*
@@ -1401,7 +1401,6 @@ nfs_mknod(void *v)
vput(newvp);
VN_KNOTE(ap->a_dvp, NOTE_WRITE);
- vput(ap->a_dvp);
return (error);
}
@@ -1427,11 +1426,8 @@ nfs_create(void *v)
/*
* Oops, not for me..
*/
- if (vap->va_type == VSOCK) {
- error = nfs_mknodrpc(dvp, ap->a_vpp, cnp, vap);
- vput(dvp);
- return (error);
- }
+ if (vap->va_type == VSOCK)
+ return (nfs_mknodrpc(dvp, ap->a_vpp, cnp, vap));
if (vap->va_vaflags & VA_EXCLUSIVE)
fmode |= O_EXCL;
@@ -1502,7 +1498,6 @@ nfsmout:
if (!wccflag)
NFS_INVALIDATE_ATTRCACHE(VTONFS(dvp));
VN_KNOTE(ap->a_dvp, NOTE_WRITE);
- vput(dvp);
return (error);
}
diff --git a/sys/tmpfs/tmpfs_vnops.c b/sys/tmpfs/tmpfs_vnops.c
index 5c06b4b788b..6615a1951bd 100644
--- a/sys/tmpfs/tmpfs_vnops.c
+++ b/sys/tmpfs/tmpfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmpfs_vnops.c,v 1.31 2018/05/28 16:02:08 visa Exp $ */
+/* $OpenBSD: tmpfs_vnops.c,v 1.32 2018/06/07 13:37:28 visa Exp $ */
/* $NetBSD: tmpfs_vnops.c,v 1.100 2012/11/05 17:27:39 dholland Exp $ */
/*
@@ -317,14 +317,11 @@ tmpfs_create(void *v)
struct vnode *dvp = ap->a_dvp, **vpp = ap->a_vpp;
struct componentname *cnp = ap->a_cnp;
struct vattr *vap = ap->a_vap;
- int error;
KASSERT(VOP_ISLOCKED(dvp));
KASSERT(cnp->cn_flags & HASBUF);
KASSERT(vap->va_type == VREG || vap->va_type == VSOCK);
- error = tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL);
- vput(dvp);
- return error;
+ return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL);
}
int
@@ -342,20 +339,15 @@ tmpfs_mknod(void *v)
enum vtype vt = vap->va_type;
int error;
- if (vt != VBLK && vt != VCHR && vt != VFIFO) {
- vput(dvp);
+ if (vt != VBLK && vt != VCHR && vt != VFIFO)
return EINVAL;
- }
- /* tmpfs_alloc_file() will unlock 'dvp'. */
error = tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL);
- vput(dvp);
- if (error)
- return error;
- vput(*vpp);
+ if (error == 0)
+ vput(*vpp);
- return 0;
+ return error;
}
int
diff --git a/sys/ufs/ext2fs/ext2fs_vnops.c b/sys/ufs/ext2fs/ext2fs_vnops.c
index 876030e9404..bb68bce04df 100644
--- a/sys/ufs/ext2fs/ext2fs_vnops.c
+++ b/sys/ufs/ext2fs/ext2fs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ext2fs_vnops.c,v 1.82 2018/05/28 16:02:08 visa Exp $ */
+/* $OpenBSD: ext2fs_vnops.c,v 1.83 2018/06/07 13:37:28 visa Exp $ */
/* $NetBSD: ext2fs_vnops.c,v 1.1 1997/06/11 09:34:09 bouyer Exp $ */
/*
@@ -80,13 +80,9 @@ int
ext2fs_create(void *v)
{
struct vop_create_args *ap = v;
- int error;
- error = ext2fs_makeinode(MAKEIMODE(ap->a_vap->va_type,
- ap->a_vap->va_mode),
- ap->a_dvp, ap->a_vpp, ap->a_cnp);
- vput(ap->a_dvp);
- return (error);
+ return (ext2fs_makeinode(MAKEIMODE(ap->a_vap->va_type,
+ ap->a_vap->va_mode), ap->a_dvp, ap->a_vpp, ap->a_cnp));
}
/*
@@ -104,7 +100,6 @@ ext2fs_mknod(void *v)
error = ext2fs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
ap->a_dvp, vpp, ap->a_cnp);
- vput(ap->a_dvp);
if (error != 0)
return (error);
ip = VTOI(*vpp);
diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c
index afbd3293e99..af02be00587 100644
--- a/sys/ufs/ufs/ufs_vnops.c
+++ b/sys/ufs/ufs/ufs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ufs_vnops.c,v 1.139 2018/05/24 14:08:42 visa Exp $ */
+/* $OpenBSD: ufs_vnops.c,v 1.140 2018/06/07 13:37:28 visa Exp $ */
/* $NetBSD: ufs_vnops.c,v 1.18 1996/05/11 18:28:04 mycroft Exp $ */
/*
@@ -153,7 +153,6 @@ ufs_create(void *v)
ap->a_dvp, ap->a_vpp, ap->a_cnp);
if (error == 0)
VN_KNOTE(ap->a_dvp, NOTE_WRITE);
- vput(ap->a_dvp);
return (error);
}
@@ -171,12 +170,9 @@ ufs_mknod(void *v)
if ((error =
ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
- ap->a_dvp, vpp, ap->a_cnp)) != 0) {
- vput(ap->a_dvp);
+ ap->a_dvp, vpp, ap->a_cnp)) != 0)
return (error);
- }
VN_KNOTE(ap->a_dvp, NOTE_WRITE);
- vput(ap->a_dvp);
ip = VTOI(*vpp);
ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
if (vap->va_rdev != VNOVAL) {