Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1855471rwb; Fri, 19 Aug 2022 10:30:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR4uNggZMNog0xdqsQexqD21a9L7IXqIYVaWrsj30XJ8zFxz3ARWaZ+X/ven/ihsZ8CEeuwI X-Received: by 2002:a63:4a08:0:b0:428:d6ca:5a99 with SMTP id x8-20020a634a08000000b00428d6ca5a99mr7316886pga.98.1660930215860; Fri, 19 Aug 2022 10:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930215; cv=none; d=google.com; s=arc-20160816; b=MPSsHdcl17fGv7AP/v/3wCd3pcRf/iARhLb9ryNnuR53NC9BJK9qdSskCKhqZQLMrm cyBgVJHvunyN0pzvQcerm9EpJ7P8uDonnYJPAYb/3rq7qx8JIll0LA5NRsktCc4+seQo RDexTuLpJ39DvPH6to8+kgq6gt7pmQbl49LiAXoS+5J91giPUtlw5K828J6zQdeeWo1E qoT69AQX23SJfrKQynDd1s1quWAboNITHDrgyOqaLTYKtCwxbLHFRn+Qpjvf9+O9z70l SSL5dSD7/HYbRZ0nPg55+nI0icOHbPJjevOgnLqCiNm/Mqay4ttfzLFeCONjfGfwrv9T msQg== 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=X/US9Id0UmY+9Db2wPvigQ2IX/gcgnVp+o1K/FzR5Zk=; b=Ra6iuPbn+nBkpOKfixSH0Ds+CfvSz/jWe/62ZuzDbhdnh9nEq5htwNxRHryI6FL3/+ b31Pzp4b5Ay3xf4bP3cOGOkMq6r9Tm4yrIRw4RlbOIHlFrPP8m8rQt7eIXh7pcW7yd4D Qu5I/gtJphpaStq1PeM9U/OmSmFQ5FbKcY0zr4OYJRwMXF2VLa1MJusaHKU7jddlGQNi 8IdIu6oLX0dy4bqlNlUUuYffaiJIFPW/mWE4w85/v+uAuoUKaZmoppfP8V09lxBaPJaD gHajR/PJGhEWCloXyomEaqjmdPiAWWjCTXuVJxhuqnE9qC7/iNSfe0gbKnqJaN++Gk1F CBbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oo8v68L9; 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 d5-20020a170903230500b00172ccb3f4eesi427600plh.113.2022.08.19.10.30.03; Fri, 19 Aug 2022 10:30:15 -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=oo8v68L9; 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 S1352496AbiHSQ0h (ORCPT + 99 others); Fri, 19 Aug 2022 12:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352498AbiHSQVH (ORCPT ); Fri, 19 Aug 2022 12:21:07 -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 17E6010FDA; Fri, 19 Aug 2022 09:02: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 dfw.source.kernel.org (Postfix) with ESMTPS id 404B5617A5; Fri, 19 Aug 2022 16:02:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54AF1C433D6; Fri, 19 Aug 2022 16:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924956; bh=L88j/vM4soCdE7vM4SQBpzrBszT1ntIHSWMlGAgHENk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oo8v68L9ozZrEu1BD0B7/sx8a4gZqEFkj7x55C4YCcHdvoiJP607j7FnbXaZ5CVyI PE2yx0Dm2A33DNptW6B0IXF+me4dtL3mTh+5D5eZiyLDWZ5I/saJkmo454+0sKx4Ew WF/M5Fvp3Y9efkQ6YWlPabCGsW4VfWr6qXiXa/cw= 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.10 336/545] RDMA/qedr: Fix potential memory leak in __qedr_alloc_mr() Date: Fri, 19 Aug 2022 17:41:46 +0200 Message-Id: <20220819153844.429343080@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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 bffacb47ea0e..3543b9af10b7 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -3093,7 +3093,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 */ @@ -3117,7 +3117,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; @@ -3126,8 +3126,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