All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	syzbot <syzbot+0789a72b46fd91431bd8@syzkaller.appspotmail.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-security-module@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 25/40] tomoyo: ignore data race while checking quota
Date: Wed, 24 Feb 2021 07:53:25 -0500	[thread overview]
Message-ID: <20210224125340.483162-25-sashal@kernel.org> (raw)
In-Reply-To: <20210224125340.483162-1-sashal@kernel.org>

From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>

[ Upstream commit 5797e861e402fff2bedce4ec8b7c89f4248b6073 ]

syzbot is reporting that tomoyo's quota check is racy [1]. But this check
is tolerant of some degree of inaccuracy. Thus, teach KCSAN to ignore
this data race.

[1] https://syzkaller.appspot.com/bug?id=999533deec7ba6337f8aa25d8bd1a4d5f7e50476

Reported-by: syzbot <syzbot+0789a72b46fd91431bd8@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 security/tomoyo/file.c    | 16 ++++++++--------
 security/tomoyo/network.c |  8 ++++----
 security/tomoyo/util.c    | 24 ++++++++++++------------
 3 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
index 86f7d1b90212a..966f80e4d77e6 100644
--- a/security/tomoyo/file.c
+++ b/security/tomoyo/file.c
@@ -362,14 +362,14 @@ static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a,
 {
 	u16 * const a_perm = &container_of(a, struct tomoyo_path_acl, head)
 		->perm;
-	u16 perm = *a_perm;
+	u16 perm = READ_ONCE(*a_perm);
 	const u16 b_perm = container_of(b, struct tomoyo_path_acl, head)->perm;
 
 	if (is_delete)
 		perm &= ~b_perm;
 	else
 		perm |= b_perm;
-	*a_perm = perm;
+	WRITE_ONCE(*a_perm, perm);
 	return !perm;
 }
 
