Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1798527pxp; Mon, 7 Mar 2022 02:36:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZ9at5xJN8UJt3c2D83NPYX9rRxarI2m+5DwKxWYP2tkn9CDDajfCGbM5kSco69zSny9En X-Received: by 2002:a05:6a00:1a11:b0:4f6:cff3:dc07 with SMTP id g17-20020a056a001a1100b004f6cff3dc07mr12054766pfv.70.1646649362001; Mon, 07 Mar 2022 02:36:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646649361; cv=none; d=google.com; s=arc-20160816; b=GawsrbrfXc6q0rvDGpTgXd1QsfPqW7CicrOwCr9Iwp4Yn6niLd0tfenuzxDMF/zq4a fjtaoS1V0j5NVf30LPUb8mPG88GCuXUukRGObNa0UcQlmHVLwBHGiEvRcvlaOI1Fbr2t 46ghmKb/5erV+g3NwdHv0zkhB4rNvD+YhLrBcPwtM3mAx0MYF7JnDfxLUJzSkKxgHg0L T+ECWR+B2DUjnpJJQaxZN59RjP2Hzf9DlJJib5Qg2RnOz/QPnItadZdJb5hujeV0nR0v hbaCchUOXWnYZw17rfOC/Sfy+tjVHM3kspLIECMync9VG44oxyImo6goYzVsuTgacyzg KQkw== 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=4WA8pjb/qg40IwRwIGM1qcih0nXNrv8NxDaZIQ4gXk0=; b=eEqVhiUX9AUeyt/2TTe+rJDYsLGI77EcwF4t6SIlQP+bFWOAira8DGPLqxYR91oDwZ bfUNWbTacRGk/FhXPgCgFOzJe+WIBK0Usfd9X7H9MA9bwFXUvH1jx/QARBDFXnyvqb5p FG3CXQcWo/NKSAc5eyQNK1tZVlRAltH+n13cYrINJ49wP4S35yQvmrYzG9vnDF3l6/fo PtuLCxL0eYCYtxiAw/FX/4oE8Ud3CqE17vCDXkSRwrNCbkr76n77Fm1Ze70zenqAvKJ4 76+ZUzvhEguXlewJwPFn4tU/13Nc29s1zQJxDArEebuLCxfI4rw0ElLi4wBGYwdbjXAq g5HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HMLlodOv; 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 d20-20020a056a0010d400b004e180528b34si12334983pfu.143.2022.03.07.02.35.47; Mon, 07 Mar 2022 02:36:01 -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=HMLlodOv; 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 S240740AbiCGKIl (ORCPT + 99 others); Mon, 7 Mar 2022 05:08:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239670AbiCGJuB (ORCPT ); Mon, 7 Mar 2022 04:50:01 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B805710DF; Mon, 7 Mar 2022 01:43:38 -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 ams.source.kernel.org (Postfix) with ESMTPS id E49BFB810BC; Mon, 7 Mar 2022 09:43:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 260CDC340E9; Mon, 7 Mar 2022 09:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646646216; bh=xNBSLegiMNsww5M/MQqDExxz79QvamxtTPQDiZrclWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HMLlodOvS335WtdtSmSDhMMX9OoU9JC21AMSTpaFP00l7yC3kQqtGkZq23WmkF0Hx tSx4BErlSTX75Kp2GFLxdKEpIUeooKVMhTTnAO8KMxW+bRUsfcKV6MG9wwc5cJSdzE nbCqhs7vEeY3NJi4bkU2ufhWxwtEf4fFDuCmnRps= 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.15 169/262] net/smc: fix connection leak Date: Mon, 7 Mar 2022 10:18:33 +0100 Message-Id: <20220307091707.195678290@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091702.378509770@linuxfoundation.org> References: <20220307091702.378509770@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 @@ -182,7 +182,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; @@ -190,8 +190,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)) @@ -205,6 +207,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 */