Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2444533pxa; Mon, 24 Aug 2020 14:32:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8Ndf5ynY5v+IEClUZGTBM2QmA5kdA/ClMCzMlE68ilp0Xr+lBDTFQmvIkT+7dB26bLAgT X-Received: by 2002:a17:906:134a:: with SMTP id x10mr7939135ejb.167.1598304770610; Mon, 24 Aug 2020 14:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598304770; cv=none; d=google.com; s=arc-20160816; b=t7+5JsavC6CWX2WujawaNUSqJpsU7++0H1lXqbjOKEl85TLzLt7ifcP1lbq2H2v8a6 jubCBLkt/92mrDB8rULaX87D5Ki+dNThVCxsBkgMlDQgGNF/VJoAjZj6Ox+PcarhRMOj 0Jyr0dbNfLqs128lGvWeCvYZa0wF40HyTTebyy+tTabOT5FkbJBUSdxePQvQRemHkaOd kQz1DlS3G4Yum0IWAIvcaDb3P8sL+uV6dPFmB07wvYMb/N9B4Mi/3i3hJCpQYxB7AAz3 yxBsEEUIfWq4vSJHUAE5Q9p1OfFo0gL3LMVDYpCNtEFO61DQ+KePL2D2pANtF7hqiJzI hn4Q== 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=ip2NfJop1Mn4C2YXcC4jWvJF3zXEyShjXfQMZzz1iVg=; b=jDLmfFU+37F/NPAoGBdiydszHb2loV9VEY3ABlTBAAxkAvwGHqhHe/HBer9D8+UK3I SqzhwX0rAQChB1ZrXnGvCcggd3jqx9pS521+XZFQoyoMcgsQo1pvcSab4WCyuprdK3Y6 dlSpt5H7mV2xb2UABI2JVrfErvwVTh9hLsQ2NKpB7HT5QIHdtsK62iD3qiFjuMSyiGsF vwnYGfHRaqi3Eryb0g/vRIdBVuZhSX6sNcB8YAzQgVuAOOlf+oTKOwDxOCDf7+rvw08v bTkO17v5W/NgbZSHlTc21XjAbxnzLVuCuYXY9+l8VuCx1sfoh3U91tUSoh3y7Wy0gOLh +A9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=tML63gh5; 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 j8si1985482ejx.291.2020.08.24.14.32.27; Mon, 24 Aug 2020 14:32:50 -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=tML63gh5; 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 S1726788AbgHXV3P (ORCPT + 99 others); Mon, 24 Aug 2020 17:29:15 -0400 Received: from linux.microsoft.com ([13.77.154.182]:38174 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbgHXV3P (ORCPT ); Mon, 24 Aug 2020 17:29:15 -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 0E9BE20B4908; Mon, 24 Aug 2020 14:29:14 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0E9BE20B4908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1598304554; bh=ip2NfJop1Mn4C2YXcC4jWvJF3zXEyShjXfQMZzz1iVg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=tML63gh5vIHnEShue4Gs5/MFXFSbnNSfC0Xg3Rz86qEQjJCkZx1OZ2bBrGon+vqIx H9xTuCTTInq88f5FoCa+yhFtEr7FoHyiZvpo8Tvko6HInpTGRwnUza+RObtZRLSMp8 D6BEQBhQ11OIbCxNAXvLWcv85l6kBhrSLIQmJ/zc= Subject: Re: [PATCH] SELinux: Measure state and hash of policy using IMA To: Ondrej Mosnacek , Stephen Smalley Cc: Mimi Zohar , Casey Schaufler , Tyler Hicks , tusharsu@linux.microsoft.com, Sasha Levin , James Morris , linux-integrity@vger.kernel.org, SElinux list , LSM List , linux-kernel References: <20200822010018.19453-1-nramas@linux.microsoft.com> <418618c4-a0c6-6b28-6718-2726a29b83c5@linux.microsoft.com> From: Lakshmi Ramasubramanian Message-ID: Date: Mon, 24 Aug 2020 14:29:13 -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 8/24/20 1:01 PM, Ondrej Mosnacek wrote: > On Mon, Aug 24, 2020 at 9:30 PM Stephen Smalley > wrote: >> On Mon, Aug 24, 2020 at 2:13 PM Lakshmi Ramasubramanian >> wrote: >>> >>> On 8/24/20 7:00 AM, Stephen Smalley wrote: >>> >>>>> +int security_read_policy_kernel(struct selinux_state *state, >>>>> + void **data, size_t *len) >>>>> +{ >>>>> + int rc; >>>>> + >>>>> + rc = security_read_policy_len(state, len); >>>>> + if (rc) >>>>> + return rc; >>>>> + >>>>> + *data = vmalloc(*len); >>>>> + if (!*data) >>>>> + return -ENOMEM; >>>>> >>>>> + return security_read_selinux_policy(state, data, len); >>>>> } >>>> >>>> See the discussion here: >>>> https://lore.kernel.org/selinux/20200824113015.1375857-1-omosnace@redhat.com/T/#t >>>> >>>> In order for this to be safe, you need to ensure that all callers of >>>> security_read_policy_kernel() have taken fsi->mutex in selinuxfs and >>>> any use of security_read_policy_len() occurs while holding the mutex. >>>> Otherwise, the length can change between security_read_policy_len() >>>> and security_read_selinux_policy() if policy is reloaded. >>>> >>> >>> "struct selinux_fs_info" is available when calling >>> security_read_policy_kernel() - currently in measure.c. >>> Only "struct selinux_state" is. >>> >>> Is Ondrej's re-try approach I need to use to workaround policy reload issue? >> >> No, I think perhaps we should move the mutex to selinux_state instead >> of selinux_fs_info. selinux_fs_info has a pointer to selinux_state so >> it can then use it indirectly. Note that your patches are going to >> conflict with other ongoing work in the selinux next branch that is >> refactoring policy load and converting the policy rwlock to RCU. > > Yeah, and I'm experimenting with a patch on top of Stephen's RCU work > that would allow you to do this in a straightforward way without even > messing with the fsi->mutex. My patch may or may not be eventually > committed, but either way I'd recommend holding off on this for a > while until the dust settles around the RCU conversion. > I can make the SELinux\IMA changes in "selinux next branch" taking dependencies on Stephen's patches + relevant IMA patches. Could you please let me know the URL to the "selinux next branch"? thanks, -lakshmi