Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3330220rwa; Tue, 23 Aug 2022 03:00:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR6gqsvhZW+MhCXWtE07R54K227cNGBcVRoZbtwhECe15IMHoE0e2QGCv0t1lSvnsoQISWBU X-Received: by 2002:a17:907:1de3:b0:73d:6369:fa00 with SMTP id og35-20020a1709071de300b0073d6369fa00mr9974574ejc.293.1661248819933; Tue, 23 Aug 2022 03:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248819; cv=none; d=google.com; s=arc-20160816; b=rySTAMQDbTRpOWoIL83WpTsyftGHE/i22K6Em9gEJA6KuiFmt71xlxX1Hq8+0XBgor BIGDFkHKAtRV00/uUs1NMXRVTKwxPzbFV5H70YC/UKBufXZDrPIWMCMxjeh1uhMoKcQ+ +MjpOltO3YemtoazQTpb0ouoceUXWN/YS89fRCG1qe47uG4z//GCpT2CC6UWAB3UJtDa 0X+pjaPSmHb//dTUNBpB8JFPmbFstaQdGyb6ARGqe1d2PVaJMdBC2QY94XMr5941bCjv sREMcApoq0igMbTA0bGdJJ8NelA96pb0Ybgcz5NblMJufYtxalr8Kn2G/j1N6Q65e8Yv qSrQ== 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=s47lkWUZSUi2Obo9J3EHcfcwcPRYq1ehm96M45/4fLg=; b=W5LLag420UcBvSwS9QdTi0vx3vW0TNgoR6rF1njSDY/oXpE6XkG6z0yHmrQy43OZM7 q9PMQDkwHdvuPWWyD0QWoR73xpQuI3fmOhGF7yFK+cFLuSh7Jc3x4suTHRPSApeATscB S+2tgXCvVNtZbj+PlaYf8bDMx52pmYpLDBMDeB87VrWjGBIRgdfsrpYx/8KzjQFnKV2v DzdEHVx5c/69co8G4x01gaoRLnTGAtdgcSpPCRBlty41yq63huqqYR+4BHba3Gc6DcRu HHcG8fE1e+P/A0CXl7fzFKTM78qV2Et0Fv0jI0PfXoQZHsEE6J+cAWj9YQnepEhb9oI1 ailA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gmztlOc0; 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 hr39-20020a1709073fa700b0073d61c3b3d2si9465307ejc.438.2022.08.23.02.59.51; Tue, 23 Aug 2022 03:00:19 -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=gmztlOc0; 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 S241301AbiHWJs5 (ORCPT + 99 others); Tue, 23 Aug 2022 05:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352491AbiHWJq3 (ORCPT ); Tue, 23 Aug 2022 05:46:29 -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 7E9E092F6C; Tue, 23 Aug 2022 01:44:07 -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 44198614E7; Tue, 23 Aug 2022 08:44:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EB55C433C1; Tue, 23 Aug 2022 08:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244246; bh=Nf3nLV0LGWbKIVOyxXvxMegNYIXmp73WYdm46kgRM34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gmztlOc05d1Jupx+oDiRzf7L42Ju5oeuy6vuLilt/6GUt1GBX3ZUpgbeCkS5mv0kv J5NHafcCeqZPJ0lGIBRkB6b+BhyOH+AbzjndhoGa6/GzU13V5xU9TpUj0wBkD1d1nk u9Jb2axwdP6ZBIADEWQjJEQmH8fC840ypmxguSUo= 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 4.14 108/229] RDMA/hfi1: fix potential memory leak in setup_base_ctxt() Date: Tue, 23 Aug 2022 10:24:29 +0200 Message-Id: <20220823080057.538391777@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 7b8644610feb..d586bd6ddf22 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -1327,8 +1327,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