@@ -437,7 +437,7 @@ static bool tomoyo_merge_mkdev_acl(struct tomoyo_acl_info *a,
 {
 	u8 *const a_perm = &container_of(a, struct tomoyo_mkdev_acl,
 					 head)->perm;
-	u8 perm = *a_perm;
+	u8 perm = READ_ONCE(*a_perm);
 	const u8 b_perm = container_of(b, struct tomoyo_mkdev_acl, head)
 		->perm;
 
@@ -445,7 +445,7 @@ static bool tomoyo_merge_mkdev_acl(struct tomoyo_acl_info *a,
 		perm &= ~b_perm;
 	else
 		perm |= b_perm;
-	*a_perm = perm;
+	WRITE_ONCE(*a_perm, perm);
 	return !perm;
 }
 
@@ -517,14 +517,14 @@ static bool tomoyo_merge_path2_acl(struct tomoyo_acl_info *a,
 {
 	u8 * const a_perm = &container_of(a, struct tomoyo_path2_acl, head)
 		->perm;
-	u8 perm = *a_perm;
+	u8 perm = READ_ONCE(*a_perm);
 	const u8 b_perm = container_of(b, struct tomoyo_path2_acl, head)->perm;
 
 	if (is_delete)
 		perm &= ~b_perm;
 	else
 		perm |= b_perm;
-	*a_perm = perm;
+	WRITE_ONCE(*a_perm, perm);
 	return !perm;
 }
 
@@ -655,7 +655,7 @@ static bool tomoyo_merge_path_number_acl(struct tomoyo_acl_info *a,
 {
 	u8 * const a_perm = &container_of(a, struct tomoyo_path_number_acl,
 					  head)->perm;
-	u8 perm = *a_perm;
+	u8 perm = READ_ONCE(*a_perm);
 	const u8 b_perm = container_of(b, struct tomoyo_path_number_acl, head)
 		->perm;
 
@@ -663,7 +663,7 @@ static bool tomoyo_merge_path_number_acl(struct tomoyo_acl_info *a,
 		perm &= ~b_perm;
 	else
 		perm |= b_perm;
-	*a_perm = perm;
+	WRITE_ONCE(*a_perm, perm);
 	return !perm;
 }
 
diff --git a/security/tomoyo/network.c b/security/tomoyo/network.c
index f9ff121d7e1eb..a89ed55d85d41 100644
--- a/security/tomoyo/network.c
+++ b/security/tomoyo/network.c
@@ -233,14 +233,14 @@ static bool tomoyo_merge_inet_acl(struct tomoyo_acl_info *a,
 {
 	u8 * const a_perm =
 		&container_of(a, struct tomoyo_inet_acl, head)->perm;
-	u8 perm = *a_perm;
+	u8 perm = READ_ONCE(*a_perm);
 	const u8 b_perm = container_of(b, struct tomoyo_inet_acl, head)->perm;
 
 	if (is_delete)
 		perm &= ~b_perm;
 	else
 		perm |= b_perm;
-	*a_perm = perm;
+	WRITE_ONCE(*a_perm, perm);
 	return !perm;
 }
 
@@ -259,14 +259,14 @@ static bool tomoyo_merge_unix_acl(struct tomoyo_acl_info *a,
 {
 	u8 * const a_perm =
 		&container_of(a, struct tomoyo_unix_acl, head)->perm;
-	u8 perm = *a_perm;
+	u8 perm = READ_ONCE(*a_perm);
 	const u8 b_perm = container_of(b, struct tomoyo_unix_acl, head)->perm;
 
 	if (is_delete)
 		perm &= ~b_perm;
 	else
 		perm |= b_perm;
-	*a_perm = perm;
+	WRITE_ONCE(*a_perm, perm);
 	return !perm;
 }
 
diff --git a/security/tomoyo/util.c b/security/tomoyo/util.c
index eba0b3395851e..3e6be8ff9a396 100644
--- a/security/tomoyo/util.c
+++ b/security/tomoyo/util.c
@@ -1036,30 +1036,30 @@ bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r)
 
 		if (ptr->is_deleted)
 			continue;
+		/*
+		 * Reading perm bitmap might race with tomoyo_merge_*() because
+		 * caller does not hold tomoyo_policy_lock mutex. But exceeding
+		 * max_learning_entry parameter by a few entries does not harm.
+		 */
 		switch (ptr->type) {
 		case TOMOYO_TYPE_PATH_ACL:
-			perm = container_of(ptr, struct tomoyo_path_acl, head)
-				->perm;
+			data_race(perm = container_of(ptr, struct tomoyo_path_acl, head)->perm);
 			break;
 		case TOMOYO_TYPE_PATH2_ACL:
-			perm = container_of(ptr, struct tomoyo_path2_acl, head)
-				->perm;
+			data_race(perm = container_of(ptr, struct tomoyo_path2_acl, head)->perm);
 			break;
 		case TOMOYO_TYPE_PATH_NUMBER_ACL:
-			perm = container_of(ptr, struct tomoyo_path_number_acl,
-					    head)->perm;
+			data_race(perm = container_of(ptr, struct tomoyo_path_number_acl, head)
+				  ->perm);
 			break;
 		case TOMOYO_TYPE_MKDEV_ACL:
-			perm = container_of(ptr, struct tomoyo_mkdev_acl,
-					    head)->perm;
+			data_race(perm = container_of(ptr, struct tomoyo_mkdev_acl, head)->perm);
 			break;
 		case TOMOYO_TYPE_INET_ACL:
-			perm = container_of(ptr, struct tomoyo_inet_acl,
-					    head)->perm;
+			data_race(perm = container_of(ptr, struct tomoyo_inet_acl, head)->perm);
 			break;
 		case TOMOYO_TYPE_UNIX_ACL:
-			perm = container_of(ptr, struct tomoyo_unix_acl,
-					    head)->perm;
+			data_race(perm = container_of(ptr, struct tomoyo_unix_acl, head)->perm);
 			break;
 		case TOMOYO_TYPE_MANUAL_TASK_ACL:
 			perm = 0;
-- 
2.27.0


  parent reply	other threads:[~2021-02-24 14:00 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 12:53 [PATCH AUTOSEL 5.4 01/40] staging: fwserial: Fix error handling in fwserial_create Sasha Levin
2021-02-24 12:53 ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 02/40] x86/reboot: Add Zotac ZBOX CI327 nano PCI reboot quirk Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 03/40] vt/consolemap: do font sum unsigned Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 04/40] wlcore: Fix command execute failure 19 for wl12xx Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 05/40] Bluetooth: hci_h5: Set HCI_QUIRK_SIMULTANEOUS_DISCOVERY for btrtl Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 06/40] pktgen: fix misuse of BUG_ON() in pktgen_thread_worker() Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 07/40] ath10k: fix wmi mgmt tx queue full due to race condition Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 08/40] x86/build: Treat R_386_PLT32 relocation as R_386_PC32 Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 09/40] Bluetooth: Fix null pointer dereference in amp_read_loc_assoc_final_data Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 10/40] staging: most: sound: add sanity check for function argument Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 11/40] staging: bcm2835-audio: Replace unsafe strcpy() with strscpy() Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 12/40] brcmfmac: Add DMI nvram filename quirk for Predia Basic tablet Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 13/40] brcmfmac: Add DMI nvram filename quirk for Voyo winpad A15 tablet Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 14/40] drm/hisilicon: Fix use-after-free Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 15/40] udlfb: Fix memory leak in dlfb_usb_probe Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 16/40] crypto: tcrypt - avoid signed overflow in byte count Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 17/40] drm/amdgpu: Add check to prevent IH overflow Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 18/40] PCI: Add a REBAR size quirk for Sapphire RX 5600 XT Pulse Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 19/40] drm/amd/display: Guard against NULL pointer deref when get_i2c_info fails Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 20/40] media: mceusb: sanity check for prescaler value Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 21/40] media: v4l2-ctrls.c: fix shift-out-of-bounds in std_validate Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 22/40] media: uvcvideo: Allow entities with no pads Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 23/40] f2fs: handle unallocated section and zone on pinned/atgc Sasha Levin
2021-02-24 12:53   ` [f2fs-dev] " Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 24/40] f2fs: fix to set/clear I_LINKABLE under i_lock Sasha Levin
2021-02-24 12:53   ` [f2fs-dev] " Sasha Levin
2021-02-24 12:53 ` Sasha Levin [this message]
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 26/40] nvme-core: add cancel tagset helpers Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 27/40] nvme-rdma: add clean action for failed reconnection Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 28/40] nvme-tcp: " Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 29/40] smackfs: restrict bytes count in smackfs write functions Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 30/40] Drivers: hv: vmbus: Resolve race condition in vmbus_onoffer_rescind() Sasha Levin
2021-02-24 13:20   ` Andrea Parri
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 31/40] ASoC: Intel: Add DMI quirk table to soc_intel_is_byt_cr() Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 32/40] btrfs: fix error handling in commit_fs_roots Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 33/40] perf/x86/kvm: Add Cascade Lake Xeon steppings to isolation_ucodes[] Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 34/40] erofs: fix shift-out-of-bounds of blkszbits Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 35/40] parisc: Bump 64-bit IRQ stack size to 64 KB Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 36/40] sched/features: Fix hrtick reprogramming Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 37/40] ASoC: Intel: bytcr_rt5640: Add quirk for the Estar Beauty HD MID 7316R tablet Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 38/40] ASoC: Intel: bytcr_rt5640: Add quirk for the Voyo Winpad A15 tablet Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 39/40] ASoC: Intel: bytcr_rt5651: Add quirk for the Jumper EZpad 7 tablet Sasha Levin
2021-02-24 12:53   ` Sasha Levin
2021-02-24 12:53 ` [PATCH AUTOSEL 5.4 40/40] ASoC: Intel: bytcr_rt5640: Add quirk for the Acer One S1002 tablet Sasha Levin
2021-02-24 12:53   ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210224125340.483162-25-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+0789a72b46fd91431bd8@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.