From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE87DECE58D for ; Wed, 9 Oct 2019 11:53:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F933206B6 for ; Wed, 9 Oct 2019 11:53:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730757AbfJILx2 (ORCPT ); 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