Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3089746rwb; Mon, 15 Aug 2022 17:52:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR5tk5JR+o5NyhGA/QYU3dVisr0yC73863hyWMOZIZ3X3/MuAvnGAEoQZZaz+TOHqsc6oRhv X-Received: by 2002:aa7:d5c8:0:b0:442:b0c5:1fba with SMTP id d8-20020aa7d5c8000000b00442b0c51fbamr16639060eds.237.1660611164165; Mon, 15 Aug 2022 17:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611164; cv=none; d=google.com; s=arc-20160816; b=lIqJio3dRTOpPX9/9sQtR7CRVRAp707NS+cnAuJHP1K5zHkxEywQI+gA7OJ5sdwmhx iOynfUl3+r9rShzU/HnOxJOR+dKkW2FR1G7/PMsZr10mVsXuGHUGamCE5TvFFSKE7+xI 476PyPzECDneZKSGV6ugA3G2bqXHdyI3F35UgcirRb1ENXzPhl1d1oSuu0n914gDT1P9 sX/9ZuQyNmOmrx3Uw2+lyGA/bUlpNNMNETPBKpHqtPgN0MqeWiEdnv4cGDSbAIhav7Nt cmZkZvi5q4Paj3UDeVkEEEmU7bPkwhcJdct9UF7LJBBBTk1VwunKFtleFg/jE+lM5t5N 1Y8g== 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=Kqe3APvhYynXuvAY4hdYcEA7jRo42Vs4iBQtRQ+wJh8=; b=qUsRvyK8431Iq0+MKD2HqLLwnpIDbcPFaxQtEucoYclN2Pl4oCXco/F2Io5+OdW5cd qhO30XZOg4uPjPkWqaOz8tbHS4ArGcTFrBQtST6fpgnGbYEr61+xrEtU6GCeW+K/zz/u N25UA6UybX34v5DsjiYRvYF1bMgq7HM03THwaxcVGyOWOwnE86rg+dAmXR6ZBAnr6qid 6AJMcZbmdeHf37SWYTF4sKoBJRCRZu1d+vBjw0n3KZb1LfL+KkogiA7v9jC/Y2KWBYwD QN8X515Sst7npiFgSHUZ9kbcNYlfkc1h5JEIxFs6FdRxeVyeePvDK2gNcmzJ8yV7dE41 c/RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MuUfSVuF; 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 b13-20020a056402350d00b0043e4a260ad8si10185836edd.563.2022.08.15.17.52.15; Mon, 15 Aug 2022 17:52:44 -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=MuUfSVuF; 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 S1347911AbiHPAZB (ORCPT + 99 others); Mon, 15 Aug 2022 20:25:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348929AbiHPAXA (ORCPT ); Mon, 15 Aug 2022 20:23:00 -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 719D517DAA3; Mon, 15 Aug 2022 13:34:10 -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 2B70E60EE9; Mon, 15 Aug 2022 20:33:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15A13C433D6; Mon, 15 Aug 2022 20:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595634; bh=b7HQ7HYv3Nl1NaFZpDeZ1AnQeVV75qbUAncsk6g7D+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MuUfSVuFIz3noToGz8EBWeQcZBlH8bRDjZPytF39RTzgLeUMDyGa3PHnBeO0+ovC5 Ml/aveIt36hCqKTTLXGzDQVZj/zSlk/iXyzF8MJ1fA0URnd43zVYEmY6UiHgjno5yo Dxtm5pFoowhCrofWb/aQqPJMOKAI0rvMCssH3nIc= 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.19 0825/1157] RDMA/qedr: Fix potential memory leak in __qedr_alloc_mr() Date: Mon, 15 Aug 2022 20:03:01 +0200 Message-Id: <20220815180512.491532380@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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 03ed7c0fae50..d745ce9dc88a 100644 --- a/drivers/infiniband/hw/qedr/verbs.c +++ b/drivers/infiniband/hw/qedr/verbs.c @@ -3084,7 +3084,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 */ @@ -3108,7 +3108,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; @@ -3117,8 +3117,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