Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3280821imw; Mon, 18 Jul 2022 05:30:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sAxt9AhYlG876kuW5KtbEs5YvGIaK8rZ/i6T+Ny3xW/mTbEq9Wudnu7FLKO4L2mLZME3G9 X-Received: by 2002:a05:6870:51c6:b0:10c:2b7c:a542 with SMTP id b6-20020a05687051c600b0010c2b7ca542mr16572509oaj.19.1658147427329; Mon, 18 Jul 2022 05:30:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658147427; cv=pass; d=google.com; s=arc-20160816; b=L7GfZWGxWBNXo9LUHYDLVxNj+bmB7IcF8VvL9DOeg9jj98yB5wYb895fTmQh7tbl5j NRFXLi/bEfO+nzb+rpBnzjk8Prc/2wcZ6zPtZiGBHOZIVRADS6iWEyOXU2Z+tayKld+N aaAHDLWLp3TraAlsgyLDuJEvLBGeHu4M3Xwa77MK2YmeWbPIhftBTTUDOFRQetLL7VBW IR+WRx1ZNpKWf0tdBxP/pr+loWMwLkkSLynSOb8V+rcpWrtINJz4bvT8Wz3nv6GZA16l VAPoZCg4ip51w44fjUL/EtX6JSI/AXlYYGwjbfa5JcxoNZTvbLbbRy4HEcoJTbH9amD0 VG1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=7WnRURhbprDrqCtwUwuN9nOOaYwwaCE8PIzYskBdYv4=; b=qBfLUMmQWDJaVU/AALxnwr5LE+M5U9maLwll6BiGU81Mr2qndQ6KhL3OyifM8Fw7jR Kqi7HvErmDet/7Enz+kHJvkypfVqnfhtMcB7P8y4FzZEpd+D7Nh7SmWxpEkNqH+2TUj0 o9Jmi1JP/qz/brn7GVR3bFT7tuYsKmLiNEYM6yhslHUeoAhqh2C2/W5IHhB1LXdYJxJo 6YXf5FJ931A8EkU7YcH2XuwBfrlcj2uoMV0Rql0NQBrckDucULuDUMqQCgRU0Rd+fuZ7 nvQ4KPa09KllDq7+VLE8c+YR4LFv0mvqgunSzd5vIQs1UQI0hJ7+rsJibY+GUrIMSr/N 3tPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cornelisnetworks.com header.s=selector1 header.b="VuSiOJ/A"; arc=pass (i=1 spf=pass spfdomain=cornelisnetworks.com dkim=pass dkdomain=cornelisnetworks.com dmarc=pass fromdomain=cornelisnetworks.com); 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j19-20020a056870169300b000fb283f4b0esi8270906oae.195.2022.07.18.05.30.13; Mon, 18 Jul 2022 05:30:27 -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=@cornelisnetworks.com header.s=selector1 header.b="VuSiOJ/A"; arc=pass (i=1 spf=pass spfdomain=cornelisnetworks.com dkim=pass dkdomain=cornelisnetworks.com dmarc=pass fromdomain=cornelisnetworks.com); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234843AbiGRMMJ (ORCPT + 99 others); Mon, 18 Jul 2022 08:12:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234837AbiGRMMH (ORCPT ); Mon, 18 Jul 2022 08:12:07 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2114.outbound.protection.outlook.com [40.107.220.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C0D248CC; Mon, 18 Jul 2022 05:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N1a7YeWZ1l/7XdZNq58zuWi9bC65+u1+n/kIkdfgo3F3M2P9cT//+LhyCOMAyIEqOFwjGlEXUdYh1DkK45v0Fx7Y9nkCYvsEAUUwTCWYpEZeE3iohAJS6QtU7vJIg+gvVenV4UUqNY6HK2dLa6m7KZ4lzy6I5sP8jUoqE7BOtns2a/EeT/0Htz7Nnr6Am+NvK+1aTxgd0fGvGlHiIxoPc1hjqvC0pxXTd+rDSjSunIymrlFgcGe7JamznYE6DGTt/U2M4PNTGtjJK0x3iqDcyqy0sqMXlFKXTPFE/zwzsLKxzBlFRHs+mNQ+77zIA/plkbAx2c0nQPR9dO0wzKGAFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7WnRURhbprDrqCtwUwuN9nOOaYwwaCE8PIzYskBdYv4=; b=dLLYRD6B/mnuE2funG7xwF+QjqGqbqat66T2hJbfZwW7surlhwhV9TmrJIAWrssf4EWX9MpgYDhDqefKnKgzdtBuboZXzjlWEIRPxDospZ3RoA1R9J97cnwk0he3aoFgn3LpPJzi2eWxefsQv56ivAafSTLhaS1Au0Z7R6ZK1zSOnOop41ivmvJFrlSe/0gSITImMjuuebxl2DlxncsRFMzKPD5HoaF0bVUnNgEc3EjDrACaaI7dMZOvRWjCFWZ5tFy4Uiwgv3a0BL6dgAfjKpQ96RKrDGgOdjLjJyTJzEESd5qA2MqHgBlEcX37jK0VNoW+JNc1ichJ9Kl/0S/xgw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornelisnetworks.com; dmarc=pass action=none header.from=cornelisnetworks.com; dkim=pass header.d=cornelisnetworks.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cornelisnetworks.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7WnRURhbprDrqCtwUwuN9nOOaYwwaCE8PIzYskBdYv4=; b=VuSiOJ/Ap7hgmfXR+bDZ42iQspb5pUx+zMy+snPS8O0WIad8GeupBpP6ar4EV28kk3E4fMa+Er9nR3/7KZdFedORK+1Rbu1OMn3sirIUKCixIErKLKWfzyV9aMKXOMhUBWuWt3MsFEn5VYBiyZ5lvSa3gQZkazv04EfA+nMRtKLL4on4EOV5ieIHLjqVjZKNEm/E7iPttmezgyxqLrRKI8YaQSlnUtg1aZ2ap9oiML51h0qSDsalB2KX8s/+W1RfyqMxnElPHEgcVLac2wZGtwW3i4snsR5dQKsaiB6NoMndUHO9sSVKM76fDTN4wbabMub58A7YeX7LqLcNEh/1Kw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cornelisnetworks.com; Received: from PH0PR01MB6439.prod.exchangelabs.com (2603:10b6:510:d::22) by DM6PR01MB4361.prod.exchangelabs.com (2603:10b6:5:7a::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12; Mon, 18 Jul 2022 12:12:04 +0000 Received: from PH0PR01MB6439.prod.exchangelabs.com ([fe80::4000:7ba9:d4a:c339]) by PH0PR01MB6439.prod.exchangelabs.com ([fe80::4000:7ba9:d4a:c339%7]) with mapi id 15.20.5438.023; Mon, 18 Jul 2022 12:12:03 +0000 Message-ID: Date: Mon, 18 Jul 2022 08:11:59 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] RDMA/hfi1: fix potential memory leak in setup_base_ctxt() Content-Language: en-US To: Leon Romanovsky Cc: Jianglei Nie , jgg@ziepe.ca, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220711070718.2318320-1-niejianglei2021@163.com> <1038e814-5f0d-17a3-1331-8ed24a64d597@cornelisnetworks.com> From: Dennis Dalessandro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MN2PR01CA0049.prod.exchangelabs.com (2603:10b6:208:23f::18) To PH0PR01MB6439.prod.exchangelabs.com (2603:10b6:510:d::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d5f2ee37-f93a-4a06-1a6c-08da68b6b9af X-MS-TrafficTypeDiagnostic: DM6PR01MB4361:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W4BHqQ//vYreHj4l2KaxOcDy8TD/Z4nMbJASDnIG+hGWA2pD/M+Vd01SfnTwTT/yPRDbi9nGgjfoRZEcj8AIs2f9C1voSK26RczoAtZdPyeUpN/Hjkg4oHuG+So0sfwulgu7Ix8hsAlDJ3S9DeXxPcNVULJsXOwiKTx9SyrwmmmuZ4tIyPZAjj0nUWrCyPhP2Hn0QhJjvwpBI8UckSPtnsczWOXd+aTVU8JGYhka1Y+BtMrytFSh6OCIeIHV2xla8EwtOCMD/J2AiufvfinJjtO3X79Zi3bFCILeTdUMHoDbmN9woenHeXFaTSR2bXZa4sN65TBFGLfkXbxewkwloII38QicXvZfrfEVOEUmXG8T40L0HRLo1S2+iGicCbiNeRzytf5pikHseINeCohudLwrIRS+ja++2x+ZE/Ovhq+uP7SsNmBTP8ZoYfGFFYYgs6Wl9GIGt6IN1NeZl1VIOKKcccSioALzZIc+yHTLwhzFlYwix0nPnQWpKYKKWeWuREvKVR8LKIwGuD6K0zZwYSC3PjU24Dk2cnlpFcLEhKj70VwClPi8W5aSB0yGFBF69+sX2QTDZgs2InWPtRH0bISOg+zgOVSG9SCJ0IwNohHYTAx4WxkRW9hAkaYYKG4Rbr5ReILlimv4SmVixys/RWUOkigf5XxBxC1qOiGGbTq60oVwL79s07b9WKhWDBfKxMo5XcrS5nxfIIXdRPW6X/+kScMtbFLEAAqllVILBeMOD2PwK4br0qfRw1Mdahw0QTm1HaRtnFa7bavePFyS3BLSC++PhJYSgGj2N2n/eBH8Y/AWdPNvhtX46eYGjy5zERoBLRwf7NHvfPygvP3zdg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR01MB6439.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(376002)(136003)(346002)(366004)(39830400003)(396003)(83380400001)(6512007)(186003)(44832011)(26005)(2906002)(41300700001)(6666004)(86362001)(6506007)(52116002)(53546011)(478600001)(6486002)(5660300002)(2616005)(8936002)(31696002)(38100700002)(6916009)(316002)(31686004)(36756003)(8676002)(66556008)(38350700002)(66946007)(4326008)(66476007)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cFN4YnFsYVlGeGFsZURPOWtHK0VGRHZ0ZFdEeVhXMkdHL2pvQTdsK0dnb0hN?= =?utf-8?B?T3VQbUhScWRKUHZSYVRvUEJmazJVQ2xLdU5LQUgzY2ErSm1YTWM5N3RWUHVH?= =?utf-8?B?S25lYnEvU1k2dlRueUJpZkdqZjdlWXpHZU1WZTJnR0hJc2pZZWFMajkzUi8v?= =?utf-8?B?Vzloc2JoNm1nVDlBaXB0K3lsU0s5SWlHMit4U3pCZkRTZFNoczhvbWZkajRM?= =?utf-8?B?eFVHNGkzTjltZ0FSU2tXZTBaWG41WVA0L1dOMm1rL3NuYVYyeFlDTzliaUYr?= =?utf-8?B?QmxMZmQ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rWVdHcVV3?= =?utf-8?B?c0tzeEhKR090K2JkcjZYbkVkN29uVWZaTGFMMVFTOHRKQ1RDQkgxUkxiYVNm?= =?utf-8?Q?cmmPHQqezh3OP8Xb12jTQgA=3D?= X-OriginatorOrg: cornelisnetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5f2ee37-f93a-4a06-1a6c-08da68b6b9af X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB6439.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2022 12:12:03.6518 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4dbdb7da-74ee-4b45-8747-ef5ce5ebe68a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HyjUQx0/zEOF1nnxF8n+8sTF/dfywqohRGmryuQMA9Ha1iZXT2qNpLv+ZKkwVMS31qLAz4KPdjd+yCihDMK2FbD4xU1g44B/+0DPiA1QgMFMdgOWfUo1VCYk5K/bwfhE X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB4361 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 On 7/18/22 6:39 AM, Leon Romanovsky wrote: > On Mon, Jul 11, 2022 at 07:52:25AM -0400, Dennis Dalessandro wrote: >> On 7/11/22 3:07 AM, Jianglei Nie wrote: >>> 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. >>> >>> Signed-off-by: Jianglei Nie >>> --- >>> 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); >>> >> >> Doesn't seem like this patch is correct. The free is done when the file is >> closed, along with other clean up stuff. See hfi1_file_close(). > > Can setup_base_ctxt() be called twice for same uctxt? > You are allocating rcd->groups and not releasing. The first thing assign_ctxt() does is a check of the fd->uctxt and it bails with -EINVAL. So effectively only once. -Denny