Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1681395iof; Tue, 7 Jun 2022 09:40:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwshTaMLkJXMEvFFW/HMrn3YJhLQLNWzR+eK73PVxrpZ9YW7DMiZFoJjp8J6BBsa6ym/1Q X-Received: by 2002:a17:902:d584:b0:167:6ab9:b094 with SMTP id k4-20020a170902d58400b001676ab9b094mr16436300plh.16.1654620034432; Tue, 07 Jun 2022 09:40:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654620034; cv=none; d=google.com; s=arc-20160816; b=R97HGkcEKAeyXb6gMe7HzcdL2bDWrEbukmcBURyyrfwL7KFxH7nzTQWVhAKiUh4p5D A7+KDjZ0ljepFgA6hw2yGpPoEw1RjWKQunRHkinsvE794RdXZM7/jJdMCqynlaUTaC0A x0dGAVFKa1+tsI5iGFIkq5qSkrMAqKJiaqNykUzx12w9ksA/Kpfj4IA5tF0QmyEpsr1h Yqwx/zq1vU1Op/ZU2RP72q95ehjjsKQUnh72NlX2TWz4Y83twMuUofjH2ehXZk8I3Dgt E1yeQ5aTSpG9ieXialLeq8N8PC1ZZW0MDLZfW8FYI1G5ZkOjM7KIv9AP3xOaBg/CInIs HCHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=YzSJM3GOzz8DUDfszt+kAhZMPyn+HzK6fLAM1xzK1lw=; b=AHC4j7RfW/64rUxEnp3X1rnxFalv9TOSdXxyc+fI7j+kghnD86xR16F9NBNoA6pfO8 Usk+L5T9z75Uz14M18ZZwH/nCw3jMU0n57BAeIod1io+fA9lao7bis5CwYzltS4Sg5hr Slvn/prCGHIJkde/dFWM8nt+sfVaW8CevYfi/XpDTuqy0IrOj9VferiMtasL1BLiycgL lMuRRuFgrfzBnEAizBzZ2u0Is3cfHJl1JzJcn4C/FVNXN5MD0qb3YyIImzKg4Hl9aq4A 28F/bMTNqqPNCIHvPFyO5mhhDyfWFCeytU20ddO/G/OHv4RAnvCrYskXZofzb90zjYyi 5FtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ep4byXZ8; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l18-20020a170903245200b00163f185b031si28875697pls.378.2022.06.07.09.40.18; Tue, 07 Jun 2022 09:40:34 -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=@kernel.org header.s=k20201202 header.b=Ep4byXZ8; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240677AbiFGKL6 (ORCPT + 99 others); Tue, 7 Jun 2022 06:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240669AbiFGKLz (ORCPT ); Tue, 7 Jun 2022 06:11:55 -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 4DC1DA338C; Tue, 7 Jun 2022 03:11:54 -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 F3A09B81EDB; Tue, 7 Jun 2022 10:11:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F64AC3411E; Tue, 7 Jun 2022 10:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654596711; bh=u/LeARG2hwxh21NjNwvi6BgnN1cum7FrrFPMu1OzkfY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ep4byXZ8izun2IJ+1pW7U1VjvjuX0mLio8JYSqFxp96ZTPtlppNuwjAgGzLO58DmO F1BS8dLeF3tRS57YXHB2AvkPU01RHWYxPVpx92soGPkInCwWYWmomoS9qYBNmd0ku0 YxFLyuy9RTaY8uFE8iT3Ls3OI2sWZO3Mob0QDIvNY89Scx0xrDv690vrFmpi9mB2Ni CWPTE4foaaomaw1I+BJzDb48A7ytfFhQt0+boLnB0h0DeMLFoZuV9Nt0xooN6rLOn+ bMikhScHjD8yv0fS1vf3q59YUNCycOQzHg5Fh17I+XYsHnJuayqQIPG0pCqkVnLbeF JRyee4eULKOWg== Date: Tue, 7 Jun 2022 13:09:56 +0300 From: Jarkko Sakkinen To: Jianglei Nie Cc: jejb@linux.ibm.com, zohar@linux.ibm.com, dhowells@redhat.com, jmorris@namei.org, serge@hallyn.com, linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] security:trusted_tpm2: Fix memory leak in tpm2_key_encode() Message-ID: References: <20220607074650.432834-1-niejianglei2021@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220607074650.432834-1-niejianglei2021@163.com> X-Spam-Status: No, score=-8.3 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 "KEYS: trusted: fix memory leak in tpm2_key_encode()" On Tue, Jun 07, 2022 at 03:46:50PM +0800, Jianglei Nie wrote: > The function allocates a memory chunk for scratch by kmalloc(), but ~~~ ~~ from with There's more than one function in Linux - maybe you'd rather want to write: "tpm2_key_encode() allocates ..." > it is never freed through the function, which leads to a memory leak. You can just write "it is never freed, which leads to a memory leak." > Handle those cases with kfree(). "Free the memory chunk with kfree() in the return paths." > Signed-off-by: Jianglei Nie Thank you finding this and providing a fix, it is highly appreciated. Please don't take the nitpicking with the language personally. Just want to have it documented in appropriate form. BR, Jarkko