Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp843281pxb; Tue, 3 Nov 2020 14:10:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwENYGEJgswdybMFCt7D/7RfUfWwG1lkFBzyOhlYhVo1zAa8TFtPJmYT1lHxATD/CrbTQa X-Received: by 2002:a17:906:1381:: with SMTP id f1mr21375756ejc.87.1604441403085; Tue, 03 Nov 2020 14:10:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604441403; cv=none; d=google.com; s=arc-20160816; b=a3KIg+t5OPkz/iqF+HeyzL5f/d039e+IC2NWEPtZp2ou3MPXwrsTXtP94foa0hYRc8 rwN200yo0JSq5lVxUUwgerjrlC2vqDscnHdEnt+6l+eeVf1mpQN0pS0IW0Zg8SFi/76I gzJkCdCKn1pFgePRMmjTxHg3usqLr7Wmt5DwsuIPTOjtLaiq3ZPCoO4Wf6Jpd88GaAyJ kheYvD9OtzVKikjXVLVrScxZi+32s5HCxsKVTHz1gPgYpLYWexjZM3gtGOnGubAFPwax dCh2UVhqhVeBC8etKFAADYCDJiZIyAtbGdBOzcoNWJFhbXCFcmA/C9xbDQXLguUkj0Aw Tg3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Pa5HBzB7G13U/lPSIlps3LUn6mI9XygmgKhiSRTnINs=; b=F8JtypJJAhC3GFek8fbIrLciQIRPqNAaO8OZyG4cvVU4UO+/2DUDgibdRSwT3txxQv KBJeOug7tqVt16mPddCYA2jiGS+DTerOUfjT6YDWk4NT337zWzALm/4H1COL8sgscyTT gO2e49B1pqn5kNSpWS84wR2OGpBrqPlTDor/dBanjn2ZimkMhrKSH6phrX4/sD7eGNcB k1ndBGSHWwzBRs0oE/a8qPussByi26ujwlvBesGN9J+3P7RYXqkKQ2GgAjQpQJg1Wkmt rvqftsloBJJCCcA1xr7lT+ofb1fZxR7vXQrR7Li7xPmwumdmr/sJeZqGiQOPRE+qEJi0 9Swg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="FmfTg/8A"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h17si124883ejf.88.2020.11.03.14.09.38; Tue, 03 Nov 2020 14:10:03 -0800 (PST) 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=@kernel.org header.s=default header.b="FmfTg/8A"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730444AbgKCUl4 (ORCPT + 99 others); Tue, 3 Nov 2020 15:41:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:53764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730421AbgKCUlv (ORCPT ); Tue, 3 Nov 2020 15:41:51 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A4979223AB; Tue, 3 Nov 2020 20:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436110; bh=b+EUa/HZZerOFZhY3a4qiUmM1E6DUp3dYuXsys0e0qM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FmfTg/8AvrvWbk2HiwwunN8W06dgryk42kh4bWC33aiaj3lx/6r1kHThC45Xlk1wT 3swl/1CqtXwR1OUvzmnIwf141l2RLkEe4BP6Sw+1m+TqmvRb5RWtPq3sY4bgBQoXGS 3jWd4fyVCaDxRrhaNXt765nLocAYNHsHtmP5q944= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Smalley , Paul Moore , Sasha Levin Subject: [PATCH 5.9 108/391] selinux: access policycaps with READ_ONCE/WRITE_ONCE Date: Tue, 3 Nov 2020 21:32:39 +0100 Message-Id: <20201103203354.109057343@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephen Smalley [ Upstream commit e8ba53d0023a76ba0f50e6ee3e6288c5442f9d33 ] Use READ_ONCE/WRITE_ONCE for all accesses to the selinux_state.policycaps booleans to prevent compiler mischief. Signed-off-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- security/selinux/include/security.h | 14 +++++++------- security/selinux/ss/services.c | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h index b0e02cfe3ce14..8a432f646967e 100644 --- a/security/selinux/include/security.h +++ b/security/selinux/include/security.h @@ -177,49 +177,49 @@ static inline bool selinux_policycap_netpeer(void) { struct selinux_state *state = &selinux_state; - return state->policycap[POLICYDB_CAPABILITY_NETPEER]; + return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_NETPEER]); } static inline bool selinux_policycap_openperm(void) { struct selinux_state *state = &selinux_state; - return state->policycap[POLICYDB_CAPABILITY_OPENPERM]; + return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_OPENPERM]); } static inline bool selinux_policycap_extsockclass(void) { struct selinux_state *state = &selinux_state; - return state->policycap[POLICYDB_CAPABILITY_EXTSOCKCLASS]; + return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_EXTSOCKCLASS]); } static inline bool selinux_policycap_alwaysnetwork(void) { struct selinux_state *state = &selinux_state; - return state->policycap[POLICYDB_CAPABILITY_ALWAYSNETWORK]; + return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_ALWAYSNETWORK]); } static inline bool selinux_policycap_cgroupseclabel(void) { struct selinux_state *state = &selinux_state; - return state->policycap[POLICYDB_CAPABILITY_CGROUPSECLABEL]; + return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_CGROUPSECLABEL]); } static inline bool selinux_policycap_nnp_nosuid_transition(void) { struct selinux_state *state = &selinux_state; - return state->policycap[POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION]; + return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION]); } static inline bool selinux_policycap_genfs_seclabel_symlinks(void) { struct selinux_state *state = &selinux_state; - return state->policycap[POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS]; + return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS]); } int security_mls_enabled(struct selinux_state *state); diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 1caf4e6033096..c55b3063753ab 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -2103,7 +2103,8 @@ static void security_load_policycaps(struct selinux_state *state) struct ebitmap_node *node; for (i = 0; i < ARRAY_SIZE(state->policycap); i++) - state->policycap[i] = ebitmap_get_bit(&p->policycaps, i); + WRITE_ONCE(state->policycap[i], + ebitmap_get_bit(&p->policycaps, i)); for (i = 0; i < ARRAY_SIZE(selinux_policycap_names); i++) pr_info("SELinux: policy capability %s=%d\n", -- 2.27.0