Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3412961rwa; Tue, 23 Aug 2022 04:29:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR5GI7q9QbOmLKAwxn5ApYk56zuuBwLqxLB7xxTGqRmGFp8pLdA2u6UH/vq4BlpuMNMQMOfr X-Received: by 2002:a63:6d09:0:b0:427:bbb0:e62 with SMTP id i9-20020a636d09000000b00427bbb00e62mr19461538pgc.346.1661254151907; Tue, 23 Aug 2022 04:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254151; cv=none; d=google.com; s=arc-20160816; b=UkoAraEnlfVlzjrf/yXbsO0GSetghzmhmr1S5vMUKuCNXYmw/T4L/ZCoSi9KgdArOV TKEyjhrLd0z7883dGZyO645pKG77UCWADpjn/pTCi/jFXCflwVfzY36HUWMBMnBc2YQG WXjbZ+f/4gjOzE2HOZvBNPxyIhHs+rn5RnJ/Kp1QTFrhriDAphyu/aOiWXnCtsEpZnEC eg2SXrwsrs8/+yjp8Y95vW2Rvu+EIiSqhw4Jt2SUJiNkl0MSrupMqjSr+UTFfJaBYduU B5hCHj09NpD/BSPARSuft5H4b/W4CuvLegjeGjQtiQDTv1td2NPGEelhhQkdMK2ssfBj GadA== 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=YXaeKUjuXwGsVl1lF7EJwEGMmU9wXEmzKZl5pugaSiU=; b=uvGBbvu72v1fMaVwh6VbA3j2Wg2z1pRgZS5FjhlraDmguiZC7yYGaT17WafXvyJiwV WPIukfJi/qTTgBohLzk1rt0OgZTcR7X2xLPrfB1pf+Uk4uEkQyposaW+EPkQ4eu8mH+p SDMZGLBD1TCYp/JEj+Vq4+1aVZHjAJlZzcLRNrAs6t3ClAiFnBZSYSYTNLoRjcBtmn5W 6ef8xKkDhcPkY493D1KejMqNOiQtGpYZuCamz2NJJeNPATTrSOC5XaNINQ/9InUxJmAy 4+hT/s1OHtX7pFyLye4dk69EIDBUfYKMysw8Yl76Fv4y66rTGyXrnQF6qLNakP/jiyPD Z3gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wRvsjld8; 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 q68-20020a632a47000000b004128e9db273si15975012pgq.587.2022.08.23.04.29.00; Tue, 23 Aug 2022 04:29:11 -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=wRvsjld8; 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 S1355615AbiHWKnx (ORCPT + 99 others); Tue, 23 Aug 2022 06:43:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355166AbiHWKer (ORCPT ); Tue, 23 Aug 2022 06:34:47 -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 6A712A5C71; Tue, 23 Aug 2022 02:07:01 -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 394E26158D; Tue, 23 Aug 2022 09:07:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 077EFC433D6; Tue, 23 Aug 2022 09:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245619; bh=z4f0bDwwawu5JjlTezENU3S/+w7vDeKkbxb19Qhx/HI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wRvsjld8bt9LFc2IzicN7l5TXer9d6cXE246XUmjdZ3TG89Nm9gaaNrSzrqMZosg4 4o+nIun6tX6y9LgKSv49gqQ/Au3LGGrq+hkqzJiRUGr707y3CYQDd4KvcLESfl+zcv fZ1MbVn+zoPwmGdPqOHydlCGi5W0QG7WIPqhLVOI= 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.19 134/287] RDMA/hfi1: fix potential memory leak in setup_base_ctxt() Date: Tue, 23 Aug 2022 10:25:03 +0200 Message-Id: <20220823080104.948798574@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 64ee11542a56..be31faf6cc62 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -1222,8 +1222,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