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=-26.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham 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 0CE66C2BBCA for ; Mon, 14 Dec 2020 19:20:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC08022473 for ; Mon, 14 Dec 2020 19:20:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502326AbgLNTUw (ORCPT ); Mon, 14 Dec 2020 14:20:52 -0500 Received: from linux.microsoft.com ([13.77.154.182]:58450 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440658AbgLNTU3 (ORCPT ); Mon, 14 Dec 2020 14:20:29 -0500 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 5918420B718C; Mon, 14 Dec 2020 11:19:11 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5918420B718C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607973551; bh=DsqR7vzIXHoUsAEq7hzDyWxUD/vBBswSPRJLWzRzPQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OlZCck7KXDpFmFF206z6b5aoRsssJYga0eFCHXG2uJ8Wv1l4hKobTq8XToagJfKkV d/e6HnvvGJMJul2lWCU40ne4pXxn0qThZKC5D32/TsUeiz63vRuh+EbbLoTVD3tf9Z dntyIENoK3nejHi6taDDE9X+bbwwcemp16NDPjBY= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, takahiro.akashi@linaro.org, gregkh@linuxfoundation.org, will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au Cc: james.morse@arm.com, sashal@kernel.org, benh@kernel.crashing.org, paulus@samba.org, frowand.list@gmail.com, vincenzo.frascino@arm.com, mark.rutland@arm.com, dmitry.kasatkin@gmail.com, jmorris@namei.org, serge@hallyn.com, pasha.tatashin@soleen.com, allison@lohutok.net, masahiroy@kernel.org, bhsharma@redhat.com, mbrugger@suse.com, hsinyi@chromium.org, tao.li@vivo.com, christophe.leroy@c-s.fr, prsriva@linux.microsoft.com, balajib@linux.microsoft.com, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Subject: [PATCH v11 7/8] arm64: Free DTB buffer if fdt_open_into() fails Date: Mon, 14 Dec 2020 11:18:53 -0800 Message-Id: <20201214191854.9050-8-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201214191854.9050-1-nramas@linux.microsoft.com> References: <20201214191854.9050-1-nramas@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org create_dtb() function allocates memory for the device tree blob (DTB) and calls fdt_open_into(). If this call fails the memory allocated for the DTB is not freed before returning from create_dtb() thereby leaking memory. Call vfree() to free the memory allocated for the DTB if fdt_open_into() fails. Signed-off-by: Lakshmi Ramasubramanian --- arch/arm64/kernel/machine_kexec_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 7de9c47dee7c..3e045cd62451 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -65,8 +65,10 @@ static int create_dtb(struct kimage *image, /* duplicate a device tree blob */ ret = fdt_open_into(initial_boot_params, buf, buf_size); - if (ret) + if (ret) { + vfree(buf); return -EINVAL; + } ret = of_kexec_setup_new_fdt(image, buf, initrd_load_addr, initrd_len, cmdline); -- 2.29.2 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 54321C2BBCD for ; Mon, 14 Dec 2020 19:20:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E191922525 for ; Mon, 14 Dec 2020 19:20:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E191922525 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8QE4wDUDK7zObtaj2rPszibFREbakEt5gFrdF5/O7vE=; b=UdNNmQumXgW7fPVHYq9lMB9/d sBx33Tujeoxu5lZaQfIyrlaceIiQ3q1H33eenETL/LkvsEdLEXHW3hF+Tod6OBL2NJFABd3RkGfCM vYKQsG8+Dl+zTvVyThs7oryTEJKBnDBtzfW7OvW8J6FLNeSNxBfq93pV1bApJkzR7Fe7C6wuh0hZN tOK1DEKK5oewej46eFWIBBhIs+Bm2/B6YqKNSQ8F0CttxEgEJEHmlfoiyDIYi32mXs+qaN1YTfZbR wD2dx0IR6AHh8zYo8zzZf1wyxHwV8/12qIz/spbLUmOd4cwzM7NanJGGyfNJs4JMRGIQbUL8uqPI6 ohh8qX7fQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kotNm-0002sq-0U; Mon, 14 Dec 2020 19:19:42 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kotNI-0002mp-8x for linux-arm-kernel@lists.infradead.org; Mon, 14 Dec 2020 19:19:15 +0000 Received: from localhost.localdomain (c-73-42-176-67.hsd1.wa.comcast.net [73.42.176.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 5918420B718C; Mon, 14 Dec 2020 11:19:11 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5918420B718C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607973551; bh=DsqR7vzIXHoUsAEq7hzDyWxUD/vBBswSPRJLWzRzPQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OlZCck7KXDpFmFF206z6b5aoRsssJYga0eFCHXG2uJ8Wv1l4hKobTq8XToagJfKkV d/e6HnvvGJMJul2lWCU40ne4pXxn0qThZKC5D32/TsUeiz63vRuh+EbbLoTVD3tf9Z dntyIENoK3nejHi6taDDE9X+bbwwcemp16NDPjBY= From: Lakshmi Ramasubramanian To: zohar@linux.ibm.com, bauerman@linux.ibm.com, robh@kernel.org, takahiro.akashi@linaro.org, gregkh@linuxfoundation.org, will@kernel.org, catalin.marinas@arm.com, mpe@ellerman.id.au Subject: [PATCH v11 7/8] arm64: Free DTB buffer if fdt_open_into() fails Date: Mon, 14 Dec 2020 11:18:53 -0800 Message-Id: <20201214191854.9050-8-nramas@linux.microsoft.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201214191854.9050-1-nramas@linux.microsoft.com> References: <20201214191854.9050-1-nramas@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201214_141912_490616_EFD9F99C X-CRM114-Status: GOOD ( 12.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, benh@kernel.crashing.org, bhsharma@redhat.com, tao.li@vivo.com, paulus@samba.org, vincenzo.frascino@arm.com, frowand.list@gmail.com, sashal@kernel.org, masahiroy@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, serge@hallyn.com, devicetree@vger.kernel.org, pasha.tatashin@soleen.com, prsriva@linux.microsoft.com, hsinyi@chromium.org, allison@lohutok.net, christophe.leroy@c-s.fr, mbrugger@suse.com, balajib@linux.microsoft.com, dmitry.kasatkin@gmail.com, linux-kernel@vger.kernel.org, james.morse@arm.com, linux-integrity@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org create_dtb() function allocates memory for the device tree blob (DTB) and calls fdt_open_into(). If this call fails the memory allocated for the DTB is not freed before returning from create_dtb() thereby leaking memory. Call vfree() to free the memory allocated for the DTB if fdt_open_into() fails. Signed-off-by: Lakshmi Ramasubramanian --- arch/arm64/kernel/machine_kexec_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 7de9c47dee7c..3e045cd62451 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -65,8 +65,10 @@ static int create_dtb(struct kimage *image, /* duplicate a device tree blob */ ret = fdt_open_into(initial_boot_params, buf, buf_size); - if (ret) + if (ret) { + vfree(buf); return -EINVAL; + } ret = of_kexec_setup_new_fdt(image, buf, initrd_load_addr, initrd_len, cmdline); -- 2.29.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel