Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4129071ybg; Mon, 21 Oct 2019 04:20:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAYB3qYB86nPhL4cd70NFLJnLWY7Wpjvbs2oUewYuhQyB71xqkuOple40egW38kug0nkWC X-Received: by 2002:a05:6402:6c9:: with SMTP id n9mr23435114edy.190.1571656807580; Mon, 21 Oct 2019 04:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571656807; cv=none; d=google.com; s=arc-20160816; b=I+SUgHJdY1HsvWQQgHFEynkSXnXizgBunjLOXtxhjxIzwN3qE0baAd3NHHKsY8iAG2 chW/CFVD6l2Bo5VfzOoNqqR/AYazXQC6Ka/AITkzaS10kqF0CP8N6OjWkyRya354pZkb Fv7IBQmmGiVHiHYxthocCizB0n7KaleFSrKwxyhnkUkXy1PJXB8Mp1E4za5Zl69VWdbF d6V0bbgt6O9LrPos8uudxkrth6MDQkyIlEkZTnSMPa42AXBUkjMxpnwQ8Xec4hNV5qEL kKNpKvLvwPCyyMJFGhW17dKSt0szMifDqbXEdizwuV0IoUKKgtVBswqpkvK2Od5/iVmn EK1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ENBuAmLEX5r5J7fvvN8zwfiAA7WD3H3zSXdLg3jqqtM=; b=JOqWXLpdmfpuqtOJNPu+V9qhkUcw2p7uoDA2jEdDH28o1r/JshEqGuWr2gwfKsZbHb u3ysfIaxkbcfPnX8fofEmXJ5lDn17bnINjIkZoC4MqAhGnw+J/YHG34uBgc81cv0crcP KvNSCWLVX/rELtHdXkzw2H+KI3iXsmYUj8x6jN5tqKVaIk445F0SDzDHTSb59EQw3eKC 9TfvSf8MBrKt/3TYf9uHunQxQ3xpA4IrIOlq3L8YZ736BUHfdwg+gCaZav0hmc19kuNi ZG12ywgBbg0oqhUOK8R7EQ3TvH+zLykxoq9ZfWPHLs6qtc08mKfwFSkUXY4uwymq6/yS iOJQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e56si1302381edb.172.2019.10.21.04.19.40; Mon, 21 Oct 2019 04:20:07 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727620AbfJULTb (ORCPT + 99 others); Mon, 21 Oct 2019 07:19:31 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:56970 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726767AbfJULTb (ORCPT ); Mon, 21 Oct 2019 07:19:31 -0400 Received: from [213.220.153.21] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iMVic-0006Ks-23; Mon, 21 Oct 2019 11:19:22 +0000 Date: Mon, 21 Oct 2019 13:19:21 +0200 From: Christian Brauner To: syzbot , oleg@redhat.com Cc: akpm@linux-foundation.org, arnd@arndb.de, christian@brauner.io, deepa.kernel@gmail.com, ebiederm@xmission.com, elver@google.com, guro@fb.com, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, will@kernel.org Subject: Re: KCSAN: data-race in exit_signals / prepare_signal Message-ID: <20191021111920.frmc3njkha4c3a72@wittgenstein> References: <0000000000003b1e8005956939f1@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <0000000000003b1e8005956939f1@google.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [+Cc Will] On Mon, Oct 21, 2019 at 03:34:07AM -0700, syzbot wrote: > Hello, > > syzbot found the following crash on: > > HEAD commit: d724f94f x86, kcsan: Enable KCSAN for x86 > git tree: https://github.com/google/ktsan.git kcsan > console output: https://syzkaller.appspot.com/x/log.txt?x=13eab79f600000 > kernel config: https://syzkaller.appspot.com/x/.config?x=c0906aa620713d80 > dashboard link: https://syzkaller.appspot.com/bug?extid=492a4acccd8fc75ddfd0 > compiler: gcc (GCC) 9.0.0 20181231 (experimental) > > Unfortunately, I don't have any reproducer for this crash yet. > > IMPORTANT: if you fix the bug, please add the following tag to the commit: > Reported-by: syzbot+492a4acccd8fc75ddfd0@syzkaller.appspotmail.com > > ================================================================== > BUG: KCSAN: data-race in exit_signals / prepare_signal This traces back to Oleg fixing a race between a group stop and a thread exiting before it notices that it has a pending signal or is in the middle of do_exit() already, causing group stop to get wacky. The original commit to fix this race is commit d12619b5ff56 ("fix group stop with exit race") which took sighand lock before setting PF_EXITING on the thread. Later on in commit 5dee1707dfbf ("move the related code from exit_notify() to exit_signals()") an improvement was made for the single-threaded case and the case where the group stop is already in progress. This removed the sighand lock around the PF_EXITING assignment. If the race really matters and given how tsk->flags is currently accessed everywhere the simple fix for now might be: diff --git a/kernel/signal.c b/kernel/signal.c index c4da1ef56fdf..cf61e044c4cc 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2819,7 +2819,9 @@ void exit_signals(struct task_struct *tsk) cgroup_threadgroup_change_begin(tsk); if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) { + spin_lock_irq(&tsk->sighand->siglock); tsk->flags |= PF_EXITING; + spin_unlock_irq(&tsk->sighand->siglock); cgroup_threadgroup_change_end(tsk); return; } Christian