Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1790307pxp; Mon, 7 Mar 2022 02:23:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7pPJGnieYNeFIGWzfyHcr7ko7OftAZFVjSB+40rxdL0pSg3YgJlDicbSUF1XytDyV/jf5 X-Received: by 2002:a63:d64c:0:b0:374:8aff:a293 with SMTP id d12-20020a63d64c000000b003748affa293mr9372802pgj.388.1646648587711; Mon, 07 Mar 2022 02:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646648587; cv=none; d=google.com; s=arc-20160816; b=OjeT4ZWZYbjKJQ9p7gtHGNPflMtgpyrIogGvo7pGHOLOfjxWW5sm1idCE2byFortBD 4//3KwxC/XuTlVFTK7YhtTCS/VTQJIbyili7JhXdgT25CkdvsPEa6y4EyKDd7Gi40xar ko0siLMbPWe2/cIKL/FoPyBG8Fh0639CrCM4O/eUr9SbCs8dgbDgfNuYhgoa8rT/zLrK dkRglmTiSWrVrmDBDMlKSigI3+ho9WPYuFctFxGi+4neFBkyCNw0gaofHp4eJB6l+o6B Hth441ZbaIGEs9GeMp+8fQyyKVNUwp5YXmolcbEJYs+FHfcJU2e7kjjQYLZ1/rlxbM7O DXRA== 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=ju3Lnso5H1WI2uVW7SjAsr5q8hNzYeSjow1TxvyunT4=; b=i9HkwnV4MitBozR4RorVIFsnygWQOcpM59/7oU+q+mcyY+9r9TSQqGB3n2GZKC+MZa DBSlNc0ztdjpMUvM85lWmP+MYHQoktpPIwc71VqTsbRYBC6haqKCvOs/GC9eLpWXkQ4B l0w5UyfRle+8QsEDJwKcS0U0P2h0pNvkw0PRmlsfmqfkLQeHlahdC03l/rnIXLkhNyH0 fXn0Dyy2X+Pn6t04yVTFRDPE074RGou8sIwhuw0hOWI2qTI9nwMi9P6Pvd7OtSKV/7kM lFG9wCZ4nOaP6A1eB46SYIS5GeNYj7qcQl2rgqG+HKO0xxZcmmrG/Sz+Xf0vfYZF1hC+ yBNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gH8V8gf9; 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 i62-20020a638741000000b003802ff3514esi3291546pge.275.2022.03.07.02.22.51; Mon, 07 Mar 2022 02:23:07 -0800 (PST) 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=gH8V8gf9; 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 S229456AbiCGJ4i (ORCPT + 99 others); Mon, 7 Mar 2022 04:56:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238334AbiCGJiR (ORCPT ); Mon, 7 Mar 2022 04:38:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B972AE4E; Mon, 7 Mar 2022 01:32:29 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 9A63261225; Mon, 7 Mar 2022 09:31:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F31DC340E9; Mon, 7 Mar 2022 09:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646645505; bh=XDc477/3beWxxSmCW2K4WGCl4Y/J3tDQ9d+epshTneI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gH8V8gf91saaT6YLF59aTh1LsNAN+Zz7jX0o9XxdCR6788evzcXJyzOWdqzVoSXIn Ro639+qdtVmbeNhEEkRr9hduqlscjXWeWNsysrd7ZqRly2pXNC4z4Lsq1nrRMBFbc/ SM2h4ce9FEy4Ahg5/AzrO56EL35V8eB8ov+W+Je8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "D. Wythe" , Karsten Graul , "David S. Miller" Subject: [PATCH 5.10 051/105] net/smc: fix connection leak Date: Mon, 7 Mar 2022 10:18:54 +0100 Message-Id: <20220307091645.619198431@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091644.179885033@linuxfoundation.org> References: <20220307091644.179885033@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.6 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: D. Wythe commit 9f1c50cf39167ff71dc5953a3234f3f6eeb8fcb5 upstream. There's a potential leak issue under following execution sequence : smc_release smc_connect_work if (sk->sk_state == SMC_INIT) send_clc_confirim tcp_abort(); ... sk.sk_state = SMC_ACTIVE smc_close_active switch(sk->sk_state) { ... case SMC_ACTIVE: smc_close_final() // then wait peer closed Unfortunately, tcp_abort() may discard CLC CONFIRM messages that are still in the tcp send buffer, in which case our connection token cannot be delivered to the server side, which means that we cannot get a passive close message at all. Therefore, it is impossible for the to be disconnected at all. This patch tries a very simple way to avoid this issue, once the state has changed to SMC_ACTIVE after tcp_abort(), we can actively abort the smc connection, considering that the state is SMC_INIT before tcp_abort(), abandoning the complete disconnection process should not cause too much problem. In fact, this problem may exist as long as the CLC CONFIRM message is not received by the server. Whether a timer should be added after smc_close_final() needs to be discussed in the future. But even so, this patch provides a faster release for connection in above case, it should also be valuable. Fixes: 39f41f367b08 ("net/smc: common release code for non-accepted sockets") Signed-off-by: D. Wythe Acked-by: Karsten Graul Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/smc/af_smc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -180,7 +180,7 @@ static int smc_release(struct socket *so { struct sock *sk = sock->sk; struct smc_sock *smc; - int rc = 0; + int old_state, rc = 0; if (!sk) goto out; @@ -188,8 +188,10 @@ static int smc_release(struct socket *so sock_hold(sk); /* sock_put below */ smc = smc_sk(sk); + old_state = sk->sk_state; + /* cleanup for a dangling non-blocking connect */ - if (smc->connect_nonblock && sk->sk_state == SMC_INIT) + if (smc->connect_nonblock && old_state == SMC_INIT) tcp_abort(smc->clcsock->sk, ECONNABORTED); if (cancel_work_sync(&smc->connect_work)) @@ -203,6 +205,10 @@ static int smc_release(struct socket *so else lock_sock(sk); + if (old_state == SMC_INIT && sk->sk_state == SMC_ACTIVE && + !smc->use_fallback) + smc_close_active_abort(smc); + rc = __smc_release(smc); /* detach socket */