From nobody Sun Dec 14 06:16:10 2025 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 D472BC00140 for ; Mon, 15 Aug 2022 19:23:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242118AbiHOTXH (ORCPT ); Mon, 15 Aug 2022 15:23:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241010AbiHOTTp (ORCPT ); Mon, 15 Aug 2022 15:19:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07D6E58B5D; Mon, 15 Aug 2022 11:39:55 -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 DC54C61120; Mon, 15 Aug 2022 18:39:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC836C433C1; Mon, 15 Aug 2022 18:39:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588794; bh=NnNp7DWWOboATNhkynY0ZdcfWWZJZrnmvFmpd0g1rf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xDjWHVe3WABOublAsqbMQnnPBrk//L2ECQ5TLhA07jqz8h/8/IrIXC+qFuduO+FUQ u4Zwzp9iGFcOk9Z4mGP26wtBRW9MsG1V1oFJL3oEYMvXc8bl2J9vZBuCcBUmTEOaIF AuI7y6Oj27nrMyvSipaDo1CE1DqB0iX5dLDRFXMM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianglei Nie , Dennis Dalessandro , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.15 516/779] RDMA/hfi1: fix potential memory leak in setup_base_ctxt() Date: Mon, 15 Aug 2022 20:02:40 +0200 Message-Id: <20220815180359.314220466@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jianglei Nie [ Upstream commit aa2a1df3a2c85f855af7d54466ac10bd48645d63 ] setup_base_ctxt() allocates a memory chunk for uctxt->groups with hfi1_alloc_ctxt_rcv_groups(). When init_user_ctxt() fails, uctxt->groups is not released, which will lead to a memory leak. We should release the uctxt->groups with hfi1_free_ctxt_rcv_groups() when init_user_ctxt() fails. Fixes: e87473bc1b6c ("IB/hfi1: Only set fd pointer when base context is com= pletely initialized") Link: https://lore.kernel.org/r/20220711070718.2318320-1-niejianglei2021@16= 3.com Signed-off-by: Jianglei Nie Acked-by: Dennis Dalessandro Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hfi1/file_ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/= hfi1/file_ops.c index 3ebdd42fec36..686d170a5947 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -1179,8 +1179,10 @@ static int setup_base_ctxt(struct hfi1_filedata *fd, goto done; =20 ret =3D init_user_ctxt(fd, uctxt); - if (ret) + if (ret) { + hfi1_free_ctxt_rcv_groups(uctxt); goto done; + } =20 user_init(uctxt); =20 --=20 2.35.1