aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2001-01-23 22:23:25 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2001-01-23 22:23:25 +0000
commit0e9f2d667cdf4356e21d688503071c6f626e90d7 (patch)
tree4b26e9d8695aeed52686c0f63fb8aea5ef0bfe66
parent4957d1b4cb07c4a4c9f1ffdb0474bcd4cebeef1f (diff)
Proc locking to protect p_ucred while we obtain another reference to it.
Notes
Notes: svn path=/head/; revision=71478
-rw-r--r--sys/dev/vn/vn.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/sys/dev/vn/vn.c b/sys/dev/vn/vn.c
index 570b9266301b..d11b6ed29f25 100644
--- a/sys/dev/vn/vn.c
+++ b/sys/dev/vn/vn.c
@@ -562,6 +562,7 @@ vniocattach_file(vn, vio, dev, flag, p)
struct proc *p;
{
struct vattr vattr;
+ struct ucred *uc;
struct nameidata nd;
int error, flags;
@@ -578,10 +579,15 @@ vniocattach_file(vn, vio, dev, flag, p)
return (error);
}
NDFREE(&nd, NDF_ONLY_PNBUF);
+ PROC_LOCK(p);
+ uc = p->p_ucred;
+ crhold(uc);
+ PROC_UNLOCK(p);
if (nd.ni_vp->v_type != VREG ||
- (error = VOP_GETATTR(nd.ni_vp, &vattr, p->p_ucred, p))) {
+ (error = VOP_GETATTR(nd.ni_vp, &vattr, uc, p))) {
VOP_UNLOCK(nd.ni_vp, 0, p);
- (void) vn_close(nd.ni_vp, flags, p->p_ucred, p);
+ (void) vn_close(nd.ni_vp, flags, uc, p);
+ crfree(uc);
return (error ? error : EINVAL);
}
VOP_UNLOCK(nd.ni_vp, 0, p);
@@ -596,11 +602,13 @@ vniocattach_file(vn, vio, dev, flag, p)
vn->sc_size = (quad_t)vio->vn_size * PAGE_SIZE / vn->sc_secsize;
else
vn->sc_size = vattr.va_size / vn->sc_secsize;
- error = vnsetcred(vn, p->p_ucred);
+ error = vnsetcred(vn, uc);
if (error) {
- (void) vn_close(nd.ni_vp, flags, p->p_ucred, p);
+ (void) vn_close(nd.ni_vp, flags, uc, p);
+ crfree(uc);
return(error);
}
+ crfree(uc);
vn->sc_flags |= VNF_INITED;
if (flags == FREAD)
vn->sc_flags |= VNF_READONLY;
@@ -627,6 +635,7 @@ vniocattach_swap(vn, vio, dev, flag, p)
struct proc *p;
{
int error;
+ struct ucred *uc;
/*
* Range check. Disallow negative sizes or any size less then the
@@ -658,7 +667,12 @@ vniocattach_swap(vn, vio, dev, flag, p)
}
}
vn->sc_flags |= VNF_INITED;
- error = vnsetcred(vn, p->p_ucred);
+ PROC_LOCK(p);
+ uc = p->p_ucred;
+ crhold(uc);
+ PROC_UNLOCK(p);
+ error = vnsetcred(vn, uc);
+ crfree(uc);
if (error == 0) {
IFOPT(vn, VN_FOLLOW) {
printf("vnioctl: SET vp %p size %x\n",