Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3662485pxk; Mon, 7 Sep 2020 21:45:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6LOw9gY+x5XGM20m8dIhiFTwSL62qNdt6bgeua6pBLUOecuX1GbsW3qS9ZDDdNf2f8PEu X-Received: by 2002:a17:907:10db:: with SMTP id rv27mr23343161ejb.223.1599540348885; Mon, 07 Sep 2020 21:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599540348; cv=none; d=google.com; s=arc-20160816; b=uaoM3LOyQcrbvxU8shayw03USOs7zNoHun4LIjIp5NSpEZ29OmEG1sdXSDGvUmeZiX pgo0VPNzen8Ioo4cuaNrGZi3cGnQ+wPk3ef0fTzlTAShM7I2g2NttroJfIuoncYXzLRK BgVk9wTcauAic8kK3AcAypDmXdC++BMnjETsXUztaQdDcbgI6cr2wtKEKG6ekEFRQWiJ /CzXPobAcGu2cjB3RFyCEBTvSjK/qI+rpqbZqiswO2j7kPPaeQaSr+bWN//qF71+teMR 1w3tlBpIxnJ3bHyn5hu6EKeqfIs8gLjmufk+zF9oaX/ixFOGaJlknJ6UMh/HtntsRoZX b/Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature:dkim-filter; bh=TEOOR8j/hWPxlCxwN4TevnXBuQUcVlAC+4yB4apsr3s=; b=Sy4ZXNBmb6MVnOs/7PkX5DUinhHetd43bk3i16yIOwyNWf7+F/DUfCMktOszZnz2ef Wcu4zFnpx69lRiCVqMtH66Pyln9w85KsySJ3EKnHaD0XQ5IPME8mjdXF8JH8erWOL0Un eLQMoyI2t0S9tmH2FRFwTGYtKLnkyY7/iKP9hUwHAr92IW9hwPphdapqLWSNqaI1w4qx ZyLa3FCKHGfRx/I6hleEAw4IgEclvGyqitxoRHKSBre16eDrG1F7ijeuuOuVU2n9hZKz 8cOcRE/CB66FaBcGGbFMMYl+HSeUgwkvuYAXvHWXKWfm9vqos/hcuy4aPOt6zSoA93A7 CWlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=diLF5Vbk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si11183792eji.521.2020.09.07.21.45.26; Mon, 07 Sep 2020 21:45:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=diLF5Vbk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726216AbgIHEon (ORCPT + 99 others); Tue, 8 Sep 2020 00:44:43 -0400 Received: from linux.microsoft.com ([13.77.154.182]:44740 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725938AbgIHEom (ORCPT ); Tue, 8 Sep 2020 00:44:42 -0400 Received: from [192.168.0.104] (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 76A902074C73; Mon, 7 Sep 2020 21:44:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 76A902074C73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1599540281; bh=TEOOR8j/hWPxlCxwN4TevnXBuQUcVlAC+4yB4apsr3s=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=diLF5VbkJv/7uC5w7isWgG+P1DKYZZIUXljR0d6IQedJ+8aqBnqdVKSrfQoPEmchd urkdbKP642eoCaULdCP0ynG4xZ4G4r8GPSSH6FZgd8jbyYAa5ivVvIdkbeT35Tx8eN 6SuswUvYGNutjw+txEQJtUvqlco0NWd6L0vsAw1M= Subject: Re: [PATCH] SELinux: Measure state and hash of policy using IMA To: Stephen Smalley Cc: Mimi Zohar , Paul Moore , Ondrej Mosnacek , Casey Schaufler , Tyler Hicks , tusharsu@linux.microsoft.com, Sasha Levin , James Morris , linux-integrity@vger.kernel.org, SElinux list , LSM List , linux-kernel References: <20200907213855.3572-1-nramas@linux.microsoft.com> From: Lakshmi Ramasubramanian Message-ID: <7c4e2e9f-54e1-1dee-c33c-64dac0fe9678@linux.microsoft.com> Date: Mon, 7 Sep 2020 21:44:37 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/7/20 3:32 PM, Stephen Smalley wrote: >> Signed-off-by: Lakshmi Ramasubramanian >> Suggested-by: Stephen Smalley >> Reported-by: kernel test robot # error: implicit declaration of function 'vfree' >> Reported-by: kernel test robot # error: implicit declaration of function 'crypto_alloc_shash' >> Reported-by: kernel test robot # sparse: symbol 'security_read_selinux_policy' was not declared. Should it be static? > > Not sure these Reported-by lines are useful since they were just on > submitted versions of the patch not on an actual merged commit. I'll remove them when I update the patch. > >> diff --git a/security/selinux/measure.c b/security/selinux/measure.c >> new file mode 100644 >> index 000000000000..caf9107937d9 >> --- /dev/null >> +++ b/security/selinux/measure.c > >> +void selinux_measure_state(struct selinux_state *state, bool policy_mutex_held) >> +{ > >> + >> + if (!policy_mutex_held) >> + mutex_lock(&state->policy_mutex); >> + >> + rc = security_read_policy_kernel(state, &policy, &policy_len); >> + >> + if (!policy_mutex_held) >> + mutex_unlock(&state->policy_mutex); > > This kind of conditional taking of a mutex is generally frowned upon > in my experience. > You should likely just always take the mutex in the callers of > selinux_measure_state() instead. > In some cases, it may be the caller of the caller. Arguably selinuxfs > could be taking it around all state modifying operations (e.g. > enforce, checkreqprot) not just policy modifying ones although it > isn't strictly for that purpose. Since currently policy_mutex is not used to synchronize access to state variables (enforce, checkreqprot, etc.) I am wondering if selinux_measure_state() should measure only state if policy_mutex is not held by the caller - similar to how we skip measuring policy if initialization is not yet completed. /* * Measure SELinux policy only after initialization is * completed. */ if (!initialized) goto out; -lakshmi