From owner-p4-projects@FreeBSD.ORG Thu Oct 20 18:44:39 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9568E16A421; Thu, 20 Oct 2005 18:44:38 +0000 (GMT) X-Original-To: perforce@freebsd.org 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 575ED16A41F for ; Thu, 20 Oct 2005 18:44:38 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id E6B9B43D69 for ; Thu, 20 Oct 2005 18:44:37 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j9KIibRT019755 for ; Thu, 20 Oct 2005 18:44:37 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j9KIibhB019752 for perforce@freebsd.org; Thu, 20 Oct 2005 18:44:37 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Thu, 20 Oct 2005 18:44:37 GMT Message-Id: <200510201844.j9KIibhB019752@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 Cc: Subject: PERFORCE change 85610 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Oct 2005 18:44:39 -0000 http://perforce.freebsd.org/chv.cgi?CH=85610 Change 85610 by rwatson@rwatson_zoo on 2005/10/20 18:44:37 Simplify token allocation code: because we allocate with M_WAITOK, failure isn't permitted. When we abandon an audit record because we don't know how to convert it to BSM, make sure that we free the BSM subject token allocated before this decision was made. Affected files ... .. //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_audit.c#27 edit .. //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_token.c#12 edit Differences ... ==== //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_audit.c#27 (text+ko) ==== @@ -116,16 +116,11 @@ tm.tv_usec = ctime->tv_nsec / 1000; tm.tv_sec = ctime->tv_sec; hdr = au_to_header32(tot_rec_size, event, 0, tm); - - if (hdr != NULL) { - /* Add to head of list */ - TAILQ_INSERT_HEAD(&rec->token_q, hdr, tokens); + TAILQ_INSERT_HEAD(&rec->token_q, hdr, tokens); + + trail = au_to_trailer(tot_rec_size); + TAILQ_INSERT_TAIL(&rec->token_q, trail, tokens); - trail = au_to_trailer(tot_rec_size); - if (trail != NULL) - TAILQ_INSERT_TAIL(&rec->token_q, trail, - tokens); - } /* Serialize token data to the record. */ rec->len = tot_rec_size; @@ -1052,6 +1047,8 @@ default: /* We shouldn't fall through to here. */ printf("BSM conversion requested for unknown event %d\n", ar->ar_event); + /* Write the subject token so it is properly freed here. */ + kau_write(rec, subj_tok); kau_free(rec); return (BSM_NOAUDIT); } ==== //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_token.c#12 (text+ko) ==== @@ -59,16 +59,9 @@ #define GET_TOKEN_AREA(t, dptr, length) do { \ t = malloc(sizeof(token_t), M_AUDITBSM, M_WAITOK); \ - if (t != NULL) { \ - t->len = length; \ - t->t_data = malloc(length * sizeof(u_char), \ - M_AUDITBSM, M_WAITOK); \ - if ((dptr = t->t_data) == NULL) { \ - free(t, M_AUDITBSM); \ - t = NULL; \ - } else \ - memset(dptr, 0, length); \ - } \ + t->t_data = malloc(length, M_AUDITBSM, M_WAITOK | M_ZERO); \ + t->len = length; \ + dptr = t->t_data; \ } while (0) /*