Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp821103ybp; Wed, 9 Oct 2019 04:54:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqz46XZ3LmysG1Pstj9pwrUFiSn5P0Py4UalJ0LTXaqWc9pakaATho3QFqACe8z1kHSwBPpy X-Received: by 2002:a17:907:393:: with SMTP id ss19mr2353100ejb.62.1570622047055; Wed, 09 Oct 2019 04:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570622047; cv=none; d=google.com; s=arc-20160816; b=UPnqgqsfoSa5DVMCqGT8zbF4jz/FUcm5U4Q1XHgKjFUvLGnBxjxsOqEofF1YVfm4WM cYl3qWFpL0xTuCuLCnVAH4+yHq8yEglVZQD8/Yaa4xIqXyBX29V9sSZiLfZQ+RTnV9lT LUcA6KsLHdR3M/hIqQyRn7DWVl/SfkSdHrFx+rA2z18693Qsjvieo+Fu2+9EdgNSdgLH TK2QTNNHuhe1QoKm5Br67tH5dVLrmy6byfjeJZ98c6xxttkiGIzIVgxaamOowt2jPl+Z NDDWxp6V4qGIV3cr3tODS50dmQuNPKsAJF73nwTU2Zj5o6q9XsWv1lC8IEVPca+7CfF3 e2ww== 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=Igka7ryoSVDxdSWOk6SiGHk4qPCFam09mMVFJT0uYzg=; b=xMcd/1jFite6mdkxF35Fu9wsO3Th/GeN6XHxlIKLbGEG8I2ctb+PflE22r3a3S4HiN pvsO4oYelo0cXDi0dG6wDyq13af+yg78yLbcoxZKplNnbXYMVX+L9iW+ToF6hpYu9Pk3 g1RXs55PdI6GFJ4luzliwf6GrTWi5ob8sIh7QqBSg5BlPUCjkgN1zWs9NcMiF7mv5GQC NBoowOZmtzm6QeFvUvZestIjFOmtyvGGBeNlt5Ose0Ij6Z0tsUeGKPrEF8HF1/eN3RBv W0qhE1qr8CYz0kaK6HXWN9fGUyIFjqip4yqBVYbM+fF3MzKFjEiMTFyhK4dH3D/ard0b YGmQ== 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 f57si1121211ede.78.2019.10.09.04.53.43; Wed, 09 Oct 2019 04:54: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 S1730678AbfJILx2 (ORCPT + 99 others); Wed, 9 Oct 2019 07:53:28 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58907 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbfJILx2 (ORCPT ); Wed, 9 Oct 2019 07:53:28 -0400 Received: from [79.140.115.128] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iIAX0-00013X-4J; Wed, 09 Oct 2019 11:53:26 +0000 Date: Wed, 9 Oct 2019 13:53:25 +0200 From: Christian Brauner To: Marco Elver Cc: Andrea Parri , bsingharora@gmail.com, Dmitry Vyukov , LKML , stable@vger.kernel.org, syzbot+c5d03165a1bd1dead0c1@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: Re: [PATCH] taskstats: fix data-race Message-ID: <20191009115324.iczitezqqkotpocj@wittgenstein> References: <20191008154418.GA16972@andrea> <20191009113134.5171-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 09, 2019 at 01:48:27PM +0200, Marco Elver wrote: > On Wed, 9 Oct 2019 at 13:31, Christian Brauner > wrote: > > > > When assiging and testing taskstats in taskstats_exit() there's a race > > when writing and reading sig->stats when a thread-group with more than > > one thread exits: > > > > cpu0: > > thread catches fatal signal and whole thread-group gets taken down > > do_exit() > > do_group_exit() > > taskstats_exit() > > taskstats_tgid_alloc() > > The tasks reads sig->stats without holding sighand lock seeing garbage. > > > > cpu1: > > task calls exit_group() > > do_exit() > > do_group_exit() > > taskstats_exit() > > taskstats_tgid_alloc() > > The task takes sighand lock and assigns new stats to sig->stats. > > > > Fix this by using smp_load_acquire() and smp_store_release(). > > > > Reported-by: syzbot+c5d03165a1bd1dead0c1@syzkaller.appspotmail.com > > Fixes: 34ec12349c8a ("taskstats: cleanup ->signal->stats allocation") > > Cc: stable@vger.kernel.org > > Signed-off-by: Christian Brauner > > Reviewed-by: Dmitry Vyukov > > --- > > /* v1 */ > > Link: https://lore.kernel.org/r/20191005112806.13960-1-christian.brauner@ubuntu.com > > > > /* v2 */ > > Link: https://lore.kernel.org/r/20191006235216.7483-1-christian.brauner@ubuntu.com > > - Dmitry Vyukov , Marco Elver : > > - fix the original double-checked locking using memory barriers > > > > /* v3 */ > > Link: https://lore.kernel.org/r/20191007110117.1096-1-christian.brauner@ubuntu.com/ > > - Andrea Parri : > > - document memory barriers to make checkpatch happy > > > > /* v4 */ > > - Andrea Parri : > > - use smp_load_acquire(), not READ_ONCE() > > - update commit message > > Acked-by: Marco Elver > > Note that this now looks almost like what I suggested, except the Right, I think we all just needed to get our heads clear about what exactly is happening here. This codepath is not a very prominent one. :) > return at the end of the function is accessing sig->stats again. In > this case, it seems it's fine assuming sig->stats cannot be written > elsewhere. Just wanted to point it out to make sure it's considered. Yes, I considered that but thanks for mentioning it. Note that this patch has a bug. It should be smp_load_acquire(&sig->stats) and not smp_load_acquire(sig->stats). I accidently didn't automatically recompile the patchset after the last change I made. Andrea thankfully caught this. Thanks! Christian