Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1622037ybz; Sun, 26 Apr 2020 00:27:09 -0700 (PDT) X-Google-Smtp-Source: APiQypKVXGxOftiona2IoXL5XwaVNFKRj7VRI9p2mS9DRaagL/S1uOXno3o0fQtX7yu2mcqUt96z X-Received: by 2002:a05:6402:1587:: with SMTP id c7mr13310452edv.61.1587886029729; Sun, 26 Apr 2020 00:27:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587886029; cv=none; d=google.com; s=arc-20160816; b=k6AtE5hXcqMYil/nAwN+1wSCcZ+GpX7BKPxSnzw/t5poXWPMOhZaYBi37C7AaNU+xh 5Ex3XUl2GwvQN5NIhEluhAHBqYoka3XPTm0cYw9qWIesZQ4XLRLokoOUDIhRzcs0JZB2 cWieaPyzT6C0FkzHPR7D83maFfgf6y5IKI2EzDD+mJNSDxuV0ismHJZ35Wc/sRz1X51y jsiqviq1uCgTZOUf9kmnBkIfyE6Gz2QFn/5sS4THBLgJ9bqAhHmASx7sePgJNoUvsz24 61//Hv2SiXIQbR9nkHrNY8WnCLqfiQiBZ+VDX8f+WwMDNPyZngnNUlAlrMOajqT834P5 S19g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=61EB29D4gsydfyLZ6zmlIGUCBWAxn58DY2mudslCfeQ=; b=x1C+FHMRdhwY42OYs/HsunZ5z4ESFk2pTuyeg69CjCYDIcbL+psDiEXAHVaKcZXTAA V7BuiNl3kYFIptunhs6GtfyEpRauFM4Ti5XoHtixlHbKsxTOs1veCCpc+wuKaMi//+Kn 5AkbzrVLouZQGQxf4bM5LgS1QZ3fBKhJmwE74O8Ou4dGN9RC8X/cBcDQDyfuvQZIcSYJ 6I+74nNeclBs2Xv0TFOMwWKnqvwZ9cV/Re+PEQlhPeWpopdFYI8VvD6axnGhuzm4s+1s dhHGnX/J2Akw8DZgrTSG+orcW64s6Zs+Wfo3ncyFZ6KgPVPhWbOzeUZD2UEDqIbqj5Ya BgkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gljatc4u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l26si5840578eje.378.2020.04.26.00.26.46; Sun, 26 Apr 2020 00:27:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gljatc4u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726147AbgDZGxf (ORCPT + 99 others); Sun, 26 Apr 2020 02:53:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:55584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725864AbgDZGxe (ORCPT ); Sun, 26 Apr 2020 02:53:34 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 63F1B206B6; Sun, 26 Apr 2020 06:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587884014; bh=AX72LrszXZVr3GndLIzHGcqKzv1x/vpPvEudF3/4TvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gljatc4u33OL5OuVaTllZP9PkbFfwTwkMAavfoa1DUFT1JAWb5UcpFBLjl1daoEJC euW/AlmgKN/fS9xkDkCfGsXO7Vr20FZ/KpbVFWxJWWZ1DsbAyAKUpuC4FmG/xMgy2H 2IXB54siLdZtgYVxLNS6k7btgpKOz78DbuUtkGTY= From: Masami Hiramatsu To: Steven Rostedt Cc: Borislav Petkov , Kees Cook , LKML , Ingo Molnar , Andrew Morton , Masami Hiramatsu Subject: [BUGFIX PATCH v2 1/1] bootconfig: Fix to remove bootconfig data from initrd while boot Date: Sun, 26 Apr 2020 15:53:30 +0900 Message-Id: <158788401014.24243.17424755854115077915.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200424195833.1487a1a0@oasis.local.home> References: <20200424195833.1487a1a0@oasis.local.home> User-Agent: StGit/0.17.1-dirty 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 If there is a bootconfig data in the tail of initrd/initramfs, initrd image sanity check caused an error while decompression stage as follows. [ 0.883882] Unpacking initramfs... [ 2.696429] Initramfs unpacking failed: invalid magic at start of compressed archive This error will be ignored if CONFIG_BLK_DEV_RAM=n, but CONFIG_BLK_DEV_RAM=y the kernel failed to mount rootfs and causes a panic. To fix this issue, shrink down the initrd_end for removing tailing bootconfig data while boot the kernel. Fixes: 7684b8582c24 ("bootconfig: Load boot config from the tail of initrd") Signed-off-by: Masami Hiramatsu Cc: stable@vger.kernel.org --- Changes in v2: - Make new functions __init. - Do nothing if CONFIG_BLK_DEV_INITRD=n --- init/main.c | 69 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/init/main.c b/init/main.c index 295aec3a1a7a..f55cb15f23d2 100644 --- a/init/main.c +++ b/init/main.c @@ -258,6 +258,47 @@ 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) +{ + u32 size, csum; + char *data; + u32 *hdr; + + if (!initrd_end) + return NULL; + + data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN; + if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN)) + return NULL; + + hdr = (u32 *)(data - 8); + size = hdr[0]; + csum = hdr[1]; + + data = ((void *)hdr) - size; + if ((unsigned long)data < initrd_start) { + pr_err("bootconfig size %d is greater than initrd size %ld\n", + size, initrd_end - initrd_start); + 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) +{ + return NULL; +} +#endif + #ifdef CONFIG_BOOT_CONFIG char xbc_namebuf[XBC_KEYLEN_MAX] __initdata; @@ -358,9 +399,12 @@ static void __init setup_boot_config(const char *cmdline) int pos; u32 size, csum; char *data, *copy; - u32 *hdr; int ret; + data = get_boot_config_from_initrd(&size, &csum); + if (!data) + goto not_found; + strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE); parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL, bootconfig_params); @@ -368,27 +412,12 @@ static void __init setup_boot_config(const char *cmdline) if (!bootconfig_found) return; - if (!initrd_end) - goto not_found; - - data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN; - if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN)) - goto not_found; - - hdr = (u32 *)(data - 8); - size = hdr[0]; - csum = hdr[1]; - if (size >= XBC_DATA_MAX) { pr_err("bootconfig size %d greater than max size %d\n", size, XBC_DATA_MAX); return; } - data = ((void *)hdr) - size; - if ((unsigned long)data < initrd_start) - goto not_found; - if (boot_config_checksum((unsigned char *)data, size) != csum) { pr_err("bootconfig checksum failed\n"); return; @@ -421,8 +450,14 @@ static void __init setup_boot_config(const char *cmdline) not_found: pr_err("'bootconfig' found on command line, but no bootconfig found\n"); } + #else -#define setup_boot_config(cmdline) do { } while (0) + +static void __init setup_boot_config(const char *cmdline) +{ + /* Remove bootconfig data from initrd */ + get_boot_config_from_initrd(NULL, NULL); +} static int __init warn_bootconfig(char *str) {