]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/vn/vn.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / dev / vn / vn.c
index 265270a3ac404ec40265927a461bbe69d75b04e5..c0642c1d08a2a0821028bc3ecd52defcf00737e4 100644 (file)
@@ -1114,7 +1114,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) {
@@ -1128,8 +1128,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, 
@@ -1141,8 +1143,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;
@@ -1151,17 +1155,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;
@@ -1181,6 +1187,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);
 }
 
@@ -1195,7 +1202,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) {
@@ -1210,20 +1217,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;
@@ -1234,6 +1244,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);
 }
 
@@ -1299,8 +1310,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;