From patchwork Wed Sep 15 00:53:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 12495205 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,DKIM_INVALID, DKIM_SIGNED,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 CBB44C433EF for ; Wed, 15 Sep 2021 00:53:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5639161242 for ; Wed, 15 Sep 2021 00:53:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5639161242 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E79C76B006C; Tue, 14 Sep 2021 20:53:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E570F940008; Tue, 14 Sep 2021 20:53:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3B2F940007; Tue, 14 Sep 2021 20:53:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id C676C6B006C for ; Tue, 14 Sep 2021 20:53:09 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8025430177 for ; Wed, 15 Sep 2021 00:53:09 +0000 (UTC) X-FDA: 78587983698.13.5E97787 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf19.hostedemail.com (Postfix) with ESMTP id 38246B0000A3 for ; Wed, 15 Sep 2021 00:53:09 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 54E3061165; Wed, 15 Sep 2021 00:53:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631667188; bh=sKvjf2fiiYwNnsu3EWnRbm2IWieh3kqYhZMnjiu1GMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J2qweMngdGf7vLP9t+edQUOaQ/BYkkuPzneCCroClzxX0lLigowVrMrWTS1OQcV0F aO+HeHOiF31fbPlISjgAla6TwpGuMswVe13wGRfrsri3exSHoN/680zOpTMtNy/kdI OZZVBIMgjNAMbtmvBwIAc5PNn3o2SrA0AizZ/+Y5wzJz3GTwDgyuXwn68TRFSOABlX cUij6FGxgSaZH4JL/YB2BBAn7jOLwWmw4mHevSNAIbxZXzpsw5IjgCmOhfafrLgAhK q4+CFPGFIZgcfB6MmQI+VeobecggDh5aNboGvA0RR5go7jlMAWDEK8saSSwpTNe6Aq XZ/N0LwrmTEFQ== From: Masami Hiramatsu To: Steven Rostedt Cc: Linus Torvalds , Mike Rapoport , Andrew Morton , LKML , Ingo Molnar , Masami Hiramatsu , Linux-MM , Vlastimil Babka Subject: [PATCH v2 1/5] bootconfig: Fix to check the xbc_node is used before free it Date: Wed, 15 Sep 2021 09:53:06 +0900 Message-Id: <163166718582.510331.11732633028925882626.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163166717752.510331.12843735095061762373.stgit@devnote2> References: <163166717752.510331.12843735095061762373.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 38246B0000A3 X-Stat-Signature: fp736czz1e6yrah9njnswyhskdpnuumh Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=J2qweMng; spf=pass (imf19.hostedemail.com: domain of mhiramat@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=mhiramat@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1631667189-53940 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Fix to check the xbc_node is used before calling memblock_free() because passing NULL to phys_addr() will cause a panic. This will happen if user doesn't pass any bootconfig to the kernel, because kernel will call xbc_destroy_all() after booting. Fixes: 40caa127f3c7 ("init: bootconfig: Remove all bootconfig data when the init memory is removed") Reported-by: kernel test robot Signed-off-by: Masami Hiramatsu --- Changes in v2: - Rebase on top of Linus tree. --- lib/bootconfig.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 5ae248b29373..bee691ea8213 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -792,7 +792,8 @@ void __init xbc_destroy_all(void) xbc_data = NULL; xbc_data_size = 0; xbc_node_num = 0; - memblock_free_ptr(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX); + if (xbc_nodes) + memblock_free_ptr(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX); xbc_nodes = NULL; brace_index = 0; }