From owner-p4-projects@FreeBSD.ORG Sun Jan 11 22:08:11 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 78D4D16A4D1; Sun, 11 Jan 2004 22:08:11 -0800 (PST) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 43B9616A4CE for ; Sun, 11 Jan 2004 22:08:11 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4932643D53 for ; Sun, 11 Jan 2004 22:08:09 -0800 (PST) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.10/8.12.10) with ESMTP id i0C6880B043953 for ; Sun, 11 Jan 2004 22:08:08 -0800 (PST) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.10/8.12.10/Submit) id i0C6881b043949 for perforce@freebsd.org; Sun, 11 Jan 2004 22:08:08 -0800 (PST) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sun, 11 Jan 2004 22:08:08 -0800 (PST) Message-Id: <200401120608.i0C6881b043949@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Subject: PERFORCE change 45192 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jan 2004 06:08:11 -0000 http://perforce.freebsd.org/chv.cgi?CH=45192 Change 45192 by rwatson@rwatson_paprika on 2004/01/11 22:08:07 Create a MALLOC_DECLARE() for M_AUDIT in kern_audit.h so M_AUDIT can be used in additional .c files. Remove kmem/mutex stubs from bsm_audit.c, bsm_token.c and use FreeBSD mutex and malloc/free functions. Much logical simplification. Affected files ... .. //depot/projects/trustedbsd/audit2/sys/security/audit/bsm_audit.c#6 edit .. //depot/projects/trustedbsd/audit2/sys/security/audit/bsm_token.c#5 edit .. //depot/projects/trustedbsd/audit2/sys/security/audit/kern_audit.h#5 edit Differences ... ==== //depot/projects/trustedbsd/audit2/sys/security/audit/bsm_audit.c#6 (text+ko) ==== @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -43,14 +44,6 @@ #include #include -/* XXXDARWIN */ -typedef struct mutex mutex_t; -#define kmem_alloc(map, ptrref, size) -#define kmem_free(map, ptr, size) -#define mutex_alloc(x) (NULL) -#define mutex_lock(x) -#define mutex_unlock(x) - /* The number of BSM records allocated. */ static int bsm_rec_count = 0; @@ -65,7 +58,7 @@ /* * Lock for serializing access to the list of audit records. */ -static mutex_t *bsm_audit_mutex; +static struct mtx bsm_audit_mutex; /* * Initialize the BSM auditing subsystem. @@ -75,7 +68,7 @@ { printf("BSM auditing present\n"); LIST_INIT(&bsm_free_q); - bsm_audit_mutex = mutex_alloc(ETAP_NO_TRACE); + mtx_init(&bsm_audit_mutex, "bsm_audit_mutex", NULL, MTX_DEF); } /* @@ -94,38 +87,31 @@ /* * Find an unused record, remove it from the free list, mark as used */ - mutex_lock(bsm_audit_mutex); + mtx_lock(&bsm_audit_mutex); if (!LIST_EMPTY(&bsm_free_q)) { rec = LIST_FIRST(&bsm_free_q); LIST_REMOVE(rec, au_rec_q); } - mutex_unlock(bsm_audit_mutex); + mtx_unlock(&bsm_audit_mutex); if (rec == NULL) { - mutex_lock(bsm_audit_mutex); + mtx_lock(&bsm_audit_mutex); if (bsm_rec_count >= MAX_AUDIT_RECORDS) { /* XXX We need to increase size of MAX_AUDIT_RECORDS */ - mutex_unlock(bsm_audit_mutex); + mtx_unlock(&bsm_audit_mutex); return NULL; } - mutex_unlock(bsm_audit_mutex); + mtx_unlock(&bsm_audit_mutex); /* * Create a new BSM kernel record. */ - kmem_alloc(kernel_map, &rec, sizeof(*rec)); - if(rec == NULL) { - return NULL; - } - kmem_alloc(kernel_map, &rec->data, - MAX_AUDIT_RECORD_SIZE * sizeof(u_char)); - if((rec->data) == NULL) { - kmem_free(kernel_map, rec, sizeof(*rec)); - return NULL; - } - mutex_lock(bsm_audit_mutex); + rec = malloc(sizeof(*rec), M_AUDIT, M_WAITOK); + rec->data = malloc(MAX_AUDIT_RECORD_SIZE * sizeof(u_char), + M_AUDIT, M_WAITOK); + mtx_lock(&bsm_audit_mutex); bsm_rec_count++; - mutex_unlock(bsm_audit_mutex); + mtx_unlock(&bsm_audit_mutex); } memset(rec->data, 0, MAX_AUDIT_RECORD_SIZE); @@ -205,19 +191,19 @@ /* Free the token list */ while ((tok = TAILQ_FIRST(&rec->token_q))) { TAILQ_REMOVE(&rec->token_q, tok, tokens); - kmem_free(kernel_map, tok->t_data, tok->len); - kmem_free(kernel_map, tok, sizeof(struct au_token)); + free(tok->t_data, M_AUDIT); + free(tok, M_AUDIT); } rec->used = 0; rec->len = 0; - mutex_lock(bsm_audit_mutex); + mtx_lock(&bsm_audit_mutex); /* Add the record to the freelist */ LIST_INSERT_HEAD(&bsm_free_q, rec, au_rec_q); - mutex_unlock(bsm_audit_mutex); + mtx_unlock(&bsm_audit_mutex); } ==== //depot/projects/trustedbsd/audit2/sys/security/audit/bsm_token.c#5 (text+ko) ==== @@ -28,37 +28,26 @@ #include #include #include +#include #include -#include +#include +#include #include #include #include #include -#define kmem_alloc(map, ptrref, size) -#define kmem_free(map, ptr, size) +#include -#define GET_TOKEN_AREA(tok, dptr, length) \ - do {\ - kmem_alloc(kernel_map, &tok, sizeof(*tok)); \ - if(tok != NULL)\ - {\ - tok->len = length;\ - kmem_alloc(kernel_map, &tok->t_data, \ - length * sizeof(u_char));\ - if((dptr = tok->t_data) == NULL)\ - {\ - kmem_free(kernel_map, tok, sizeof(*tok));\ - tok = NULL;\ - }\ - else\ - {\ - memset(dptr, 0, length);\ - }\ - }\ - }while(0) - +#define GET_TOKEN_AREA(tok, dptr, length) \ + do { \ + tok = malloc(sizeof(*tok), M_AUDIT, M_WAITOK); \ + tok->len = length; \ + dptr = tok->t_data = malloc(length * sizeof(u_char), \ + M_AUDIT, M_WAITOK); \ + memset(tok->t_data, 0, length); \ + } while (0) /* ==== //depot/projects/trustedbsd/audit2/sys/security/audit/kern_audit.h#5 (text+ko) ==== @@ -85,6 +85,10 @@ #define ARG_NONE 0x0000000000000000ULL #define ARG_ALL 0xFFFFFFFFFFFFFFFFULL +#ifdef MALLOC_DECLARE +MALLOC_DECLARE(M_AUDIT); +#endif + struct vnode_au_info { mode_t vn_mode; uid_t vn_uid;