Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3867785pxb; Tue, 17 Nov 2020 05:47:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoj+KyvnMqMw6jwH/M56kWzFUWxUx2U4S6P8pRSvIPEmx555wLDpeSorcXM3ftCGiEF0vq X-Received: by 2002:a17:906:55d1:: with SMTP id z17mr20050853ejp.128.1605620844914; Tue, 17 Nov 2020 05:47:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605620844; cv=none; d=google.com; s=arc-20160816; b=JudMtOUD2Vkvt2gh84e4JnIriEuhJaaa2rYMARbbzi5CIfFakoy/TSUtkL99QdCjx9 B6rwcyIzuHg2kmeA78SJPDZKLELaFEy2NevI6h/P/6D3/XqbpqAYosV+Powi3omKiz8B eScrRoiMNs4D+zD4L48Ty+wCIiID+IFJ3iOujqY9uVemyEdWst5KfWy0hRarK8PP40bE FvxlP+QKNNCaDFmbWcdY7LHd74FuicCclDDO4cPOz7Riz2RbcVphNhXuhiMvEnkelDRQ WfZ6xcohlcNrxYl6EHonfxmwTaj3Ks+5bCJI6Y2MgkTEJVl5CWQow9uXx365QedtXP4t Ld4Q== 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=MAnP2TWavrLNRhx8fvn938ZpEMjJE1LPtASjka/uZjc=; b=WNS+MXPQZL7CvZO50ySoIDKMO/qd6LTb04yJkTK30S7HbADLtV0Gg8KnLSg/Z8MTAz UaYCf7nqr2LOZQIc0Bokk295nZxc+9kz+8EqzPy4hUDPYk6beShVgxEKj6sWDqViaIN7 hJ37bgVoLjHKSYFcx3a6XBX3+kSio00OOxE+/OrZCu3hZaLiYPFTHTQc5KWsLuI2P3yX fgPYCscwjFOHSoAJLJPb41eMLpfaQV/JouvgJ/E1gUsm01G3Pe/wotw8F3p7fsk3z2I3 sffnxhFu661aOIxS4socTxjqNCwFVX0HyLM06zThh2oC6CaQDstpZzoquJTI7zaymYkw 0ZFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gLcMKfyu; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si14360354edq.430.2020.11.17.05.47.01; Tue, 17 Nov 2020 05:47:24 -0800 (PST) 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=gLcMKfyu; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733177AbgKQNoq (ORCPT + 99 others); Tue, 17 Nov 2020 08:44:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:51990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732806AbgKQNkJ (ORCPT ); Tue, 17 Nov 2020 08:40:09 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3B38E207BC; Tue, 17 Nov 2020 13:40:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620408; bh=aeWeB7GhISJbMU5/XDoRIlrYHmcH3VZQgdT6UK1SHt0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gLcMKfyuvZhYVtjqXhEda7n/1f0tYjsAJuiQOntGS4B1bXU7Sxw1sYI85gzCUzipo wsm+iuUdd4yN/DG8qbTyQ3YEdD/2FKovaZBAJWPh0yM6IyK3wJyKot51uws57GWqBb SIQvSLw3j98hKGw+pGsTrcXEN11QmacnqoJnw+SE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chen Yu , Masami Hiramatsu , "Steven Rostedt (VMware)" Subject: [PATCH 5.9 208/255] bootconfig: Extend the magic check range to the preceding 3 bytes Date: Tue, 17 Nov 2020 14:05:48 +0100 Message-Id: <20201117122149.056573069@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masami Hiramatsu commit 50b8a742850fce7293bed45753152c425f7e931b upstream. Since Grub may align the size of initrd to 4 if user pass initrd from cpio, we have to check the preceding 3 bytes as well. Link: https://lkml.kernel.org/r/160520205132.303174.4876760192433315429.stgit@devnote2 Cc: stable@vger.kernel.org Fixes: 85c46b78da58 ("bootconfig: Add bootconfig magic word for indicating bootconfig explicitly") Reported-by: Chen Yu Tested-by: Chen Yu Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- init/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/init/main.c +++ b/init/main.c @@ -267,14 +267,24 @@ static void * __init get_boot_config_fro u32 size, csum; char *data; u32 *hdr; + int i; if (!initrd_end) return NULL; data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN; - if (memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN)) - return NULL; + /* + * Since Grub may align the size of initrd to 4, we must + * check the preceding 3 bytes as well. + */ + for (i = 0; i < 4; i++) { + if (!memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN)) + goto found; + data--; + } + return NULL; +found: hdr = (u32 *)(data - 8); size = hdr[0]; csum = hdr[1];