Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1862270rwb; Fri, 19 Aug 2022 10:37:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR7MAqBAxLyyBuIkco4a41bCMlZxrSPiVZm4oF1vpJOZeix1NDRukiWFCcKWv/EHQahAwPmD X-Received: by 2002:a17:90a:a406:b0:1fa:da13:549e with SMTP id y6-20020a17090aa40600b001fada13549emr5926738pjp.182.1660930628852; Fri, 19 Aug 2022 10:37:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930628; cv=none; d=google.com; s=arc-20160816; b=NZINN1qn1qqFBItSbNbrH9Xyuf53687qAeZoh7tGhmgUxex4xYBSM2xmVObcV+NWID seSwyMMrwpW4ULEkSzDYGem38gH4YuGLuDhIvPzshDBjAoTKk4ITAP2P2zfyzuG2GNhn E11vPNHTo0GSAGQdE6h5fSbhN1HEk7U9drqYzY06HRTfaCIxQ17yZiYguklmv60pHC57 C6OH0h7OcJfDCd4Rzt3DPHGgvvpJaDWeWoXNYK+t5nP/fFleDpe/ONFIBjcmK5I/N4R4 g/hqRA3tKKHt9Yp62xZsebEsaY9JjzPNY1FugpGQZAw7tzWnu89wugR3T6E3qSIqv9m0 UBPQ== 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=vzdvTIR8g1X9MEo8oxCGBjqa2Trh2RiM4mZid0rfYxU=; b=l+pDfUD7/Uct79HcZFmCcFs9kxN8HfI7cBed4sCx0tzPjC5So50VcUu8NqPwU5S4CO ijuU2ZbfMY5OL6C67GUYaFlblhWtirOv4Pak5KR3EXi3iX934TwXtBpKe4pxjHY1ZUzf /Ua+WhFHOqyaoNOgVjqVZ7te4Lh7AAPuOVVAcEAeRQVxVuSHsutq/8EQBpsO9JFsI6nG ZvB2rdtz37rnLJANeaSHo//QrHI4DCmAZuLXw9fbTwE5si4sCf6LepCsUuZbuXFwZDY8 LU0YENSa9KOU/QcyEN+6URkqP8BWvhuoXDMd7JyMWTiYVsdDW8NYFq1uWt+c2UuIbgWd 1EJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tqlS8XiW; 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 lp13-20020a17090b4a8d00b001f51df21ffasi7066211pjb.162.2022.08.19.10.36.56; Fri, 19 Aug 2022 10:37:08 -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=tqlS8XiW; 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 S1352674AbiHSQ05 (ORCPT + 99 others); Fri, 19 Aug 2022 12:26:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352165AbiHSQVT (ORCPT ); Fri, 19 Aug 2022 12:21:19 -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 79F94B728D; Fri, 19 Aug 2022 09:02:47 -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 37D3E614DA; Fri, 19 Aug 2022 16:02:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 408DAC433C1; Fri, 19 Aug 2022 16:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924965; bh=AWCP9M4pMoXHkzEm335nFo9facEPfSbGH8zo8pZEi/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tqlS8XiW8qCUJZ50V969jIw+isalrHDXw5Z7lEqcNw+Kw8FOPpEV0e/RgMHX6DXt7 2Yspda64TP4z9zRTQaB9u76KbyyvTh3P+4ywYY+U3bce3whFo2ZNeNnK/CttqZ+VEo ZzBlc8sVct2+39lq+XXasp2r9UQ+2N6bBPgZpzNY= 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.10 339/545] RDMA/hfi1: fix potential memory leak in setup_base_ctxt() Date: Fri, 19 Aug 2022 17:41:49 +0200 Message-Id: <20220819153844.562898276@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 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 cfc2110fc38a..d84b1098762c 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -1220,8 +1220,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