From patchwork Thu Feb 18 12:59:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: qiuguorui1 X-Patchwork-Id: 12093529 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 2F5A9C433DB for ; Thu, 18 Feb 2021 13:01:14 +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 C5D7564DE9 for ; Thu, 18 Feb 2021 13:01:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5D7564DE9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.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: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:In-Reply-To:References:List-Owner; bh=NZMrcGW+QzYILylG1SlDapStD8fvPQOWjqzHaKejYaM=; b=wgnxKGn13DpZONSS5x7lnBnSrJ M3bRAxd/iKtqpsOeQejVshs0eEf4Ja7rpcZaOxYcLOQ1MRBiRZR0kOdORPbQGQ28EP4sJFeC3Y4pu MGiKWaqSycOVyuo0rRpk0QI/qZR4cF1t/zsc5Ff6U+gk3qUDeo9AsWdzqSUvvTF1gaBC+orCX2MIw 8yxZzo1s+vgsi2vF5PLWUANQ9BqSngwq5s93LjaH4UaTVCG5ReJjtbSFwxa2aqbr3xo7qsV/bhXBy HgLiXQV2HEd2+8omzSKZ2z0ZO0Oi0hXpz7jkWCVYBZXk3dBM/2/AgNigGkuSD4reJ4WEpT1FncT/S iuE80usQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCiuA-0007ll-MS; Thu, 18 Feb 2021 12:59:38 +0000 Received: from szxga07-in.huawei.com ([45.249.212.35]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lCiu6-0007h5-N5 for linux-arm-kernel@lists.infradead.org; Thu, 18 Feb 2021 12:59:36 +0000 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DhF9k0NxTz7lVX; Thu, 18 Feb 2021 20:57:46 +0800 (CST) Received: from localhost.localdomain (10.90.52.227) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Thu, 18 Feb 2021 20:59:09 +0800 From: qiuguorui1 To: , , , , , , , , , , Subject: [PATCH] arm64: kexec_file: fix memory leakage in create_dtb() when fdt_open_into() fails Date: Thu, 18 Feb 2021 20:59:00 +0800 Message-ID: <20210218125900.6810-1-qiuguorui1@huawei.com> X-Mailer: git-send-email 2.12.3 MIME-Version: 1.0 X-Originating-IP: [10.90.52.227] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210218_075935_039065_E92C7C78 X-CRM114-Status: GOOD ( 10.48 ) 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: liuwenliang@huawei.com, qiuguorui1@huawei.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, zengweilin@huawei.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org in function create_dtb(), if fdt_open_into() fails, we need to vfree buf before return. Fixes: 52b2a8af74360 ("arm64: kexec_file: load initrd and device-tree") Cc: stable@vger.kernel.org # v5.0 Signed-off-by: qiuguorui1 --- 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 03210f644790..0cde47a63beb 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -182,8 +182,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 = setup_dtb(image, initrd_load_addr, initrd_len, cmdline, buf);