Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 09 Apr 2002 15:25:55 -0400 (EDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        "Andrew R. Reiter" <arr@FreeBSD.org>
Cc:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   RE: PERFORCE change 9457 for review
Message-ID:  <XFMail.20020409152555.jhb@FreeBSD.org>
In-Reply-To: <200204091921.g39JL9R62159@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

On 09-Apr-2002 Andrew R. Reiter wrote:
> http://people.freebsd.org/~peter/p4db/chv.cgi?CH=9457
> 
> Change 9457 by arr@arr_shibby on 2002/04/09 12:20:46
> 
>       - Use curthread instead of a passed in thread pointer in
>         some places.
>       - Remember crfree() our saved cred.

You don't do a crhold on it though, which you probably should.

>       - Rearrange a check of the shutdown flag, so we can better
>         handle a bad situation -- this needs to possibly lock
>         the flag on write
> 
> Affected files ...
> 
> ... //depot/projects/trustedbsd/audit/sys/kern/kern_audit.c#20 edit
> 
> Differences ...
> 
> ==== //depot/projects/trustedbsd/audit/sys/kern/kern_audit.c#20 (text+ko)
> ====
> 
> @@ -87,9 +87,6 @@
>  audit_record_generate_id(audit_id_t *id)
>  {
>  
> -     /*
> -      * XXX
> -      */
>       return(*++id);
>  }
>  
> @@ -128,7 +125,6 @@
>  {
>       struct vnode *vp;
>       struct audit_info *ai;
> -     struct ucred *cred;
>       vm_zone_t zone;
>       char *sptr;
>       int err = 0;
> @@ -141,8 +137,7 @@
>       sptr = malloc(strlen(AUDLOG), M_TEMP, M_WAITOK|M_ZERO);
>       strcpy(sptr, AUDLOG);
>  
> -     /* XXX curthread */
> -     vp = audit_write_init(sptr, curthread, &cred);
> +     vp = audit_write_init(sptr, curthread, curthread->td_ucred);
>       if (vp == NULL)
>               panic("Unable to init audit system.\n");
>  
> @@ -151,7 +146,7 @@
>               panic("audit_init: unable to init audit record zone");
>  
>       AINFO_LOCK(ai);
> -     ai->ai_cred = cred;
> +     ai->ai_cred = curthread->td_ucred;

Here, do a crhold() so you preserve your own reference in case this audit info
lives longer than the syscall.

>       ai->ai_vp = vp;
>       ai->ai_zone = zone;
>       ai->ai_lname = sptr;
> @@ -169,15 +164,17 @@
>  SYSINIT(tbsd_audit, SI_ORDER_ANY, SI_SUB_MAC, &audit_init, NULL);
>  
>  void
> -audit_shutdown(int what, void *arg, struct thread *td)
> +audit_shutdown(void)
>  {
>       struct vnode *vp;
> -     struct audit_info *ai = arg;
> +     struct audit_info *ai;
>       struct ucred *cred;
>       vm_zone_t zone = NULL;
>       char *ptr;
>  
>       audit_shutdown_flag = 1;
> +     ai = &ainfo;
> +
>       AINFO_LOCK(ai);
>       cred = ai->ai_cred;
>       vp = ai->ai_vp;
> @@ -185,10 +182,10 @@
>       ptr = ai->ai_lname;
>       AINFO_UNLOCK(ai);
>       mtx_destroy(&ai->ai_mtx);
> +     free(ptr, M_TEMP);
>       bzero(ai, sizeof(*ai));
> -
> -     free(ptr, M_TEMP);
> -     audit_write_shutdown(vp, td, cred);
> +     audit_write_shutdown(vp, curthread, cred);      /* curthread ok? */
> +     crfree(cred);
>       zdestroy(zone);
>  }
>  SYSUNINIT(tbsd_audit, SI_ORDER_ANY, SI_SUB_MAC, &audit_shutdown, NULL);
> @@ -300,19 +297,20 @@
>               mtx_lock(&record_queue_mtx);
>               TAILQ_REMOVE(&record_queue, ar, ar_next);
>               mtx_unlock(&record_queue_mtx);
> +
> +             /* XXX Check flag here and hope it doesnt change. */
> +             if (audit_shutdown_flag) {
> +                     mtx_destroy(&record_queue_mtx);
> +                     kthread_exit(0);
> +             }
> +
>               if (ar) {
> -                     /* XXX */
>                       (void)audit_record_write(ar, NULL, NULL); 
>                       AINFO_LOCK(ai);
>                       z = ai->ai_zone;
>                       lease = &ai->ai_leased;
>                       AINFO_UNLOCK(ai);
>                       audit_record_free(ar, z, lease);
> -             } else if (ar == NULL && audit_shutdown_flag) {
> -                     mtx_destroy(&record_queue_mtx);
> -                     kthread_exit(0);
>               }
> -             if (audit_shutdown_flag)
> -                     continue;
>       }
>  }

-- 

John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20020409152555.jhb>