summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>2026-09-11 23:13:06 +0900
committerAndrew Morton <akpm@linux-foundation.org>2026-09-13 21:33:42 -0700
commit4837362583347989050a3b1f65dbff6059590a64 (patch)
tree38bf6012dc0ef1814f2038ce8237acadff612868 /lib
parent5271eb8b27ac5673d3f066ecbbfa61bc0467f6dd (diff)
downloadlinux-next-4837362583347989050a3b1f65dbff6059590a64.tar.gz
linux-next-4837362583347989050a3b1f65dbff6059590a64.zip
bootconfig: reject unexpected data after null character
Patch series "bootconfig: Reject unexpected data after null character and cleanups", v2. Make bootconfig reject unexpected config data after null character and implement other cleanups including tools/bootconfig to consolidate bootconfig initialization with errors, and to skip internal tree sanity checks in kernel. This patch (of 4): If a bootconfig buffer contains an intermediate null character in the middle of the configuration, xbc_parse_tree() stops at the null character because string delimiter searches (e.g. strpbrk()) stop at '\0', and cleanly breaks out of the loop without error. As a result, any configuration data following the intermediate null character is silently ignored, allowing unparsed or potentially malicious data to be hidden after an early termination. Fix this in xbc_parse_tree() by checking that no non-null data remains between the parser termination point and the end of the input buffer. Trailing null characters (such as alignment padding in initrd) continue to be accepted as valid. Also update apply_xbc() in tools/bootconfig/main.c to calculate the buffer size based on the loaded file size rather than strlen(), so that files with intermediate null characters are not truncated before validation. Assisted-by: Antigravity:gemini-3.8-flash Link: https://lore.kernel.org/178913597653.248794.1237187523153227751.stgit@devnote2 Link: https://lore.kernel.org/178913598628.248794.1048773774471250986.stgit@devnote2 Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Sang-Heon Jeon <ekffu200098@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/bootconfig.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index f248b5770291..b6adf8b27474 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -1118,6 +1118,13 @@ static int __init xbc_parse_tree(void)
}
} while (!ret);
+ if (!ret) {
+ while (p < xbc_data + xbc_data_size - 1 && *p == '\0')
+ p++;
+ if (p < xbc_data + xbc_data_size - 1)
+ ret = xbc_parse_error("Unexpected data after null character", p);
+ }
+
return ret;
}