Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4188313ybg; Mon, 21 Oct 2019 05:16:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBydgKeMbedBfBpJCOBQD16rK4829ost1p2FbkURb1mIH50zjrZQ9WHtqZNx4V7tSivdd+ X-Received: by 2002:aa7:c24d:: with SMTP id y13mr24654463edo.186.1571660187171; Mon, 21 Oct 2019 05:16:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571660187; cv=none; d=google.com; s=arc-20160816; b=GpFQIbTvX+GDgjWiiM5I2NTBDs+ACEWA/Bem42FfFsBC8kKW8ilem9KHyQwB+eOlHR LGMO0SJozHcq08PYniUI5V2xB6XKZrQaVwJmTlEOfluixw/LRed5kFrS1ruZ8lQ0m759 XTJGDLI+il6CtuBLCmYrSOdqgqwP535Xqe2qJqzhwegHDc561HbWikDxKvRZjATM9bT0 /qZRiPblKDBHzvmxpFbSmgzYbgChkW2PhkNwsm6EEygPAiB7fnE/NL5FzIn5G7BLGM/6 VWrachxF7H6ZoOl1ozNTBelG8LMlaCiMVqX2nA3Ig7ul6m42CVuTovWN/sPUu2OACxbI muCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1lI93YNTuV9z0QswEaOR/XuZAwGw+CRQ58pTCQCCBVA=; b=uO+SdE/lToojkHO07LFUSEj1ww2PkBe4ZH53HsBiHQ2T2VXHJuRfzhIRt7+tP6gBG1 eFDTGLMsmR5Zoz0jubZu6PN6ag403I4OepOOFlSoHarLhJBTkxVUEhr6BTk6X7CSUHxx tQddlN1VERDmxei3e/cJrekHKaZ0Pz6RWO0oFhoKb/xitp6ZbzJ0mn+Q4I6P96Zc1WFL 9LNcW0o+tQn3fMIwbDwcykhLogUEKIyocRRIEOLwT62XDl9roPdZC25c1Ga8g+lcpChx GP0jw6lVZpVWjee3EoUoIw0h1U9BAweahepN+MUybWUMJY1aS1MWsrKSTtbB4MdKhoXA SOig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZjdyHa19; 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 w54si10352983edd.427.2019.10.21.05.16.04; Mon, 21 Oct 2019 05:16: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=@google.com header.s=20161025 header.b=ZjdyHa19; 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 S1728648AbfJUMP3 (ORCPT + 99 others); Mon, 21 Oct 2019 08:15:29 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:37462 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728613AbfJUMP2 (ORCPT ); Mon, 21 Oct 2019 08:15:28 -0400 Received: by mail-oi1-f194.google.com with SMTP id i16so10818452oie.4 for ; Mon, 21 Oct 2019 05:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1lI93YNTuV9z0QswEaOR/XuZAwGw+CRQ58pTCQCCBVA=; b=ZjdyHa190eojc7Vs3ciDRMhe2DzSUghJPm7Juo02qFoKR8IEtGsOVE8gw1inVDqw4s QybrcvyBD/VQbFJnXIo0T9ILSsGxoqHLJFW/UdUY53njccNqdE2GMgz1Dg4IY7raUnou 7AYKUqPaZxtgALSyUiFDUfP1nUpQa2uUrve98ve01kZmfCjTNg7DykYBI/64LSlxYVv0 ncVxPq/UAk821MxREnI9SUedNPsgSeE4YT6NUsyvPobRT+jfkwDkQHh71O45q6DDuJqs uQu3czaRDDKQ9koMGngUYzRmVE9j8VmsSTkg6P/WHh+BBxkYmlFA+9YK/j2VB3qS3B+5 ru/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1lI93YNTuV9z0QswEaOR/XuZAwGw+CRQ58pTCQCCBVA=; b=cF8I+N3Hkb8xVl/hvuhi0jvEmjV1NmHwI44Dk41WRfQgslhk8X1PSa/gGcUBWQ53ry BrgPa0HnbpP3922JBWi9o4ZbLkHHdkFfc4d1hrGO6I79FUGiY4wtZ6TAtiODZNhz5/LW ZG1thnW+XT0xPxfh2uFwEXnfn2oHVmCwjCEJCHA55dg6vySZhHRVZ9nntB41mT15dlVT 12WeekXN4AceORi6c2zT935RCC5l9DJxRYvHInPIdd0S7GlueOrfvShuAi8rf5Ub/267 04WLsHTKYnwVasNo9O18C/f4D4GAoeV9xu/9EelNxmJjU2+o++KmEtmp7W3blnEkWAge Q02g== X-Gm-Message-State: APjAAAWooTEmPb7nQXf5AV2qDHCqjjHdDPTBQHxcAAIsN4jA7BN/3jb/ NzLdzrpj5oNvM507CYLjAYUp/BLyl4g2OQIFOI/7sQ== X-Received: by 2002:a05:6808:4b:: with SMTP id v11mr18996250oic.70.1571660127086; Mon, 21 Oct 2019 05:15:27 -0700 (PDT) MIME-Version: 1.0 References: <0000000000003b1e8005956939f1@google.com> <20191021111920.frmc3njkha4c3a72@wittgenstein> <20191021120029.GA24935@redhat.com> In-Reply-To: <20191021120029.GA24935@redhat.com> From: Marco Elver Date: Mon, 21 Oct 2019 14:15:15 +0200 Message-ID: Subject: Re: KCSAN: data-race in exit_signals / prepare_signal To: Oleg Nesterov Cc: Christian Brauner , syzbot , Andrew Morton , Arnd Bergmann , christian@brauner.io, deepa.kernel@gmail.com, ebiederm@xmission.com, guro@fb.com, LKML , syzkaller-bugs@googlegroups.com, Will Deacon 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 On Mon, 21 Oct 2019 at 14:00, 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. > > For example, freezable_schedule() which sets PF_FREEZER_SKIP can equally > "race" with sig_task_ignored() or with ANY other code which checks this > task's flags. > > I think this is WONTFIX. If taking the spinlock is unnecessary (which AFAIK it probably is) and there are no other writers to this flag, you will still need a WRITE_ONCE(tsk->flags, tsk->flags | PF_EXITING) to avoid the data-race. However, if it is possible that there are concurrent writers setting other bits in flags, you need to ensure that the bits are set atomically (unless it's ok to lose some bits here). This can only be done via 1) taking siglock, or 2) via e.g. atomic_or(...), however, flags is not atomic_t ... -- Marco