Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4719251ybv; Tue, 11 Feb 2020 02:03:17 -0800 (PST) X-Google-Smtp-Source: APXvYqypmWVT2IprbYakcCtIUDpES1ti83obo3Q7nrwQ16tiRcqEwx1frTo+NVAN4qFDRKRGCdoZ X-Received: by 2002:aca:c691:: with SMTP id w139mr2396396oif.17.1581415397724; Tue, 11 Feb 2020 02:03:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581415397; cv=none; d=google.com; s=arc-20160816; b=TyroDHHBmIKaTliRNNKtIRYlgzoMpXjpZkYBEVQKBwT7sA3Z5dIX3jO4ce2t0+c/wW aELDfAzWAn5jAhwr5TBPXPbujipCH5sxA1vsNR7XAOhL7tNhZx5UU97RQsxwQLDzR1Ir N/SJItjwVcGev6j1BBBRzB5Q5KELmk7nO6mo9e5hV+a70UiV0hwrKJGinHGVvJCaduic akGBeAX3KOsZOUKBaPgdZ74TDz7rQqdFa0TVoCjieX02xmpaiWA3dBpS+dAgFN6VB9lb ULqL60FVjCptu+ap6SJ2EJzl+nxgFgS0BR+3oNbsTG75HbHxO5VTVmzgfMeUIDr0FJVO ZG6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=4ErgepGfDI3yrrGPodBZCow6kOhTX1ReLVCDrlwlOKY=; b=ZPDPFxfv7DZJi8xIAS8hxMUncq9bP/1RJUlOIAisFjKDEOpMPUvVOlp1+PLULwRHqz g/YTz2tdkb2zi9E0WyQhm6j8/TSWf7HGh45GhR33r4YAGzG7SZRKiOjxpLI6pLFAqt8/ pzeL8vxH8RiiiEL9NemURiZdwLFJaU2WHt5Fs13SOwSKyiovHyvrtoaw9Z/xMJyJmSfN 6EM6iZ6lpLKy059bsF1jUdnkV1WOkYln8xWGNP/feYb1imW9lK0hzePSTXcVOjx1P16l Y3A6Zs3ldM6dJNTlaxNk+3Hk/lpKaCtDkaWiieCL4+g3t60Hlt0ob719mf6/jHzsNMXY jiqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FqQJM5dW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si1421087oiy.68.2020.02.11.02.03.05; Tue, 11 Feb 2020 02:03:17 -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=@google.com header.s=20161025 header.b=FqQJM5dW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728137AbgBKKDA (ORCPT + 99 others); Tue, 11 Feb 2020 05:03:00 -0500 Received: from mail-wm1-f73.google.com ([209.85.128.73]:58630 "EHLO mail-wm1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbgBKKDA (ORCPT ); Tue, 11 Feb 2020 05:03:00 -0500 Received: by mail-wm1-f73.google.com with SMTP id p2so1106340wmi.8 for ; Tue, 11 Feb 2020 02:02:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=4ErgepGfDI3yrrGPodBZCow6kOhTX1ReLVCDrlwlOKY=; b=FqQJM5dW1/FooZ2cFt2xQ5iJ1Tqxr/S+zlg1ivQ1SkzX+LJssklGFCSACCll8ncIth S83G93n7UzkiRiLY4LZVPlBGJxjWhKyEOCfzt2k5IQxEuZUar1fNNb31Je07/gdPtqN3 GR5HvEGi2L0eWu31vlJE0S7lQaYr33Rib8WyHmURGcmy7+o+p9DW/VX6TqT+WNhZpo8P EWlDnL+65tIdbLAnOxZQkDkXijD2FU7yD1U6IZicFllGphHU5B7O3M+jXYR6kMIs3/7L zJqrwdE593crtsJvki30OZSyR34/duLqlP5/c07V4IdIa08jE5nKE/Y1RmxYbZ0RES0u woOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=4ErgepGfDI3yrrGPodBZCow6kOhTX1ReLVCDrlwlOKY=; b=f4VlAtgsWgGuLKSTIs49FFVorhWEqQit7zdCgR2GRAw2A6i0VweY//aqhFcra6xvtq 9qSxAhFBmo52e58cioZdHJ5IFfsJWXSay19NOherbqYUPzixwQcj09It5riT/rQhnV5N llDj+pzMtt8ScqoIc4QQEmXTKiGeQKHVxYYvn0w9MES5uxX7XDaysBoIKgSAG9pU9bEJ NVuL9hyIldK5dz16KHBYpUPhYQxx6EKeQW+PTpjd9ovjltSl2BuqhfeACAU1rvQdcHh3 Rsk/1ObVdAGj6MW88TA5di1lEFy00eJCjaMQKx59GUBuFFoYUm2mlkaNPSMkZw1tJVOX BU8g== X-Gm-Message-State: APjAAAWn9/se7D+fvXOO8MX/fIzwz1oO3oBIC20PgpMDf3bKPJsvzM+L JKq34ndVxtE8U6HXvCYub7Ow3nZAVw== X-Received: by 2002:adf:fe43:: with SMTP id m3mr8140672wrs.213.1581415377060; Tue, 11 Feb 2020 02:02:57 -0800 (PST) Date: Tue, 11 Feb 2020 11:02:43 +0100 Message-Id: <20200211100243.101187-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.225.g125e21ebc7-goog Subject: [PATCH v2] kcsan: Fix misreporting if concurrent races on same address From: Marco Elver To: elver@google.com Cc: paulmck@kernel.org, andreyknvl@google.com, glider@google.com, dvyukov@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v2: * Improve comment to illustrate more concrete case. --- kernel/kcsan/report.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c index 3bc590e6be7e3..abf6852dff72f 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.25.0.225.g125e21ebc7-goog