Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp893291ybc; Tue, 19 Nov 2019 11:02:01 -0800 (PST) X-Google-Smtp-Source: APXvYqxFWxXENi2Y99JELOr1q168BWn7dT9DX49WnvI18Q6EqmeSpQXmMGMVjhZIHIuNITujpdxG X-Received: by 2002:ac2:434f:: with SMTP id o15mr5205906lfl.190.1574190121450; Tue, 19 Nov 2019 11:02:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574190121; cv=none; d=google.com; s=arc-20160816; b=b0Qx7AKE69EFc4+Z/r8CnQvWbNSKICD5ed9d9aLq+nhPO3d5pBAceSTqL/T6FXaHwt IshNoDn/ZM7ObWauVRL4qWBV06xxzUUveR17orEzWFKktyybhISGYB42TpsbnIn+6H9k vlZ9EMfoAQESYAiOqvRhwANzbSpwZy64Exk8Kc1J7nGGAJ4nWKFhG8cuKsO4ApMj1yZD UFq7Zv0/3Bwle7byW5LVeSRpZABBDCfNGdBNQDqiTtTZ6qTEZ+Fj1CDMTx+1xAN0dorN nuULIEN05SIvWrQfbujSTEzqt8jV3NnC6fA2DgMFMVWYRZfMPeeRONV4XPsURh0eooT5 BI8g== 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:ironport-phdr :dkim-signature; bh=Otwbz/MfqeHzCKb0LGfOQsxR4iVvzAIFYiCKCK//gOU=; b=z2+stkVK1oGDom5EQGkCa9hBzFQf4a3oS8t7wy93EMg4RDeLjTs2aFQ/pUG8POcmkW 8TR2oswMRyuUq0IyZiSirHWHkhIXG/dJisYaPOuwSO0iyhUMHGVvUmw2+U0Y82BehRY0 ao3qVqiXY/F9HT8wy+z3v4Z2agCo2A1AGN9CRTVgeaUa4rl9S4kLJBpnJMkTOJcA+9Ek fbiqwJmAfmXKPTEIku9BBYx+lvz70Y9t/LKMAF48vk4TNuaXSkTAd8eyzklEN3bMToyO OwBS+jQkGVHu3bMQfuutMboMgup4uo56nN5ibWHEai3L9NPtVKL+EoIXplIOTOJ2LDYD zFZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho.nsa.gov header.s=tycho.nsa.gov header.b=Lbswht9F; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tycho.nsa.gov Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6si19277829edk.210.2019.11.19.11.01.35; Tue, 19 Nov 2019 11:02:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@tycho.nsa.gov header.s=tycho.nsa.gov header.b=Lbswht9F; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tycho.nsa.gov Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727590AbfKSS7r (ORCPT + 99 others); Tue, 19 Nov 2019 13:59:47 -0500 Received: from UCOL19PA34.eemsg.mail.mil ([214.24.24.194]:54360 "EHLO UCOL19PA34.eemsg.mail.mil" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727527AbfKSS7n (ORCPT ); Tue, 19 Nov 2019 13:59:43 -0500 X-EEMSG-check-017: 51451598|UCOL19PA34_ESA_OUT01.csd.disa.mil X-IronPort-AV: E=Sophos;i="5.69,219,1571702400"; d="scan'208";a="51451598" Received: from emsm-gh1-uea11.ncsc.mil ([214.29.60.3]) by UCOL19PA34.eemsg.mail.mil with ESMTP/TLS/DHE-RSA-AES256-SHA256; 19 Nov 2019 18:59:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.nsa.gov; i=@tycho.nsa.gov; q=dns/txt; s=tycho.nsa.gov; t=1574189982; x=1605725982; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=Otwbz/MfqeHzCKb0LGfOQsxR4iVvzAIFYiCKCK//gOU=; b=Lbswht9F/JyV+0vNx+z+9w14M/11psdC7yAUTUzJ2zL1DqoiBI7gzblC 91BL0e0fTOHDgF74SSpa2ZpYNIXSPlWz/APtmXphx0YboQ6T6++eFG8Ry KESotGz5FbmW4zZEopD6iyvyu3Za9L2eCE94psV5IjgevTQaYLKKqxeck A/xE6gvJwIK4vMEjeF46+kF9btP5JgquVOFKDOjl74Ot+xNfgSRaDjiqS t69io0fsUi2Lu2PFQoUTQ8/2tT5NJAOegSjooj3dVzvR3PNV0dPoCHExE ICP2gOFNcMlGxhtxv6Fq9rN6VXAnRwPmswFIBb3Ew6W2ymWXhQ8MKPp+Q A==; X-IronPort-AV: E=Sophos;i="5.69,219,1571702400"; d="scan'208";a="35732484" IronPort-PHdr: =?us-ascii?q?9a23=3AtMOERxyON7fNv4rXCy+O+j09IxM/srCxBDY+r6?= =?us-ascii?q?Qd2u4eIJqq85mqBkHD//Il1AaPAdyArasY26GP6vCocFdDyK7JiGoFfp1IWk?= =?us-ascii?q?1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBA?= =?us-ascii?q?j0OxZrKeTpAI7SiNm82/yv95HJbAhEmTSwbalvIBi5rgjdudQajZZhJ60s1h?= =?us-ascii?q?bHv3xEdvhMy2h1P1yThRH85smx/J5n7Stdvu8q+tBDX6vnYak2VKRUAzs6PW?= =?us-ascii?q?874s3rrgTDQhCU5nQASGUWkwFHDBbD4RrnQ5r+qCr6tu562CmHIc37SK0/VD?= =?us-ascii?q?q+46t3ThLjlTwKP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= =?us-ascii?q?B4jvoQLtla4/dEQ09uLpLH5/BrAND1HATad5GGT0jwEYbuOi04Ut9km4xGWE?= =?us-ascii?q?16Adj3y0mYjic=3D?= X-IPAS-Result: =?us-ascii?q?A2ASAAATO9Rd/wHyM5BlGgEBAQEBAQEBAQMBAQEBEQEBA?= =?us-ascii?q?QICAQEBAYFtAgEBAQELAYFzLIFAMyqEKo9aAQEBAQEBBoE2iWaRQwkBAQEBA?= =?us-ascii?q?QEBAQE0AQIBAYRAAoIlJDcGDgIQAQEBBAEBAQEBBQMBAWyFQ4I7KQGCbQEFI?= =?us-ascii?q?wQRQRALGAICJgICVwYBDAYCAQGCXz+CUyWxSH8zhU6DLoFIgQ4oAYwUGHiBB?= =?us-ascii?q?4E4gms+h1WCXgSND4lMRnSWFII1gjeTEgYbgj6MIosxLY4bnBgjgVgrCAIYC?= =?us-ascii?q?CEPgydQERSRJheOQSMDMIEFAQGOMgEB?= Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by emsm-gh1-uea11.NCSC.MIL with ESMTP; 19 Nov 2019 18:59:41 +0000 Received: from moss-pluto.infosec.tycho.ncsc.mil (moss-pluto [192.168.25.131]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id xAJIxedE005094; Tue, 19 Nov 2019 13:59:41 -0500 Subject: Re: [RFC PATCH 1/2] selinux: Don't call avc_compute_av() from RCU path walk To: Will Deacon , selinux@vger.kernel.org Cc: linux-kernel@vger.kernel.org References: <20191119184057.14961-1-will@kernel.org> <20191119184057.14961-2-will@kernel.org> From: Stephen Smalley Message-ID: <5e51f9a5-ba76-a42d-fc2b-9255f8544859@tycho.nsa.gov> Date: Tue, 19 Nov 2019 13:59:40 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191119184057.14961-2-will@kernel.org> 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 11/19/19 1:40 PM, Will Deacon wrote: > 'avc_compute_av()' can block, so we carefully exit the RCU read-side > critical section before calling it in 'avc_has_perm_noaudit()'. > Unfortunately, if we're calling from the VFS layer on the RCU path walk > via 'selinux_inode_permission()' then we're still actually in an RCU > read-side critical section and must not block. avc_compute_av() should never block AFAIK. The blocking concern was with slow_avc_audit(), and even that appears dubious to me. That seems to be more about misuse of d_find_alias in dump_common_audit_data() than anything. > > 'avc_denied()' already handles this by simply returning success and > postponing the auditing until we're called again on the slowpath, so > follow the same approach here and return early if the node lookup fails > on the RCU walk path. > > Signed-off-by: Will Deacon > --- > security/selinux/avc.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/security/selinux/avc.c b/security/selinux/avc.c > index ecd3829996aa..9c183c899e92 100644 > --- a/security/selinux/avc.c > +++ b/security/selinux/avc.c > @@ -1159,16 +1159,19 @@ inline int avc_has_perm_noaudit(struct selinux_state *state, > rcu_read_lock(); > > node = avc_lookup(state->avc, ssid, tsid, tclass); > - if (unlikely(!node)) > + if (unlikely(!node)) { > + if (flags & AVC_NONBLOCKING) > + goto out; > node = avc_compute_av(state, ssid, tsid, tclass, avd, &xp_node); > - else > + } else { > memcpy(avd, &node->ae.avd, sizeof(*avd)); > + } > > denied = requested & ~(avd->allowed); > if (unlikely(denied)) > rc = avc_denied(state, ssid, tsid, tclass, requested, 0, 0, > flags, avd); > - > +out: > rcu_read_unlock(); > return rc; > } >