Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp663856pxb; Tue, 5 Apr 2022 17:51:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzM9jev9z0mhO3sEJMJPkv3XM8OWjndTVfdFnV6qaeKaG3U1dFIinIuEdhzMBbA4FTl2s9c X-Received: by 2002:a50:da8b:0:b0:415:a122:d7ad with SMTP id q11-20020a50da8b000000b00415a122d7admr6247083edj.123.1649206316342; Tue, 05 Apr 2022 17:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649206316; cv=none; d=google.com; s=arc-20160816; b=qHNZc/ciykjEBS2iRjX6qolI8vAq95RZ/jUXM1hDJmigLjZO5OKf2SZ5KXslYxWtWY 7iCP3V9+qS0aK2UOAVhciPVD7tTTWrh5nhSQdute55m7nAS6Yh5xxMGHeNvmc+pObpOD X98vWg7UI9fRwBq/Qg3xNBTHb6uF0ao1f1uNDrWsihBAUmGlxoochntnOl1QfSsFfd9b jgPumtHSCXYeBJ6ChE+p683U4znDYRTFPGvsJKtu9DO33etSamLvSXUtiUhS1T0xCPBK DlA3EuGg6+P1KXpXRb/Tlr3zZ5+UKcE4WApilgSFsAjxW/guYSdasWS+NjUU05O3hEqB brvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NAM3qAeRawHLmGhilI/GHJ6WbtcZPOOwTgdPpnPoGGc=; b=Iwquy0eyXVYw8tRlHmdUXu74VscGj/DwvVMikBxm3GrIZxz9wCHMDywgt4lv9rniqL 6KB3trc6+H4MnN35VEeYcNcQHkG0U0vIQCLAEFw4xweWdOTkYe2UHywkR8X1QfuM9k9C mSgW/YSAfX1Om1Y/YNpJI3IRub7s7+Klm5n7KyDbpYVB1CmyADr+pmXnuRRlnrefedtY e9CqM8Wmt5y6H4Jynni6raE4gLGbiUhpLLFlwNKx19xGrtfs229XtP1SltJY8aysGYDX 8mdro1R8u7W7Gc2pE9OrgADGEukWeGlf9S9Ejk12LJTpFrrQhQhNiBebyeLVChgR1bKj T6xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bpADlPwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14-20020a170906284e00b006e7ede451d8si6269618ejc.957.2022.04.05.17.51.21; Tue, 05 Apr 2022 17:51:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bpADlPwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387614AbiDEOcg (ORCPT + 99 others); Tue, 5 Apr 2022 10:32:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238963AbiDEJdN (ORCPT ); Tue, 5 Apr 2022 05:33:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99CD063FD; Tue, 5 Apr 2022 02:21:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5170BB81C77; Tue, 5 Apr 2022 09:21:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93A8BC385A3; Tue, 5 Apr 2022 09:20:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150460; bh=mIYdWx0WBpNnvt8DHmteblO2kXpl0mYYQv47KMUPvpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bpADlPwX4RpdO+mJsvCpdrmzgoOASS1hX9NIW82kUn2csq3nSPd1JDUi2xRiHV9zv S9FNTtN0jguyxxbtGSDDpXpxI3RSha7qvPZoWSdkhnzcyNxR9T5kCLULC/D7MlaoFK O2pHxE93gWm3KModYejT88yLR8R5ja9JGHzvqVQk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , Trond Myklebust Subject: [PATCH 5.15 063/913] SUNRPC: avoid race between mod_timer() and del_timer_sync() Date: Tue, 5 Apr 2022 09:18:45 +0200 Message-Id: <20220405070341.712316511@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: NeilBrown commit 3848e96edf4788f772d83990022fa7023a233d83 upstream. xprt_destory() claims XPRT_LOCKED and then calls del_timer_sync(). Both xprt_unlock_connect() and xprt_release() call ->release_xprt() which drops XPRT_LOCKED and *then* xprt_schedule_autodisconnect() which calls mod_timer(). This may result in mod_timer() being called *after* del_timer_sync(). When this happens, the timer may fire long after the xprt has been freed, and run_timer_softirq() will probably crash. The pairing of ->release_xprt() and xprt_schedule_autodisconnect() is always called under ->transport_lock. So if we take ->transport_lock to call del_timer_sync(), we can be sure that mod_timer() will run first (if it runs at all). Cc: stable@vger.kernel.org Signed-off-by: NeilBrown Signed-off-by: Trond Myklebust Signed-off-by: Greg Kroah-Hartman --- net/sunrpc/xprt.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -2111,7 +2111,14 @@ static void xprt_destroy(struct rpc_xprt */ wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_UNINTERRUPTIBLE); + /* + * xprt_schedule_autodisconnect() can run after XPRT_LOCKED + * is cleared. We use ->transport_lock to ensure the mod_timer() + * can only run *before* del_time_sync(), never after. + */ + spin_lock(&xprt->transport_lock); del_timer_sync(&xprt->timer); + spin_unlock(&xprt->transport_lock); /* * Destroy sockets etc from the system workqueue so they can