Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2744044ybh; Mon, 9 Mar 2020 12:06:27 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu3EqY0fjWsy9t2irVBk3+8a+KGkFYiGSaUi0lKY/TdUQAr/3j7v5do1VFAYlxq+FKGTEwJ X-Received: by 2002:a9d:b8f:: with SMTP id 15mr11964669oth.256.1583780787160; Mon, 09 Mar 2020 12:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583780787; cv=none; d=google.com; s=arc-20160816; b=QRDoBa+aPtHlYJAgOSxRlripZ5bbZcZ3jUcjFHv/JqRl1Xn1TZ3WGSWX1KkAvBZOpP EM17xwm/aMjVmSjnTLrDKaj7WVNHeb/mtjxugwS+BZF5tj9u7+VRgktBMYFKtFeQ7WY7 3XY95hdSUXH/CIscMXTIW4xZ/dK/rOVWF5g2CI9JsFmlQ4uWhQa15+BmohoiWf41VVn/ +bjuUDXFyNjgyphrsI3zPaPniA6Z1jqYEdhnkNyUTMgMhQOd44lpMz7mbL+xs5Ka5TfQ kXw2bS9nfXkv36baCgt7/lQO0MDz4uE2VF+l0K0TsORhmNuRwcChxfF5xF3idv5hpV/e YgkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=15ARx1YToHX4rpjIXyTdjQwrVNcIJKN1xPCYiL0kg0o=; b=nrtxRvVY3FdRyo1/g3LoiIgfN7Q7PBBO5t66x0riaLNrPphiYqpAXtWGzJMCWSHf+X 2as+jejKxnwSwoNOqLpuCNq8Ah09hMAMGIIX65wBXT3WCP/8WnYm8fzdzGC+WaYGTihO UmWZ8pu+IdHGGn810iY63nmOCeAdpalMBCPHy51lgmZD2uQB/HdIeGwVGdCsM7gLuvli tjWIK/o2LKxbLuo9fjUb1JDignkNzIZNNo4PGQ6P0a25LKczJeCqpmgzngqJL/vvftLm /GOX1jRUaClEiJoBgXvBUNds8Noe8tSK+olGBrPPdOfq4k1mYN/UNCPQA2aIgPrBrZ0I 2KVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Udws6YeY; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11si2577847otk.207.2020.03.09.12.06.13; Mon, 09 Mar 2020 12:06:27 -0700 (PDT) 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=@kernel.org header.s=default header.b=Udws6YeY; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbgCITFS (ORCPT + 99 others); Mon, 9 Mar 2020 15:05:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:47902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727613AbgCITE1 (ORCPT ); Mon, 9 Mar 2020 15:04:27 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 191B62468D; Mon, 9 Mar 2020 19:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583780667; bh=64cjWCbiThdHFvvHyU3CCz9FjTHDjRwEeHSwlRZf0BQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Udws6YeYpOcyByJ+CcccVQH8qZfCiLSomJ08n0VhegRHjEwtpHU4Kt6ZNtjoAL2n7 vFBVbrcVx3KTSd8TjUv6rkYjR+hfHUvHSM/DkU7YNdxY7G1ZAtdg0aiNmyNfEFoF6L JMhPt2TdLiaQvn6fuJr9HDMinMlovucALLyiVMHk= From: paulmck@kernel.org To: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, kernel-team@fb.com, mingo@kernel.org Cc: elver@google.com, andreyknvl@google.com, glider@google.com, dvyukov@google.com, cai@lca.pw, boqun.feng@gmail.com, "Paul E . McKenney" Subject: [PATCH kcsan 20/32] kcsan: Fix misreporting if concurrent races on same address Date: Mon, 9 Mar 2020 12:04:08 -0700 Message-Id: <20200309190420.6100-20-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20200309190359.GA5822@paulmck-ThinkPad-P72> References: <20200309190359.GA5822@paulmck-ThinkPad-P72> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marco Elver If there are at least 4 threads racing on the same address, it can happen that one of the readers may observe another matching reader in other_info. To avoid locking up, we have to consume 'other_info' regardless, but skip the report. See the added comment for more details. Signed-off-by: Marco Elver Signed-off-by: Paul E. McKenney --- kernel/kcsan/report.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c index 3bc590e..abf6852 100644 --- a/kernel/kcsan/report.c +++ b/kernel/kcsan/report.c @@ -422,6 +422,44 @@ static bool prepare_report(unsigned long *flags, const volatile void *ptr, return false; } + access_type |= other_info.access_type; + if ((access_type & KCSAN_ACCESS_WRITE) == 0) { + /* + * While the address matches, this is not the other_info + * from the thread that consumed our watchpoint, since + * neither this nor the access in other_info is a write. + * It is invalid to continue with the report, since we + * only have information about reads. + * + * This can happen due to concurrent races on the same + * address, with at least 4 threads. To avoid locking up + * other_info and all other threads, we have to consume + * it regardless. + * + * A concrete case to illustrate why we might lock up if + * we do not consume other_info: + * + * We have 4 threads, all accessing the same address + * (or matching address ranges). Assume the following + * watcher and watchpoint consumer pairs: + * write1-read1, read2-write2. The first to populate + * other_info is write2, however, write1 consumes it, + * resulting in a report of write1-write2. This report + * is valid, however, now read1 populates other_info; + * read2-read1 is an invalid conflict, yet, no other + * conflicting access is left. Therefore, we must + * consume read1's other_info. + * + * Since this case is assumed to be rare, it is + * reasonable to omit this report: one of the other + * reports includes information about the same shared + * data, and at this point the likelihood that we + * re-report the same race again is high. + */ + release_report(flags, KCSAN_REPORT_RACE_SIGNAL); + return false; + } + /* * Matching & usable access in other_info: keep other_info_lock * locked, as this thread consumes it to print the full report; -- 2.9.5