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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC19EC32753 for ; Wed, 14 Aug 2019 17:12:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 830532173B for ; Wed, 14 Aug 2019 17:12:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802732; bh=j9MIz3asbyWyrjyFUN/nVZifFgfa9bkPDB77i1lNoIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=zKxfH3nn/JCS8XLEdHH2cKpqx4o/ZKIHKZq5zFeFJlkhxyJ68WXJIiSONwNEPREuZ HmW/btLKQXUDaazdnrSS6oFLeIDw4z89b1N2/pHr6U5aBkyCZ6YOZljUKXj9lJUKMY DBswP/m3m4nSIf77wKfynqOPTr5k1CLj6IcWoBSY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730686AbfHNRML (ORCPT ); Wed, 14 Aug 2019 13:12:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:35680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730671AbfHNRME (ORCPT ); Wed, 14 Aug 2019 13:12:04 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE05F2173E; Wed, 14 Aug 2019 17:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802723; bh=j9MIz3asbyWyrjyFUN/nVZifFgfa9bkPDB77i1lNoIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OWbYzhhcV6xWBJgfqlOPEp4ekGZ5SLFrF3bAH8yAYpNLk0K6+PIPqrNje8hUSnIs/ Dm6yHrT3CYQGXtNzpknp/NqeBngYyh1yI7CBgH80DbjnvXB2DqmglmhRF0rADX5y26 Tn2PpX1Tsv+ueWV8A9YqxWKzrw6wyCj+OSluXLCo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , Sasha Levin Subject: [PATCH 4.19 66/91] test_firmware: fix a memory leak bug Date: Wed, 14 Aug 2019 19:01:29 +0200 Message-Id: <20190814165752.422980613@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165748.991235624@linuxfoundation.org> References: <20190814165748.991235624@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit d4fddac5a51c378c5d3e68658816c37132611e1f ] In test_firmware_init(), the buffer pointed to by the global pointer 'test_fw_config' is allocated through kzalloc(). Then, the buffer is initialized in __test_firmware_config_init(). In the case that the initialization fails, the following execution in test_firmware_init() needs to be terminated with an error code returned to indicate this failure. However, the allocated buffer is not freed on this execution path, leading to a memory leak bug. To fix the above issue, free the allocated buffer before returning from test_firmware_init(). Signed-off-by: Wenwen Wang Link: https://lore.kernel.org/r/1563084696-6865-1-git-send-email-wang6495@umn.edu Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- lib/test_firmware.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/test_firmware.c b/lib/test_firmware.c index fd48a15a0710c..a74b1aae74618 100644 --- a/lib/test_firmware.c +++ b/lib/test_firmware.c @@ -894,8 +894,11 @@ static int __init test_firmware_init(void) return -ENOMEM; rc = __test_firmware_config_init(); - if (rc) + if (rc) { + kfree(test_fw_config); + pr_err("could not init firmware test config: %d\n", rc); return rc; + } rc = misc_register(&test_fw_misc_device); if (rc) { -- 2.20.1