From patchwork Thu Mar 3 08:15:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Glazkov X-Patchwork-Id: 12767204 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 00EE8C433EF for ; Thu, 3 Mar 2022 08:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbiCCIWg convert rfc822-to-8bit (ORCPT ); Thu, 3 Mar 2022 03:22:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbiCCIWf (ORCPT ); Thu, 3 Mar 2022 03:22:35 -0500 X-Greylist: delayed 379 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 03 Mar 2022 00:21:50 PST Received: from mxout01.lancloud.ru (mxout01.lancloud.ru [45.84.86.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7536917187F for ; Thu, 3 Mar 2022 00:21:50 -0800 (PST) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout01.lancloud.ru 3106A20D5C35 Received: from LanCloud Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Denis Glazkov CC: Denis Glazkov , David Howells , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , Mimi Zohar , "Mehmet Kayaalp" , "linux-kernel@vger.kernel.org" , "keyrings@vger.kernel.org" , "linux-security-module@vger.kernel.org" Subject: [PATCH] KEYS: fix memory leak when reading certificate fails Thread-Topic: [PATCH] KEYS: fix memory leak when reading certificate fails Thread-Index: AQHYLtbXK3D575r57ECuz2QMV/HRKg== Date: Thu, 3 Mar 2022 08:15:28 +0000 Message-ID: <20220303081428.12979-1-d.glazkov@omp.ru> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.11.133] MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: In the `read_file` function of `insert-sys-cert.c` script, if the data is read incorrectly, the memory allocated for the `buf` array is not freed. Fixes: c4c361059585 ("KEYS: Reserve an extra certificate symbol for inserting without recompiling") Signed-off-by: Denis Glazkov --- scripts/insert-sys-cert.c | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/insert-sys-cert.c b/scripts/insert-sys-cert.c index 8902836c2342..b98a0b12f16f 100644 --- a/scripts/insert-sys-cert.c +++ b/scripts/insert-sys-cert.c @@ -251,6 +251,7 @@ static char *read_file(char *file_name, int *size) if (read(fd, buf, *size) != *size) { perror("File read failed"); close(fd); + free(buf); return NULL; } close(fd);