From owner-p4-projects@FreeBSD.ORG Wed Nov 30 23:38:20 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 ECF0716A422; Wed, 30 Nov 2005 23:38:19 +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 AA50616A41F for ; Wed, 30 Nov 2005 23:38:19 +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 E17B543D5F for ; Wed, 30 Nov 2005 23:38:18 +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 jAUNcIZt079380 for ; Wed, 30 Nov 2005 23:38:18 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 jAUNcIwQ079377 for perforce@freebsd.org; Wed, 30 Nov 2005 23:38:18 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Wed, 30 Nov 2005 23:38:18 GMT Message-Id: <200511302338.jAUNcIwQ079377@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 87550 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: Wed, 30 Nov 2005 23:38:20 -0000 http://perforce.freebsd.org/chv.cgi?CH=87550 Change 87550 by rwatson@rwatson_peppercorn on 2005/11/30 23:37:24 Rework locking in BSM control code -- acquire mutex in the entry API calls, resulting in atomicity across each full function call (i.e., between tests for fp being non-NULL and calling into lookup functions, etc). Affected files ... .. //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#8 edit Differences ... ==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#8 (text+ko) ==== @@ -50,9 +50,11 @@ /* * Returns the string value corresponding to the given label from the * configuration file. + * + * Must be called with mutex held. */ static int -getstrfromtype(char *name, char **str) +getstrfromtype_locked(char *name, char **str) { char *type, *nl; char *tokptr; @@ -60,17 +62,11 @@ *str = NULL; - pthread_mutex_lock(&mutex); - - if ((fp == NULL) && ((fp = fopen(AUDIT_CONTROL_FILE, "r")) == - NULL)) { - pthread_mutex_unlock(&mutex); + if ((fp == NULL) && ((fp = fopen(AUDIT_CONTROL_FILE, "r")) == NULL)) return (-1); /* Error */ - } while (1) { if (fgets(linestr, AU_LINE_MAX, fp) == NULL) { - pthread_mutex_unlock(&mutex); if (ferror(fp)) return (-1); return (0); /* EOF */ @@ -89,7 +85,6 @@ if (strcmp(name, type) == 0) { /* Found matching name. */ *str = strtok_r(NULL, delim, &last); - pthread_mutex_unlock(&mutex); if (*str == NULL) { errno = EINVAL; return (-1); /* Parse error in file */ @@ -99,7 +94,6 @@ } } - pthread_mutex_unlock(&mutex); return (0); /* EOF */ } @@ -160,11 +154,14 @@ ret = 2; } - pthread_mutex_unlock(&mutex); - if (getstrfromtype(DIR_CONTROL_ENTRY, &dir) < 0) + if (getstrfromtype_locked(DIR_CONTROL_ENTRY, &dir) < 0) { + pthread_mutex_unlock(&mutex); return (-2); + } + pthread_mutex_unlock(&mutex); + if (dir == NULL) return (-1); @@ -191,9 +188,15 @@ return (-2); } - if (getstrfromtype(MINFREE_CONTROL_ENTRY, &min) < 0) + pthread_mutex_lock(&mutex); + + if (getstrfromtype_locked(MINFREE_CONTROL_ENTRY, &min) < 0) { + pthread_mutex_unlock(&mutex); return (-2); + } + pthread_mutex_unlock(&mutex); + if (min == NULL) return (1); @@ -217,8 +220,14 @@ return (-2); } - if (getstrfromtype(FLAGS_CONTROL_ENTRY, &str) < 0) + pthread_mutex_lock(&mutex); + + if (getstrfromtype_locked(FLAGS_CONTROL_ENTRY, &str) < 0) { + pthread_mutex_unlock(&mutex); return (-2); + } + + pthread_mutex_unlock(&mutex); if (str == NULL) return (1); @@ -246,8 +255,13 @@ return (-2); } - if (getstrfromtype(NA_CONTROL_ENTRY, &str) < 0) + pthread_mutex_lock(&mutex); + + if (getstrfromtype_locked(NA_CONTROL_ENTRY, &str) < 0) { + pthread_mutex_unlock(&mutex); return (-2); + } + pthread_mutex_unlock(&mutex); if (str == NULL) return (1);