diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-03-21 08:58:51 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-03-21 08:58:51 +0000 |
commit | 3e53e09e90e687016d50909112b2ad78c69b85d2 (patch) | |
tree | 18a10366e57dd4e27371ec289d0f59137f3e1e13 /sys/kern | |
parent | 4d6fae66eaa836bc7eb15975c2b5d8140d6052c7 (diff) |
Stop tracing if vget(9) fails.
Make sure to release the last reference of the vnode after all
other traced processes have given up on it.
CID 1453020 Unchecked return value.
Inputs from guenther@, ok visa@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_ktrace.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 39bd1183d5b..e9234e49abf 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_ktrace.c,v 1.100 2019/10/06 16:24:14 beck Exp $ */ +/* $OpenBSD: kern_ktrace.c,v 1.101 2020/03/21 08:58:50 mpi Exp $ */ /* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */ /* @@ -649,22 +649,29 @@ ktrwriteraw(struct proc *curp, struct vnode *vp, struct ucred *cred, auio.uio_iovcnt++; auio.uio_resid += kth->ktr_len; } - vget(vp, LK_EXCLUSIVE | LK_RETRY); + error = vget(vp, LK_EXCLUSIVE | LK_RETRY); + if (error) + goto bad; error = VOP_WRITE(vp, &auio, IO_UNIT|IO_APPEND, cred); - if (!error) { - vput(vp); - return (0); - } + vput(vp); + if (error) + goto bad; + + return (0); + +bad: /* * If error encountered, give up tracing on this vnode. */ log(LOG_NOTICE, "ktrace write failed, errno %d, tracing stopped\n", error); - LIST_FOREACH(pr, &allprocess, ps_list) + LIST_FOREACH(pr, &allprocess, ps_list) { + if (pr == curp->p_p) + continue; if (pr->ps_tracevp == vp && pr->ps_tracecred == cred) ktrcleartrace(pr); - - vput(vp); + } + ktrcleartrace(curp->p_p); return (error); } |