From patchwork Tue Apr 26 08:20:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 567848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E35FC433FE for ; Tue, 26 Apr 2022 09:00:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346361AbiDZJDX (ORCPT ); Tue, 26 Apr 2022 05:03:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345636AbiDZJBz (ORCPT ); Tue, 26 Apr 2022 05:01:55 -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 7CEE68C7FE; Tue, 26 Apr 2022 01:43:37 -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 30572B81CFE; Tue, 26 Apr 2022 08:43:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 965B4C385AE; Tue, 26 Apr 2022 08:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962614; bh=SUAn3YB/j5PTGxSFVHNsRKIXtZlnRLSnEars9wTl8II=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TfL42/A6w/Ue/mF5GB7cZp/gZKolDpCK4F4VMovQUcplyoCSga1VQENwxGZE/s7zx Y4mnFf4piLAgfA7fNqPQaK9n9XA/L+wzQdvLN9knP99kklRt2jJIOkkmUzNqPsCNQn vtt+XkH4JAU3bMA352ZDCQlKlStut8cwnM7Zx6XY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tony Lu , Karsten Graul , "David S. Miller" , Sasha Levin , syzbot+6e29a053eb165bd50de5@syzkaller.appspotmail.com Subject: [PATCH 5.17 032/146] net/smc: Fix sock leak when release after smc_shutdown() Date: Tue, 26 Apr 2022 10:20:27 +0200 Message-Id: <20220426081750.970138852@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081750.051179617@linuxfoundation.org> References: <20220426081750.051179617@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Tony Lu [ Upstream commit 1a74e99323746353bba11562a2f2d0aa8102f402 ] Since commit e5d5aadcf3cd ("net/smc: fix sk_refcnt underflow on linkdown and fallback"), for a fallback connection, __smc_release() does not call sock_put() if its state is already SMC_CLOSED. When calling smc_shutdown() after falling back, its state is set to SMC_CLOSED but does not call sock_put(), so this patch calls it. Reported-and-tested-by: syzbot+6e29a053eb165bd50de5@syzkaller.appspotmail.com Fixes: e5d5aadcf3cd ("net/smc: fix sk_refcnt underflow on linkdown and fallback") Signed-off-by: Tony Lu Acked-by: Karsten Graul Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/smc/af_smc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 303c5e56e4df..68cd110722a4 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -2538,8 +2538,10 @@ static int smc_shutdown(struct socket *sock, int how) if (smc->use_fallback) { rc = kernel_sock_shutdown(smc->clcsock, how); sk->sk_shutdown = smc->clcsock->sk->sk_shutdown; - if (sk->sk_shutdown == SHUTDOWN_MASK) + if (sk->sk_shutdown == SHUTDOWN_MASK) { sk->sk_state = SMC_CLOSED; + sock_put(sk); + } goto out; } switch (how) {