From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA8ACC433EF for ; Tue, 7 Jun 2022 10:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240686AbiFGKL7 (ORCPT ); Tue, 7 Jun 2022 06:11:59 -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> 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