Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4226651ybg; Mon, 21 Oct 2019 05:54:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQI8P5qpagqRgYp+xf4cEellKTInO3ZP6F1d2GHyneD658Ht7vTXM4CyYVQbCiQxLb8Ev+ X-Received: by 2002:a50:890c:: with SMTP id e12mr6665569ede.277.1571662440886; Mon, 21 Oct 2019 05:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571662440; cv=none; d=google.com; s=arc-20160816; b=gx0ifeM54d//AgPnU3OyFlQ1nfCJaCwrWfjhGBQguzPjtb8x+RuEuA47xvSYp9ach5 afm9MT/1hDCQEq5jh7ptEVIE7eohk5oAVpNeZxjSZYBygYWoiBQ1gHkfEVR6Rv/Dh2ZK RcN/uZSvjQScoahpkS/DqPAR6sgeMFbFiPl1XoJj+uG8Bna6LwWubPqJwsctdhc8lowa Xo/s7eORoh/yWvEsDgJxyoTdpavbS+AG+hIjN3Av620wNyWtHXIj+phzpJRmQprwizYe 2DLJjCbIvW6vKUWkjvCCk9dvKsKwJpEruGNcaC6yaUrQKMHcIIY+C6lduGLS3Yq704WH KiQQ== 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=l7/Tzc9rdGGWD57Mk0SIJhjx9eAw1ELysEcLbbbJ2LU=; b=Qny1ikn/0gJ9pcuyU6XoCU6i70Th0B6OlWdgDMsFY1QZTZ7BZFvKGQj8m2EdDXsps9 73gL/II/6H/ZqBiofXS2WqP6nRXAL94Xssu9hdT9KAjmygnOuAOvVPKo7uKij7dcmUrJ w4xbRYrVwfFOHMlWAFwOBaugVFLQ9cL+gLOHRBxNdjWKSlnoRvZ8J2dmPeNysSVb7kFF ZyE9PpnzRPMiyVbyXiVh4eReSqGvms6Euz+kdfKppu64uSdP+ZjdJmMYtonHX10d1Rh2 OWW6sWXo64MMLs+SPUdAopc1aX998p/3QQMNuNvWpZIK6oD+VxS32BIrwLZse4gIt7KX ExWw== 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 c9si9685366eds.211.2019.10.21.05.53.37; Mon, 21 Oct 2019 05:54:00 -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 S1728292AbfJUMvN (ORCPT + 99 others); Mon, 21 Oct 2019 08:51:13 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58704 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727256AbfJUMvN (ORCPT ); Mon, 21 Oct 2019 08:51:13 -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 1iMX9L-00069c-Du; Mon, 21 Oct 2019 12:51:03 +0000 Date: Mon, 21 Oct 2019 14:51:02 +0200 From: Christian Brauner To: Oleg Nesterov Cc: syzbot , 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: <20191021125101.x7omk7xa2kyc7hue@wittgenstein> References: <0000000000003b1e8005956939f1@google.com> <20191021111920.frmc3njkha4c3a72@wittgenstein> <20191021120029.GA24935@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191021120029.GA24935@redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 21, 2019 at 02:00:30PM +0200, Oleg Nesterov wrote: > On 10/21, Christian Brauner wrote: > > > > 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. > > Not really... sig_task_ignored() didn't check task->flags until the recent > 33da8e7c81 ("signal: Allow cifs and drbd to receive their terminating signals"). > But I think this doesn't matter, see below. > > > 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); > > Well, exit_signals() tries to avoid ->siglock in this case.... > > But this doesn't matter. IIUC the problem is not that exit_signals() sets > PF_EXITING, the problem is that it writes to tsk->flags and kasan detects > the data race. Right, that's the reason I said "If the race really matters". I thought that other writers/readers always take sighand lock. So the easy fix would have been to take sighand lock too. The alternative is that we need to fiddle with task_struct itself and replace flags with an atomic_t or sm which is more invasive and probably more controversial. Christian