]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_symfile.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / bsd / kern / kern_symfile.c
index 983cf38c431364534b545bcd10ac68b8c7b84493..7d25e43aa1166f812d50f2969fe836393d73a98d 100644 (file)
@@ -95,7 +95,7 @@ static int
 output_kernel_symbols(struct proc *p)
 {
     struct vnode               *vp;
-    kauth_cred_t               cred = p->p_ucred;      /* XXX */
+    kauth_cred_t               cred = p->p_ucred;      /* XXX unsafe */
     struct vnode_attr          va;
     struct vfs_context         context;
     struct load_command                *cmd;
@@ -120,6 +120,9 @@ output_kernel_symbols(struct proc *p)
     orig_mh    = NULL;
     orig_st    = NULL;
     
+    context.vc_proc = p;
+    context.vc_ucred = kauth_cred_proc_ref(p);
+
     // Dispose of unnecessary gumf, the booter doesn't need to load these
     rc_mh = IODTGetLoaderInfo("Kernel-__HEADER",
                                (void **)&orig_mh, &orig_mhsize);
@@ -140,9 +143,6 @@ output_kernel_symbols(struct proc *p)
     if (rootdevice[0] == 'e' && rootdevice[1] == 'n')
        goto out;
 
-    context.vc_proc = p;
-    context.vc_ucred = cred;
-
     if ((error = vnode_open("mach.sym", (O_CREAT | FWRITE), (S_IRUSR | S_IRGRP | S_IROTH), 0, &vp, &context)))
         goto out;
 
@@ -331,6 +331,7 @@ out:
        if (!error) error = error1;
     }
 
+    kauth_cred_unref(&context.vc_ucred);
     return(error);
 }
 /*
@@ -379,7 +380,6 @@ kern_open_file_for_direct_io(const char * name,
     struct kern_direct_file_io_ref_t * ref;
 
     struct proc                *p;
-    struct ucred               *cred;
     struct vnode_attr          va;
     int                                error;
     off_t                      f_offset;
@@ -403,9 +403,8 @@ kern_open_file_for_direct_io(const char * name,
 
     ref->vp = NULL;
     p = current_proc();                // kernproc;
-    cred = p->p_ucred;
     ref->context.vc_proc = p;
-    ref->context.vc_ucred = cred;
+    ref->context.vc_ucred = kauth_cred_proc_ref(p);
 
     if ((error = vnode_open(name, (O_CREAT | FWRITE), (0), 0, &ref->vp, &ref->context)))
         goto out;
@@ -542,13 +541,14 @@ out:
     kprintf("kern_open_file_for_direct_io(%d)\n", error);
 
     if (error && ref) {
-       if (ref->vp) {
-           vnode_close(ref->vp, FWRITE, &ref->context);
-               ref->vp = NULLVP;
-       }
-
-       kfree(ref, sizeof(struct kern_direct_file_io_ref_t));
-       ref = NULL;
+               if (ref->vp) {
+                       vnode_close(ref->vp, FWRITE, &ref->context);
+                       ref->vp = NULLVP;
+               }
+
+               kauth_cred_unref(&ref->context.vc_ucred);
+               kfree(ref, sizeof(struct kern_direct_file_io_ref_t));
+               ref = NULL;
     }
 
     return(ref);
@@ -576,6 +576,7 @@ kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref)
            kprintf("vnode_close(%d)\n", error);
                ref->vp = NULLVP;
        }
+       kauth_cred_unref(&ref->context.vc_ucred);
        kfree(ref, sizeof(struct kern_direct_file_io_ref_t));
     }
 }