Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2811515pxp; Mon, 14 Mar 2022 05:34:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsPRrgsie7loBK7tBbYfjSjj4l+LIVMEV2bMOCARM9ukdr7dtBElxt8wVlvmuWpBbWH4pL X-Received: by 2002:a17:907:961f:b0:6db:c8f3:dc72 with SMTP id gb31-20020a170907961f00b006dbc8f3dc72mr6564435ejc.92.1647261265230; Mon, 14 Mar 2022 05:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647261265; cv=none; d=google.com; s=arc-20160816; b=NoB4GSmHY9PjE86jvat3CSaa6lj82ruiyrB8t8MGufosBBJmw+6sqCWJLa7+IqHjgy E0cJpWqvbrMmn6ND6sUmVvUdnsXrWVUcyoapBt/jhNcnLkvl9lUp66QLn4WLAEbkI3i7 fpJSV7MgN3lGvS2osnINGRTAkRUbxhfVnz/SzZ8LGWd63wXcRnJNXhHsYxiBra4PKThR 9n3OQCxiLzLL2A7wxACmao5rC3NYNxEVmDxI2qvKwhCrunl1LvmEBoS7RtwwLX1Y9wAI T9mFSJcPj8xa2h3AkhLZpkwB0jgPU9SvAyZmcf5erIweTOdRJ/1NbLZull7vBA1iiW2x 2mRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e2TL/lDNRJkO9EA0MpqHr69vaJrTdVfTaoXKhxG3wNs=; b=cwaV+qbEF6tNgDA7ZXWNGhMF/9F23SCJ3dbb0Frkc5lp30Y7lj+ByXMOynQaHPWDHC u6a6Z+h8alpj/gwdflUSiDVA/7W36Ckq5UzvKXRlT2SBe2Y++8OsPxU3zp0tzmdBf9b/ EIAsyMprru1/Q2J4b8BQjU+Sjf2zJBgvNw4aqXEslrumcsul9A3jE4PLGxk+9J9UUGF7 kfaMgCoPMXLIqmZRqOYFnpqj5fOwzky7s6WUz+igL/JUgJCNo654yLTAlA9hsZ0dRH8L L4VXeRyqJPv2yUthHHggt7hTTZ38Zea+tUyXMrEa2lwOPuArMAq8xmArfMJ4Azsv3uYx ZmZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="UiT/qfTk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id el6-20020a056402360600b0041614eca4e2si8686623edb.42.2022.03.14.05.33.59; Mon, 14 Mar 2022 05:34:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="UiT/qfTk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235757AbiCNBzU (ORCPT + 99 others); Sun, 13 Mar 2022 21:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235756AbiCNBzS (ORCPT ); Sun, 13 Mar 2022 21:55:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF5FA1EEE5; Sun, 13 Mar 2022 18:54:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 258F860F0A; Mon, 14 Mar 2022 01:54:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B24D8C340E8; Mon, 14 Mar 2022 01:54:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647222848; bh=JzzzQoL0GbYCQzlYz/yEZ+EV3sEjDtQ9rE0YeOlbuRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UiT/qfTkpJ/SOem5Hpbqf/5AhqLnmO+NAlKIs0E+xLVW2frrhi5UgaAXhG2s8ZsRi tM42odHvXAmxnfq8G62+XQGC/65LCKbi6vUm3B5gjxPU9vv49JqUQTMQRfxy6O8iaO AWH9WRluirf5LFCjCTsPXHit2tTE8By95FK+ArLDIhSRYZnSNDhlmN8gpkYWvoiBQl Sci/UFsfToPmJ3c8eXUx84fncb4yIPWLn/OUWjkjzra0OmDDpQtJR8tPMqFXYBrEtW SRsLKmiwEd5uJIvMtNLynAkMUqkm36VhycuHkF4CVAql/mOurY6z8sxQ6T2uvM7s+i MQ3QsrHkCu6nw== From: Masami Hiramatsu To: Steven Rostedt Cc: Masami Hiramatsu , Padmanabha Srinivasaiah , LKML , Jonathan Corbet , linux-doc@vger.kernel.org, Randy Dunlap Subject: [PATCH v2 1/3] bootconfig: Check the checksum before removing the bootconfig from initrd Date: Mon, 14 Mar 2022 10:54:04 +0900 Message-Id: <164722284387.689258.6569515754244465668.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <164722283333.689258.144495814460576707.stgit@devnote2> References: <164722283333.689258.144495814460576707.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Check the bootconfig's checksum before removing the bootcinfig data from initrd to avoid modifying initrd by mistake. This will also simplifies the get_boot_config_from_initrd() interface. Signed-off-by: Masami Hiramatsu --- init/main.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/init/main.c b/init/main.c index 65fa2e41a9c0..421050be5039 100644 --- a/init/main.c +++ b/init/main.c @@ -265,7 +265,7 @@ static int __init loglevel(char *str) early_param("loglevel", loglevel); #ifdef CONFIG_BLK_DEV_INITRD -static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum) +static void * __init get_boot_config_from_initrd(u32 *_size) { u32 size, csum; char *data; @@ -299,17 +299,20 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum) return NULL; } + if (xbc_calc_checksum(data, size) != csum) { + pr_err("bootconfig checksum failed\n"); + return NULL; + } + /* Remove bootconfig from initramfs/initrd */ initrd_end = (unsigned long)data; if (_size) *_size = size; - if (_csum) - *_csum = csum; return data; } #else -static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum) +static void * __init get_boot_config_from_initrd(u32 *_size) { return NULL; } @@ -408,12 +411,12 @@ static void __init setup_boot_config(void) static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata; const char *msg; int pos; - u32 size, csum; + u32 size; char *data, *err; int ret; /* Cut out the bootconfig data even if we have no bootconfig option */ - data = get_boot_config_from_initrd(&size, &csum); + data = get_boot_config_from_initrd(&size); strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL, @@ -437,11 +440,6 @@ static void __init setup_boot_config(void) return; } - if (xbc_calc_checksum(data, size) != csum) { - pr_err("bootconfig checksum failed\n"); - return; - } - ret = xbc_init(data, size, &msg, &pos); if (ret < 0) { if (pos < 0) @@ -470,7 +468,7 @@ static void __init exit_boot_config(void) static void __init setup_boot_config(void) { /* Remove bootconfig data from initrd */ - get_boot_config_from_initrd(NULL, NULL); + get_boot_config_from_initrd(NULL); } static int __init warn_bootconfig(char *str)