Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1271149ybg; Wed, 23 Oct 2019 13:05:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHZSxypoiGOxXbpnNkrmudFwOXS7HG+0mcfpTIS9538ZjLhVcBMfDPcKDdp318xyrhA5Qf X-Received: by 2002:a17:906:298f:: with SMTP id x15mr34318407eje.50.1571861128884; Wed, 23 Oct 2019 13:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571861128; cv=none; d=google.com; s=arc-20160816; b=t64dI6SB96fcmRMC0iV9QFvQWQ9trz3GIe+7gx8TzRxKWj5T4ct+6FTOknPDxLLX42 R9hpXmn5E+iOolJCUlAtmCnt04lWEvRn6pUe7rVrr4tw9TSK3lY12QrE2Grq9wdT0F0i /oKcQLr50BCxwJmYiey63D40mVR08WLldazaGu+pGkzTNlJpakG2EDCw5HmxWobkjBr4 qqOSiuiBOonfS9ux2dS7BUmMZ9kZ/4oWZk7LO8YJwE9h8kxvXRChLxA+X2GF3PnrnfA2 kUEHLK0N2EdGkfPhgX0fZ++aIkmjyg9qdi2zzC5zuRXQHGoAXwJIhtVgLIEe2wedsLTV YkUw== 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=tx8Ipt4q5mk+6LZ5N4vElAT3OH3r3RgaAatKAFeXRDY=; b=mL4rJUTPeZsp6dVC/Sqlx3glCoUeH2smlXF8IouPKgMHL9NgYaGLDdaNyvb6rh0Mgu Vnsg46lLUu7iCfSuhpunfBI59IOc8lSbiOReZXksI+5PsG3EL8vMq4v3uDKKxAoirDd9 fZCKh2BNYXtz+NltqylbdJWax79p9LiY/MEYpkUyxEKwzupmm/44Izlj1iWcQathM1/7 Xk8yqel7Wb5VsZebkaD1LKOz4ekQC1YgdKRpAgkHW2WgHIOAnm49klSuSiDBP2VyHjwc 9wR8VQ+0ccJeoYXi05CvFowjYW6sy+wBsrj+PM4Ke5HImrKU9DKv1l6lXDBrGuBi/Mb7 gUaw== 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 f23si4352744edc.46.2019.10.23.13.05.04; Wed, 23 Oct 2019 13:05:28 -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 S2405673AbfJWNL6 (ORCPT + 99 others); Wed, 23 Oct 2019 09:11:58 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:32898 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405664AbfJWNL5 (ORCPT ); Wed, 23 Oct 2019 09:11:57 -0400 Received: from [79.140.115.187] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iNGQa-0001WN-Gw; Wed, 23 Oct 2019 13:11:52 +0000 Date: Wed, 23 Oct 2019 15:11:51 +0200 From: Christian Brauner To: Dmitry Vyukov , Will Deacon Cc: Andrea Parri , Will Deacon , LKML , bsingharora@gmail.com, Marco Elver , stable , syzbot , syzkaller-bugs Subject: Re: [PATCH v6] taskstats: fix data-race Message-ID: <20191023131151.ajgnbcvnec3ouc6y@wittgenstein> References: <20191009114809.8643-1-christian.brauner@ubuntu.com> <20191021113327.22365-1-christian.brauner@ubuntu.com> <20191023121603.GA16344@andrea.guest.corp.microsoft.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 23, 2019 at 02:39:55PM +0200, Dmitry Vyukov wrote: > On Wed, Oct 23, 2019 at 2:16 PM Andrea Parri wrote: > > > > On Mon, Oct 21, 2019 at 01:33:27PM +0200, 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. > > > > > > 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. > > > > > > The first approach used smp_load_acquire() and smp_store_release(). > > > However, after having discussed this it seems that the data dependency > > > for kmem_cache_alloc() would be fixed by WRITE_ONCE(). > > > Furthermore, the smp_load_acquire() would only manage to order the stats > > > check before the thread_group_empty() check. So it seems just using > > > READ_ONCE() and WRITE_ONCE() will do the job and I wanted to bring this > > > up for discussion at least. > > > > Mmh, the RELEASE was intended to order the memory initialization in > > kmem_cache_zalloc() with the later ->stats pointer assignment; AFAICT, > > there is no data dependency between such memory accesses. > > I agree. This needs smp_store_release. The latest version that I > looked at contained: > smp_store_release(&sig->stats, stats_new); This is what really makes me wonder. Can the compiler really re-order the kmem_cache_zalloc() call with the assignment. If that's really the case then shouldn't all allocation functions have compiler barriers in them? This then seems like a very generic problem. > > > Correspondingly, the ACQUIRE was intended to order the ->stats pointer > > load with later, _independent dereferences of the same pointer; the > > latter are, e.g., in taskstats_exit() (but not thread_group_empty()). > > How these later loads can be completely independent of the pointer > value? They need to obtain the pointer value from somewhere. And this > can only be done by loaded it. And if a thread loads a pointer and > then dereferences that pointer, that's a data/address dependency and > we assume this is now covered by READ_ONCE. > Or these later loads of the pointer can also race with the store? If To clarify, later loads as in taskstats_exit() and thread_group_empty(), not the later load in the double-checked locking case. > so, I think they also need to use READ_ONCE (rather than turn this earlier > pointer load into acquire). Using READ_ONCE() in the alloc, taskstat_exit(), and thread_group_empty() case. Christian