Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3021411rwb; Mon, 15 Aug 2022 16:18:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR4rfQZ4pIVMQnWUBygVGU4+xSb2Pa5vEy9y1COGvUi/ojSmAtS1Y5dRLC56rLd8KF9k0Sng X-Received: by 2002:a17:907:3e21:b0:730:92bb:7fcd with SMTP id hp33-20020a1709073e2100b0073092bb7fcdmr11780828ejc.170.1660605522801; Mon, 15 Aug 2022 16:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605522; cv=none; d=google.com; s=arc-20160816; b=nOAJT2ZGcqVbI7NrOXoPRnh9InRZOMf3ndhUh1RAExAt0ta6SHhx5KC2E++YbvIJI3 gPuZwGE4AhjaMkY4Hy1UYmrPQVPz4RbaHmSoZ8/AsnGQjdATcIrhv2dHQnkKooeQqdTV wfjjUhyQwHv/QKdm04JhLOlINfSdnJeqp3Ero9Jq8zq6ipJF0N4qyhs5qGnKpam8MwyS QoJ+0XgBAeAYjlG/kK+F7osvQGjhQVjA4BF3wcj8jwEIMS+XS2O4SEYmsjNsDC5LRieG n181j4WKpukxpyrijYZiP/mQZxNwN/29hPDWzm6dP4EgNamjp9n1zON7iuZ3juBdQMW9 XNiA== 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=6HK3YhA487V53x0IU9dM+3L5Zb20WyuAzrZWg6uNRok=; b=o0mdkQ33DgB5hZv/4tOVpcM7iK46dzEJ6Q3wOfLuVvCJWZ8UhRLRhZ9mjLzSvpTGPr fK+3Qa7U7b5MU8sdIQcfRgm83EiayIJXNrCj5DMjRozq9UHEqVS9YffjXGKZDdCDw/Kb JQo1GC0H7/NK+oCmucuVgCPrvaxXj8NebGUxgfusksmbxA3YzVblmXuDxiFVI3EdVlnM xe4EHECOytvRlyzPujrLCOiyWu5JMAMkkxGBVC1N5r6fbgNaIOtO7U7oydcAjVQUpBHG 0xwHfS0LfOQgSckFTU49FqZC0HYQOJ/7sEtKIW9S3k7LyolSBhH0Gc3039uKmFDitOkf DjOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RDOIxJDA; 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 g10-20020a056402424a00b0043d7f3e0aa7si10169648edb.26.2022.08.15.16.18.17; Mon, 15 Aug 2022 16:18:42 -0700 (PDT) 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=RDOIxJDA; 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 S1347288AbiHOWNG (ORCPT + 99 others); Mon, 15 Aug 2022 18:13:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348736AbiHOWLQ (ORCPT ); Mon, 15 Aug 2022 18:11:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C1CA11B4D6; Mon, 15 Aug 2022 12:38:39 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A8B76611E0; Mon, 15 Aug 2022 19:38:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C8A2C433D6; Mon, 15 Aug 2022 19:38:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592316; bh=5tpxLOFXVMmaWe+/GofZvF/HThOKUCePbpZoDQOPHrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RDOIxJDAbCjUG51LQzIZ6OSJuuDNDHHZjGajBmfDWXfVV7NkJaEUeMUh5FnFNYZTz QLVo5PBGKpnrJRYOFMEo34BTFwhkkrVlp3oBZGwmvNUgEPvgwf+tno/0zefcx7nKGM XCsM/28trTZj+HIqf6W2TA9ZJVrZ3yt+DvQVC6uA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianglei Nie , =?UTF-8?q?Michal=20Kalderon=C2=A0?= , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.18 0769/1095] RDMA/qedr: Fix potential memory leak in __qedr_alloc_mr() Date: Mon, 15 Aug 2022 20:02:48 +0200 Message-Id: <20220815180501.063037088@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: Jianglei Nie [ Upstream commit b3236a64ddd125a455ef5b5316c1b9051b732974 ] __qedr_alloc_mr() allocates a memory chunk for "mr->info.pbl_table" with init_mr_info(). When rdma_alloc_tid() and rdma_register_tid() fail, "mr" is released while "mr->info.pbl_table" is not released, which will lead to a memory leak. We should release the "mr->info.pbl_table" with qedr_free_pbl() when error occurs to fix the memory leak. Fixes: e0290cce6ac0 ("qedr: Add support for memory registeration verbs") Link: https://lore.kernel.org/r/20220714061505.2342759-1-niejianglei2021@163.com Signed-off-by: Jianglei Nie Acked-by: Michal KalderonĀ  Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/hw/qedr/verbs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/qedr/verbs.c b/drivers/infiniband/hw/qedr/verbs.c index df4d7970c1ad..cc99b293f0be 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -3083,7 +3083,7 @@ static struct qedr_mr *__qedr_alloc_mr(struct ib_pd *ibpd, else DP_ERR(dev, "roce alloc tid returned error %d\n", rc); - goto err0; + goto err1; } /* Index only, 18 bit long, lkey = itid << 8 | key */ @@ -3107,7 +3107,7 @@ static struct qedr_mr *__qedr_alloc_mr(struct ib_pd *ibpd, rc = dev->ops->rdma_register_tid(dev->rdma_ctx, &mr->hw_mr); if (rc) { DP_ERR(dev, "roce register tid returned an error %d\n", rc); - goto err1; + goto err2; } mr->ibmr.lkey = mr->hw_mr.itid << 8 | mr->hw_mr.key; @@ -3116,8 +3116,10 @@ static struct qedr_mr *__qedr_alloc_mr(struct ib_pd *ibpd, DP_DEBUG(dev, QEDR_MSG_MR, "alloc frmr: %x\n", mr->ibmr.lkey); return mr; -err1: +err2: dev->ops->rdma_free_tid(dev->rdma_ctx, mr->hw_mr.itid); +err1: + qedr_free_pbl(dev, &mr->info.pbl_info, mr->info.pbl_table); err0: kfree(mr); return ERR_PTR(rc); -- 2.35.1