Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3155ybp; Thu, 3 Oct 2019 09:21:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEes05t4yUJP9cS7uz3gxL7mhBEv3O+yzFmV7zsrJOihYalLxHUZnqY/NxqCKrfDY9PBgR X-Received: by 2002:a05:6402:65a:: with SMTP id u26mr10459873edx.86.1570119719584; Thu, 03 Oct 2019 09:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570119719; cv=none; d=google.com; s=arc-20160816; b=PVtPD5JRraB4UC8rBhwrM0QskOyq5Dym9xWtLjxflG8vDgWtT8mLD3DFX8As6bM1pA fhHNgsKMSMMaktUG5dGTpBDJvhAaFV1Hv3IZKRX8//z7eaku98eerkx3IGkYV3NE0XRE c7l0rlzdoqqeBbfzXCMnOVU9XB+tlDOroyfvRqpIuckWyAyDS05k1FbNWSlmV3ojK3nl rNfGJsjKsmNywKR5SebmJbo3KswuA6HHd8yV8ATkqSDjbbOiLlXvyUZYpyjbcvZ3NVAV vplJmr9y76yy3oEpXdDRlMHakCbATHRpNd9+bxE0ojQsO3naHubRUQjz8eU4RluuWecM DkeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SkEGSWrAROwe/1JNQWL7D75ZHe6BO8k4bG6TgflhyZ0=; b=VSdlxonmD149LB+T8h7SDVPmY2jHv0YqDrixFGW7KTSl+P2HDBrIz0ljsavBB37Fja uK22On7bcHeuZL/jtpBwdVfz3JkO8dPYwYeclPB9yLEIn5dvMVQYI9ehTLTXVprqhuXT MmIZVrju7Q0Hv4Y4jpel7d7WX+UTy0U4MvMXjjmsV2MVT8fJ+53u1XdfqqrsatyNORo9 HxX63DhkhYT93uvKIm6hgr+0cHJcB3xCiwFbA6bxRdVYi614CItBoqhNw7qq8x6tm/+0 CVFj8NQVkgLXJbkTCm+7RB02N6vwjOE7ZWqaNlFuVBmzXmJsFAhnq+2TEPdBiFhDdhQe YWsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GT+kXmou; 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 d9si1810321edb.371.2019.10.03.09.21.34; Thu, 03 Oct 2019 09:21:59 -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=@kernel.org header.s=default header.b=GT+kXmou; 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 S2388791AbfJCQTz (ORCPT + 99 others); Thu, 3 Oct 2019 12:19:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:47154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388597AbfJCQTy (ORCPT ); Thu, 3 Oct 2019 12:19:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 030EF215EA; Thu, 3 Oct 2019 16:19:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119593; bh=Iz/rm/WQRpcIwAOXL0oPExQ24VLEz8gHHqZ2wCq1jig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GT+kXmouK28GwBhXxQJVlO8agg2JRadozt4J48Eu1/AUpc2Q4czDGXEni9aYrZoJ7 4/x0hmRkDXVlLsA/MS1KkwpyHxzVfORdTx1bxfCjcK6LqzogozdhcK9mwZzzQi0p5M KXURU0zKMJ2yt6rmxrOJdepSGLLp/pEhs2IcIOC8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kent Overstreet , Coly Li , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 123/211] closures: fix a race on wakeup from closure_sync Date: Thu, 3 Oct 2019 17:53:09 +0200 Message-Id: <20191003154515.136772999@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kent Overstreet [ Upstream commit a22a9602b88fabf10847f238ff81fde5f906fef7 ] The race was when a thread using closure_sync() notices cl->s->done == 1 before the thread calling closure_put() calls wake_up_process(). Then, it's possible for that thread to return and exit just before wake_up_process() is called - so we're trying to wake up a process that no longer exists. rcu_read_lock() is sufficient to protect against this, as there's an rcu barrier somewhere in the process teardown path. Signed-off-by: Kent Overstreet Acked-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/closure.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/md/bcache/closure.c b/drivers/md/bcache/closure.c index 73f5319295bc9..c12cd809ab193 100644 --- a/drivers/md/bcache/closure.c +++ b/drivers/md/bcache/closure.c @@ -105,8 +105,14 @@ struct closure_syncer { static void closure_sync_fn(struct closure *cl) { - cl->s->done = 1; - wake_up_process(cl->s->task); + struct closure_syncer *s = cl->s; + struct task_struct *p; + + rcu_read_lock(); + p = READ_ONCE(s->task); + s->done = 1; + wake_up_process(p); + rcu_read_unlock(); } void __sched __closure_sync(struct closure *cl) -- 2.20.1