Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2195992iof; Tue, 7 Jun 2022 22:53:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJya75dbow+iUkB7HUdBXReBLeepqyGoTMRYDDo2UX9OBHr/HVBiei24byBsnaxm7QFIzHzF X-Received: by 2002:a17:903:40c9:b0:167:5411:3536 with SMTP id t9-20020a17090340c900b0016754113536mr23382791pld.2.1654667583182; Tue, 07 Jun 2022 22:53:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667583; cv=none; d=google.com; s=arc-20160816; b=eROlqE/7FdTxZ2/egRzzFQpalRhXZO8VMZolGBieLRJjgxG7hrTfd89WLXA+LI+F4J SOZDHvYqcDtegJu1otgr6HbV5Nz/8QoBo3Lp2twhjr6F3rdGPB4YLnm7dz/MPsilJEDX wblzDTZDaJc+WeWHMX79XoAFY9H7JHYvWSajQ+nXMKdBr1ouAOo5wJ3UHHLcy35SdiiC KvAxnE8fNA8+P63zWklxddColkgQQWVpo/NhHunucTNGiAirswLmXdF5XrSQxSEb/Rfo hXlTmOzZ13TKyF8Q+OBwdrkOEYbDnk1FQGk9Zb8UfXLnE2j7IBZU1NoAWfwltAgkk7dX ABHg== 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=I1CpqKiSFNUXjEDxQ3htIDPadtWGw3JP+VxHHK1toNg=; b=ZBx7defBcU91aBkecIzaY39ORiptmP0hmuGWcC3h4J73Dcb+vy1y0loXCPliBzmA5E jwvpd7W98+Vu/4A9asQRzsfD7k5yvMCe4kWJqakXbdP4blnBDyztx0lgLdNCjfAhnAVW kJh/zC+6pwfm9E0SsXe/6FolKVIK6uIKoQgRvw62tE9z08kVddmln4K+Hsi3Q7Ff8oyH Mp2/CwyT0LDiJDSI1RCSVRZKcr3W1MPN3RIOooOC2IOykB9CzVo4RZwooTW3Sl6qr5EJ 9d4AtK+KTsXpXnsaHdx1aS6dy148iRFataRmI2hQv0bmqTIMIWacvM4BZ3j12/QljaUN Y6Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fILzc6lA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id w2-20020a170902d70200b00163868019a3si25375563ply.360.2022.06.07.22.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:53:03 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fILzc6lA; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 72EA34AEEA9; Tue, 7 Jun 2022 22:21:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390954AbiFHAgo (ORCPT + 99 others); Tue, 7 Jun 2022 20:36:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382847AbiFGVwA (ORCPT ); Tue, 7 Jun 2022 17:52:00 -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 22B2223F210; Tue, 7 Jun 2022 12:09:50 -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 41813B823AF; Tue, 7 Jun 2022 19:09:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 818B9C385A2; Tue, 7 Jun 2022 19:09:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628987; bh=Cx5pCWFJuQHqiRJtmJve7topnEAglLRhBEONejVS2AY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fILzc6lAD2/sH1KJEYW1GFOdG4naxi5rJLhnLk/t8JPbQns4bDyxEP9kwGRTSZQb/ ca+IM8QaXQkwiV7ov5CJhsl+EknQ6H6K+W7URSZBzm9CbyhXBvrWC9nM3qfvjXMtxs Uo700CEbyxnxsApFllF3vtP7n8jYVPRZS3KjJdR0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, liuyacan , "David S. Miller" , Sasha Levin Subject: [PATCH 5.18 528/879] net/smc: fix listen processing for SMC-Rv2 Date: Tue, 7 Jun 2022 19:00:46 +0200 Message-Id: <20220607165018.201928914@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: liuyacan [ Upstream commit 8c3b8dc5cc9bf6d273ebe18b16e2d6882bcfb36d ] In the process of checking whether RDMAv2 is available, the current implementation first sets ini->smcrv2.ib_dev_v2, and then allocates smc buf desc, but the latter may fail. Unfortunately, the caller will only check the former. In this case, a NULL pointer reference will occur in smc_clc_send_confirm_accept() when accessing conn->rmb_desc. This patch does two things: 1. Use the return code to determine whether V2 is available. 2. If the return code is NODEV, continue to check whether V1 is available. Fixes: e49300a6bf62 ("net/smc: add listen processing for SMC-Rv2") Signed-off-by: liuyacan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/smc/af_smc.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 45a24d24210f..d3de54b70c05 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -2093,13 +2093,13 @@ static int smc_listen_rdma_reg(struct smc_sock *new_smc, bool local_first) return 0; } -static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc, - struct smc_clc_msg_proposal *pclc, - struct smc_init_info *ini) +static int smc_find_rdma_v2_device_serv(struct smc_sock *new_smc, + struct smc_clc_msg_proposal *pclc, + struct smc_init_info *ini) { struct smc_clc_v2_extension *smc_v2_ext; u8 smcr_version; - int rc; + int rc = 0; if (!(ini->smcr_version & SMC_V2) || !smcr_indicated(ini->smc_type_v2)) goto not_found; @@ -2117,26 +2117,31 @@ static void smc_find_rdma_v2_device_serv(struct smc_sock *new_smc, ini->smcrv2.saddr = new_smc->clcsock->sk->sk_rcv_saddr; ini->smcrv2.daddr = smc_ib_gid_to_ipv4(smc_v2_ext->roce); rc = smc_find_rdma_device(new_smc, ini); - if (rc) { - smc_find_ism_store_rc(rc, ini); + if (rc) goto not_found; - } + if (!ini->smcrv2.uses_gateway) memcpy(ini->smcrv2.nexthop_mac, pclc->lcl.mac, ETH_ALEN); smcr_version = ini->smcr_version; ini->smcr_version = SMC_V2; rc = smc_listen_rdma_init(new_smc, ini); - if (!rc) - rc = smc_listen_rdma_reg(new_smc, ini->first_contact_local); - if (!rc) - return; - ini->smcr_version = smcr_version; - smc_find_ism_store_rc(rc, ini); + if (rc) { + ini->smcr_version = smcr_version; + goto not_found; + } + rc = smc_listen_rdma_reg(new_smc, ini->first_contact_local); + if (rc) { + ini->smcr_version = smcr_version; + goto not_found; + } + return 0; not_found: + rc = rc ?: SMC_CLC_DECL_NOSMCDEV; ini->smcr_version &= ~SMC_V2; ini->check_smcrv2 = false; + return rc; } static int smc_find_rdma_v1_device_serv(struct smc_sock *new_smc, @@ -2169,6 +2174,7 @@ static int smc_listen_find_device(struct smc_sock *new_smc, struct smc_init_info *ini) { int prfx_rc; + int rc; /* check for ISM device matching V2 proposed device */ smc_find_ism_v2_device_serv(new_smc, pclc, ini); @@ -2196,14 +2202,18 @@ static int smc_listen_find_device(struct smc_sock *new_smc, return ini->rc ?: SMC_CLC_DECL_NOSMCDDEV; /* check if RDMA V2 is available */ - smc_find_rdma_v2_device_serv(new_smc, pclc, ini); - if (ini->smcrv2.ib_dev_v2) + rc = smc_find_rdma_v2_device_serv(new_smc, pclc, ini); + if (!rc) return 0; + /* skip V1 check if V2 is unavailable for non-Device reason */ + if (rc != SMC_CLC_DECL_NOSMCDEV && + rc != SMC_CLC_DECL_NOSMCRDEV && + rc != SMC_CLC_DECL_NOSMCDDEV) + return rc; + /* check if RDMA V1 is available */ if (!prfx_rc) { - int rc; - rc = smc_find_rdma_v1_device_serv(new_smc, pclc, ini); smc_find_ism_store_rc(rc, ini); return (!rc) ? 0 : ini->rc; -- 2.35.1