X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/8f6c56a50524aa785f7e596d52dddfb331e18961..89b3af67bb32e691275bf6fa803d1834b2284115:/bsd/dev/vn/vn.c diff --git a/bsd/dev/vn/vn.c b/bsd/dev/vn/vn.c index 74f8b3404..f9a2212b9 100644 --- a/bsd/dev/vn/vn.c +++ b/bsd/dev/vn/vn.c @@ -1120,7 +1120,7 @@ vniocattach_file(struct vn_softc *vn, int error, flags; context.vc_proc = p; - context.vc_ucred = proc_ucred(p); + context.vc_ucred = kauth_cred_proc_ref(p); flags = FREAD|FWRITE; if (in_kernel) { @@ -1134,8 +1134,10 @@ vniocattach_file(struct vn_softc *vn, /* vn_open gives both long- and short-term references */ error = vn_open(&nd, flags, 0); if (error) { - if (error != EACCES && error != EPERM && error != EROFS) + if (error != EACCES && error != EPERM && error != EROFS) { + kauth_cred_unref(&context.vc_ucred); return (error); + } flags &= ~FWRITE; if (in_kernel) { NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE32, @@ -1147,8 +1149,10 @@ vniocattach_file(struct vn_softc *vn, vniop->vn_file, &context); } error = vn_open(&nd, flags, 0); - if (error) + if (error) { + kauth_cred_unref(&context.vc_ucred); return (error); + } } if (nd.ni_vp->v_type != VREG) { error = EINVAL; @@ -1157,17 +1161,19 @@ vniocattach_file(struct vn_softc *vn, error = vnode_size(nd.ni_vp, &file_size, &context); } if (error != 0) { - (void) vn_close(nd.ni_vp, flags, proc_ucred(p), p); + (void) vn_close(nd.ni_vp, flags, context.vc_ucred, p); vnode_put(nd.ni_vp); + kauth_cred_unref(&context.vc_ucred); return (error); } cred = kauth_cred_proc_ref(p); nd.ni_vp->v_flag |= VNOCACHE_DATA; error = setcred(nd.ni_vp, p, cred); if (error) { - (void)vn_close(nd.ni_vp, flags, proc_ucred(p), p); + (void)vn_close(nd.ni_vp, flags, context.vc_ucred, p); vnode_put(nd.ni_vp); - kauth_cred_rele(cred); + kauth_cred_unref(&cred); + kauth_cred_unref(&context.vc_ucred); return(error); } vn->sc_secsize = DEV_BSIZE; @@ -1187,6 +1193,7 @@ vniocattach_file(struct vn_softc *vn, vn->sc_flags |= VNF_READONLY; /* lose the short-term reference */ vnode_put(nd.ni_vp); + kauth_cred_unref(&context.vc_ucred); return(0); } @@ -1201,7 +1208,7 @@ vniocattach_shadow(struct vn_softc *vn, struct user_vn_ioctl *vniop, off_t file_size; context.vc_proc = p; - context.vc_ucred = proc_ucred(p); + context.vc_ucred = kauth_cred_proc_ref(p); flags = FREAD|FWRITE; if (in_kernel) { @@ -1216,20 +1223,23 @@ vniocattach_shadow(struct vn_softc *vn, struct user_vn_ioctl *vniop, error = vn_open(&nd, flags, 0); if (error) { /* shadow MUST be writable! */ + kauth_cred_unref(&context.vc_ucred); return (error); } if (nd.ni_vp->v_type != VREG || (error = vnode_size(nd.ni_vp, &file_size, &context))) { - (void)vn_close(nd.ni_vp, flags, proc_ucred(p), p); + (void)vn_close(nd.ni_vp, flags, context.vc_ucred, p); vnode_put(nd.ni_vp); + kauth_cred_unref(&context.vc_ucred); return (error ? error : EINVAL); } map = shadow_map_create(vn->sc_fsize, file_size, 0, vn->sc_secsize); if (map == NULL) { - (void)vn_close(nd.ni_vp, flags, proc_ucred(p), p); + (void)vn_close(nd.ni_vp, flags, context.vc_ucred, p); vnode_put(nd.ni_vp); vn->sc_shadow_vp = NULL; + kauth_cred_unref(&context.vc_ucred); return (ENOMEM); } vn->sc_shadow_vp = nd.ni_vp; @@ -1240,6 +1250,7 @@ vniocattach_shadow(struct vn_softc *vn, struct user_vn_ioctl *vniop, /* lose the short-term reference */ vnode_put(nd.ni_vp); + kauth_cred_unref(&context.vc_ucred); return(0); } @@ -1305,8 +1316,7 @@ vnclear(struct vn_softc *vn, struct proc * p) } vn->sc_flags &= ~(VNF_INITED | VNF_READONLY); if (vn->sc_cred) { - kauth_cred_rele(vn->sc_cred); - vn->sc_cred = NULL; + kauth_cred_unref(&vn->sc_cred); } vn->sc_size = 0; vn->sc_fsize = 0;