FAILED: patch "[PATCH] tools/bootconfig: Fix integer overflow and truncation in size" failed to apply to 6.12-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 462d0b066b613103f579793031429db2ca23abc0
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026091614-overstock-purist-0d71@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 462d0b066b613103f579793031429db2ca23abc0 Mon Sep 17 00:00:00 2001
From: "Masami Hiramatsu (Google)" <[email protected]>
Date: Fri, 11 Sep 2026 00:15:24 +0900
Subject: [PATCH] tools/bootconfig: Fix integer overflow and truncation in size
checks
Sashiko reported that on 32-bit systems, if an attacker crafts size in the bootconfig footer such that adding BOOTCONFIG_FOOTER_SIZE wraps around (for instance, if size is 0xFFFFFFFF), the size check in load_xbc_from_initrd() can be bypassed:
if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
pr_err("bootconfig size is too big\n");
return -E2BIG;
}Furthermore, on 64-bit systems with an initrd > 4.29 GB, comparing a corrupted 32-bit size (e.g. 0xFFFFFFFF) against
stat.st_size - BOOTCONFIG_FOOTER_SIZE can also bypass the check if size is not bounded. Similarly, load_xbc_file() passes 64-bit stat.st_size directly into the 32-bit int size parameter of load_xbc_fd(), truncating large standalone files (>= 2GB).
In both cases, passing 0xFFFFFFFF to load_xbc_fd() truncates to -1, resulting in malloc(0), an integer overflow in read(), and an out-of-bounds null-byte write.
Fix this by:
1. Rejecting size > XBC_DATA_MAX or
size > stat.st_size - BOOTCONFIG_FOOTER_SIZE in load_xbc_from_initrd().
2. Rejecting stat.st_size > XBC_DATA_MAX in load_xbc_file() before passing it to load_xbc_fd().
3. Checking size < 0 || size > XBC_DATA_MAX defensively in load_xbc_fd().
tools/bootconfig/main.c +12 -1
@@ -140,6 +140,9 @@ static int load_xbc_fd(int fd, char **buf, int size) {int ret; +if (size <0 || size >XBC_DATA_MAX ) +return -EINVAL ; + *buf =malloc (size +1 );if (!*buf)return -ENOMEM ;
@@ -168,6 +171,13 @@ static int load_xbc_file(const char *path, char **buf)return ret; } +if (stat.st_size >XBC_DATA_MAX ) { +pr_err ("%s size is too big\n" , path); + ret = -E2BIG ; +close (fd); +return ret; + } + ret =load_xbc_fd (fd, buf, stat.st_size);close (fd);
@@ -218,7 +228,8 @@ static int load_xbc_from_initrd(int fd, char **buf) csum =le32toh (csum);/* Wrong size error */ -if (stat.st_size < size +BOOTCONFIG_FOOTER_SIZE ) { +if (size >XBC_DATA_MAX || + size > stat.st_size -BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ; }
Sasha Levin
maintainerPATCH 1/2 tools/bootconfig: Cleanup bootconfig footer size calculations
From: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit 26dda57695090e05c1a99c3e8f802f862d1ac474 ]
There are many same pattern of 8 + BOOTCONFIG_MAGIC_LEN for calculating the size of bootconfig footer. Use BOOTCONFIG_FOOTER_SIZE macro to clean up those magic numbers.
Stable-dep-of: 462d0b066b61 ("tools/bootconfig: Fix integer overflow and truncation in size checks")
--- tools/bootconfig/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
tools/bootconfig/main.c +11 -8
@@ -16,6 +16,10 @@#define pr_err (fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) +/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */ +#define BOOTCONFIG_FOOTER_SIZE \ + (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN) +static int xbc_show_value (struct xbc_node *node,bool semicolon) {const char *val, *eol;
@@ -188,7 +192,7 @@ static int load_xbc_from_initrd(int fd, char **buf)if (ret <0 )return -errno; -if (stat.st_size <8 +BOOTCONFIG_MAGIC_LEN ) +if (stat.st_size <BOOTCONFIG_FOOTER_SIZE )return 0 ;if (lseek (fd, -BOOTCONFIG_MAGIC_LEN ,SEEK_END ) <0 )
@@ -201,7 +205,7 @@ static int load_xbc_from_initrd(int fd, char **buf)if (memcmp (magic,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN ) !=0 )return 0 ; -if (lseek (fd, -(8 +BOOTCONFIG_MAGIC_LEN ),SEEK_END ) <0 ) +if (lseek (fd, -BOOTCONFIG_FOOTER_SIZE ,SEEK_END ) <0 )return pr_errno ("Failed to lseek for size" , -errno);if (read (fd, &size,sizeof (uint32_t )) <0 )
@@ -213,12 +217,12 @@ static int load_xbc_from_initrd(int fd, char **buf) csum =le32toh (csum);/* Wrong size error */ -if (stat.st_size < size +8 +BOOTCONFIG_MAGIC_LEN ) { +if (stat.st_size < size +BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ; } -if (lseek (fd, stat.st_size - (size +8 +BOOTCONFIG_MAGIC_LEN ), +if (lseek (fd, stat.st_size - (size +BOOTCONFIG_FOOTER_SIZE ),SEEK_SET ) <0 )return pr_errno ("Failed to lseek" , -errno);
@@ -349,7 +353,7 @@ static int delete_xbc(const char *path) ret =fstat (fd, &stat);if (!ret) ret =ftruncate (fd, stat.st_size - - size -8 -BOOTCONFIG_MAGIC_LEN ); + - size -BOOTCONFIG_FOOTER_SIZE );if (ret) ret = -errno; }/* Ignore if there is no boot config in initrd */
@@ -379,8 +383,7 @@ static int apply_xbc(const char *path, const char *xbc_path) csum =xbc_calc_checksum (buf, size);/* Backup the bootconfig data */ - data =calloc (size +BOOTCONFIG_ALIGN + -sizeof (uint32_t ) +sizeof (uint32_t ) +BOOTCONFIG_MAGIC_LEN ,1 ); + data =calloc (size +BOOTCONFIG_ALIGN +BOOTCONFIG_FOOTER_SIZE ,1 );if (!data)return -ENOMEM ;memcpy (data, buf, size);
@@ -428,7 +431,7 @@ static int apply_xbc(const char *path, const char *xbc_path) }/* To align up the total size to BOOTCONFIG_ALIGN, get padding size */ - total_size = stat.st_size + size +sizeof (uint32_t ) *2 +BOOTCONFIG_MAGIC_LEN ; + total_size = stat.st_size + size +BOOTCONFIG_FOOTER_SIZE ; pad = ((total_size +BOOTCONFIG_ALIGN -1 ) & (~BOOTCONFIG_ALIGN_MASK )) - total_size; size += pad;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 tools/bootconfig: Fix integer overflow and truncation in size checks
From: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit 462d0b066b613103f579793031429db2ca23abc0 ]
Sashiko reported that on 32-bit systems, if an attacker crafts size in the bootconfig footer such that adding BOOTCONFIG_FOOTER_SIZE wraps around (for instance, if size is 0xFFFFFFFF), the size check in load_xbc_from_initrd() can be bypassed:
if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
pr_err("bootconfig size is too big\n");
return -E2BIG;
}Furthermore, on 64-bit systems with an initrd > 4.29 GB, comparing a corrupted 32-bit size (e.g. 0xFFFFFFFF) against
stat.st_size - BOOTCONFIG_FOOTER_SIZE can also bypass the check if size is not bounded. Similarly, load_xbc_file() passes 64-bit stat.st_size directly into the 32-bit int size parameter of load_xbc_fd(), truncating large standalone files (>= 2GB).
In both cases, passing 0xFFFFFFFF to load_xbc_fd() truncates to -1, resulting in malloc(0), an integer overflow in read(), and an out-of-bounds null-byte write.
Fix this by:
1. Rejecting size > XBC_DATA_MAX or
size > stat.st_size - BOOTCONFIG_FOOTER_SIZE in load_xbc_from_initrd().
2. Rejecting stat.st_size > XBC_DATA_MAX in load_xbc_file() before passing it to load_xbc_fd().
3. Checking size < 0 || size > XBC_DATA_MAX defensively in load_xbc_fd().
--- tools/bootconfig/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
tools/bootconfig/main.c +12 -1
@@ -139,6 +139,9 @@ static int load_xbc_fd(int fd, char **buf, int size) {int ret; +if (size <0 || size >XBC_DATA_MAX ) +return -EINVAL ; + *buf =malloc (size +1 );if (!*buf)return -ENOMEM ;
@@ -167,6 +170,13 @@ static int load_xbc_file(const char *path, char **buf)return ret; } +if (stat.st_size >XBC_DATA_MAX ) { +pr_err ("%s size is too big\n" , path); + ret = -E2BIG ; +close (fd); +return ret; + } + ret =load_xbc_fd (fd, buf, stat.st_size);close (fd);
@@ -217,7 +227,8 @@ static int load_xbc_from_initrd(int fd, char **buf) csum =le32toh (csum);/* Wrong size error */ -if (stat.st_size < size +BOOTCONFIG_FOOTER_SIZE ) { +if (size >XBC_DATA_MAX || + size > stat.st_size -BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ; }
Signature · 1 line
2.53.0