From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Sun Jian <sun.jian.kdev@gmail.com>,
Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y 1/2] init/main: read bootconfig header with get_unaligned_le32()
Date: Wed, 16 Sep 2026 15:27:54 -0400 [thread overview]
Message-ID: <20260916192755.2146743-1-sashal@kernel.org> (raw)
In-Reply-To: <2026091615-curry-barracuda-b99e@gregkh>
From: Sun Jian <sun.jian.kdev@gmail.com>
[ Upstream commit 499f86de4f8c34e19a57daf2b6f0cba848e91994 ]
get_boot_config_from_initrd() scans up to 3 bytes before initrd_end to
handle GRUB 4-byte alignment. As a result, the bootconfig header
immediately preceding the magic may be unaligned.
Read the size and checksum fields with get_unaligned_le32() instead of
casting to u32 * and using le32_to_cpu(), avoiding potential unaligned
access and silencing sparse "cast to restricted __le32" warnings.
Sparse warnings (gcc + C=1):
init/main.c:292:16: warning: cast to restricted __le32
init/main.c:293:16: warning: cast to restricted __le32
No functional change intended.
Link: https://lkml.kernel.org/r/20260113101532.1630770-1-sun.jian.kdev@gmail.com
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: 7812d6dab069 ("bootconfig: Fix integer overflow in initrd size check")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
init/main.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/init/main.c b/init/main.c
index e3ef1eb34aa3e..b254678062c72 100644
--- a/init/main.c
+++ b/init/main.c
@@ -104,6 +104,7 @@
#include <linux/pidfs.h>
#include <linux/ptdump.h>
#include <linux/time_namespace.h>
+#include <linux/unaligned.h>
#include <net/net_namespace.h>
#include <asm/io.h>
@@ -269,7 +270,7 @@ static void * __init get_boot_config_from_initrd(size_t *_size)
{
u32 size, csum;
char *data;
- u32 *hdr;
+ u8 *hdr;
int i;
if (!initrd_end)
@@ -288,9 +289,9 @@ static void * __init get_boot_config_from_initrd(size_t *_size)
return NULL;
found:
- hdr = (u32 *)(data - 8);
- size = le32_to_cpu(hdr[0]);
- csum = le32_to_cpu(hdr[1]);
+ hdr = (u8 *)(data - 8);
+ size = get_unaligned_le32(hdr);
+ csum = get_unaligned_le32(hdr + 4);
data = ((void *)hdr) - size;
if ((unsigned long)data < initrd_start) {
--
2.53.0
next prev parent reply other threads:[~2026-09-16 19:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 15:15 FAILED: patch "[PATCH] bootconfig: Fix integer overflow in initrd size check" failed to apply to 6.18-stable tree gregkh
2026-09-16 19:27 ` Sasha Levin [this message]
2026-09-16 19:27 ` [PATCH 6.18.y 2/2] bootconfig: Fix integer overflow in initrd size check Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260916192755.2146743-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=mingo@kernel.org \
--cc=stable@vger.kernel.org \
--cc=sun.jian.kdev@gmail.com \
--cc=tglx@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox