Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1673394pxb; Thu, 16 Sep 2021 12:36:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIftMKo4HIA8Q193hKlUE5PR9B+gpR+GghfRZfp7yAdtGG9R9AbaZoEK/ggYLudL1bVph6 X-Received: by 2002:a50:ee82:: with SMTP id f2mr8237087edr.15.1631820991634; Thu, 16 Sep 2021 12:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631820991; cv=none; d=google.com; s=arc-20160816; b=pxb0aMd2Mm5Xsqysv+mPBqcKCf8ETAX5Scb30El9vliqtpQqAiGOclh4UWDRQ+L9ab YdzCa/k1ZP/Ne+tqN82GLp7SDimvmfCqXUjDkG7uwGl02FPov4QhSYmIKx05MlaOKYV6 oseCngzbTJoWMGK3PyrFh3Ur95aAA/T+VkW3TBlpCzXd/pEu6gNIxobsfSr4Nt/dN555 YzleuVzf3WXTAMecyeuPGAfxbO+QBYx+7MiAaOyM7bPZkGlp5XQXl6GnG5qVQoNPIEyF 8vLz/n4cfVsbpvS74pjL0invIn+UWRq5nRcIH5m0ELpwpnavhh4xLNjJk4D49ha+fQy6 4ypQ== 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=DgVHP0Vcsrmq7N3ZsP70kBx7PMt1rzrY444cVE9ot6E=; b=unoz5pc7qgAqR7ncj7rR3AqTumcC/vWCE/bMmjKw8bfCZ7sngfbU1sq8XIrm4w5WiW ooLpFMLEZQcPDRRqcuy7iujP+0HVskS+xYoNzwUZ2Q9QU3bkZoVGj7bl6s9ByMyzOQQk xy8WxGL8/F+gC+/pW1D6X0XUlL+k+N7kwP/fA9lcXqL3kk3N4HthTkOGI62kUnRixTfH tlJfOFW9pwkeyDg8wWXuMu/UMSvotdnsPMOg6CIi4mRnxC8M1TioUMlJMcmuMhdsQSDB 9gUxyYNeOnlvGAxrjYGvRe7xAVE5+5Xv4xxNVxbWTRAVYxuWYnjkWEnzG/bKmf/NShZh wi9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ONuCK0ZM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r5si4639922edy.450.2021.09.16.12.36.07; Thu, 16 Sep 2021 12:36:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ONuCK0ZM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S241089AbhIPQPK (ORCPT + 99 others); Thu, 16 Sep 2021 12:15:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:47416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234413AbhIPQIA (ORCPT ); Thu, 16 Sep 2021 12:08:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 600EE611F2; Thu, 16 Sep 2021 16:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808400; bh=w40nHKlwfktxdo7bfB8EF2NShgTfGDqxiqB+0MZR0iQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ONuCK0ZMn2HuoztCchtSTdoVYcbV786UAXdXIz9B0v8bzkRAgJCNXt7mbUFe5p4Zq 2B2gfbbTzjKXZEqqjKl7MFxzsPnGlVeQ7HG0+W2FgJdKev0QNV4ASRmyCfDciiRXD2 8bmjkdCugpKye+Vv4YEiA0cIgWDUHIl2wB5I3yS8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , Anna Schumaker , Sasha Levin Subject: [PATCH 5.10 078/306] SUNRPC: Fix potential memory corruption Date: Thu, 16 Sep 2021 17:57:03 +0200 Message-Id: <20210916155756.716861334@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Trond Myklebust [ Upstream commit c2dc3e5fad13aca5d7bdf4bcb52b1a1d707c8555 ] We really should not call rpc_wake_up_queued_task_set_status() with xprt->snd_task as an argument unless we are certain that is actually an rpc_task. Fixes: 0445f92c5d53 ("SUNRPC: Fix disconnection races") Signed-off-by: Trond Myklebust Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- include/linux/sunrpc/xprt.h | 1 + net/sunrpc/xprt.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h index cad1fa2b6baa..e7b997d6f031 100644 --- a/include/linux/sunrpc/xprt.h +++ b/include/linux/sunrpc/xprt.h @@ -421,6 +421,7 @@ void xprt_unlock_connect(struct rpc_xprt *, void *); #define XPRT_CONGESTED (9) #define XPRT_CWND_WAIT (10) #define XPRT_WRITE_SPACE (11) +#define XPRT_SND_IS_COOKIE (12) static inline void xprt_set_connected(struct rpc_xprt *xprt) { diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 9a50764be916..ccfa85e995fd 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -746,9 +746,9 @@ void xprt_force_disconnect(struct rpc_xprt *xprt) /* Try to schedule an autoclose RPC call */ if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) queue_work(xprtiod_workqueue, &xprt->task_cleanup); - else if (xprt->snd_task) + else if (xprt->snd_task && !test_bit(XPRT_SND_IS_COOKIE, &xprt->state)) rpc_wake_up_queued_task_set_status(&xprt->pending, - xprt->snd_task, -ENOTCONN); + xprt->snd_task, -ENOTCONN); spin_unlock(&xprt->transport_lock); } EXPORT_SYMBOL_GPL(xprt_force_disconnect); @@ -837,6 +837,7 @@ bool xprt_lock_connect(struct rpc_xprt *xprt, goto out; if (xprt->snd_task != task) goto out; + set_bit(XPRT_SND_IS_COOKIE, &xprt->state); xprt->snd_task = cookie; ret = true; out: @@ -852,6 +853,7 @@ void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie) if (!test_bit(XPRT_LOCKED, &xprt->state)) goto out; xprt->snd_task =NULL; + clear_bit(XPRT_SND_IS_COOKIE, &xprt->state); xprt->ops->release_xprt(xprt, NULL); xprt_schedule_autodisconnect(xprt); out: -- 2.30.2