Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3091834rwb; Mon, 15 Aug 2022 17:55:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR4B4Tw7392l8m5C4JiWCl65RXhGdASlqOjJU9aGnEgtZaCkMgp0JRESVFzaLVhOIt6mc4xh X-Received: by 2002:aa7:d8c6:0:b0:43d:b0a1:5266 with SMTP id k6-20020aa7d8c6000000b0043db0a15266mr16340400eds.164.1660611349710; Mon, 15 Aug 2022 17:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611349; cv=none; d=google.com; s=arc-20160816; b=a7vzLTy6Xv6jG7C3aiWiEJpXijwUV+d12gmmX1uEATybtlgDO7U3s7EqN5049Ad+sA 0SBvQmuIPZBic6RTVp+8KXDflI8xPynXMay228l2CU12xGXrn9yD6IFgH6YIpMWIA/oQ tRq6QiGRX3K9osO3J51ruEN520SEt2Jr+kWJDavkNax/1aRduz28rZ8lcCDVlc2IyIRJ 6OgohOE7WIRL53/5ObFSeCrEUUPynzPiNhqsyGHtpWpnxKVzPf0kDFhr7qj9v+0sydvS 7azz4BzWg1/QKN1wI9k8uH4yOQ/GLiolhdRBgxAVEpE0Ua5SL5jzyUvoymLMnBZNF6qB RxNw== 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=fLv8uqznmfuhfDuIM0PPUz1inM0bnsy+5UpGSv/yiIs=; b=uL3CEry+G0XbVbmh4aSC4h2vDBO8caSabbYrVIzw9hOTXry3/hrA3AvFwBAgPU5fxp v503JzA+lYesDIDpAzHwNRhQFwLGoElCQdSwsyg/WH2mirG5uyHqY3rBEdpMK+r/xHR6 GfBFWh7Uq54WoQwLZeC/qde7b980P74CkCRFKl6gFm07xFyf5lFLHIkGhH4Xa3+zGAPY 8Kb4gMOSRyWwb70sse0obuEBW7kgDVWjzdD/LJcO9gST9gwTVATK4epFyZD9369fSGvt 6ycjsQPOhsJmVY53ETeAae7Wh6zrb7osxJY+bkFFw6pPFGKlGOG+rsSxRsuprh2jX0vm uHGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C3Bq+vJD; 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 he7-20020a1709073d8700b00731217905f6si9487730ejc.923.2022.08.15.17.55.24; Mon, 15 Aug 2022 17:55:49 -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=C3Bq+vJD; 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 S1344656AbiHPAdi (ORCPT + 99 others); Mon, 15 Aug 2022 20:33:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353034AbiHPAbH (ORCPT ); Mon, 15 Aug 2022 20:31:07 -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 466A71859A1; Mon, 15 Aug 2022 13:36:05 -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 86AC1B8113E; Mon, 15 Aug 2022 20:36:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6312C433D6; Mon, 15 Aug 2022 20:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595759; bh=95XFJWskYR5c35UCiLc3szUERpmzKhUaat+774PWgg4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C3Bq+vJDNoAD7lz/ZfNCev3eHHKtStrlgZM8+Mdf5KOXyg28b8zujrs8qTJxElQqa 0AkT7bz1Tlx8EEhRPsDh2rFTQN76S9rkMIMrao5YfGRlWR5VwrpNi9rxtdV5mb42jB rrDx4u/J3jYRTHgOeSa1SiFwLQ3GbaJfhcHnCJSg= 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.19 0833/1157] RDMA/hfi1: fix potential memory leak in setup_base_ctxt() Date: Mon, 15 Aug 2022 20:03:09 +0200 Message-Id: <20220815180512.801120794@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 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 completely initialized") Link: https://lore.kernel.org/r/20220711070718.2318320-1-niejianglei2021@163.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 2e4cf2b11653..629beff053ad 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; ret = init_user_ctxt(fd, uctxt); - if (ret) + if (ret) { + hfi1_free_ctxt_rcv_groups(uctxt); goto done; + } user_init(uctxt); -- 2.35.1