From nobody Fri Sep 25 13:53:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2806633BBC0; Fri, 11 Sep 2026 14:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789135991; cv=none; b=QwMOF8LtqFN6dquyB4ZdiXtJs0NZE22SSnqkYpGVbWCP7hpqDXH6TB+hrZP1qrq+Qjatfi2Y+p3lx92ap4Jq33Nb6XiTSIKOvynnDmN6+//WEeJ09nyd0L8Bo1YwCHKmWCAHbjdGBP4FvuaXJHl62Q7qs22KB2UMsYgkC8Hh1EI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789135991; c=relaxed/simple; bh=VmLDgc8FVwCH7jfA1bK7WOgcB3UTbmunEsoUbXc5vCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e2xvSHGdTtXsF+7N9NNas3wUisYhwg49CWdv4V+LsMShfe+3NKPBDgkvFh6pVdCNSxidhf28DgUJBlGbrtWH9nnrcg/LPKzWtA43OBZ/w9NlpRXq5TpV+eGoLNLKPM/dW9QkZmbnBaQE+ipIznonnkbUzefBMyPaISYuR/T+yQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h96ZLCnX; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h96ZLCnX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 717BB1F008A2; Fri, 11 Sep 2026 14:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789135989; bh=mSgtp3Oo1RMv/XNAhQwl71O3GqsJP7J7NxfICduxt3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=h96ZLCnXcBiPd3a7J4hu9EhKZIH5/dyEAi9sA0WhjI/Ccti0br7B08lqrLgSwhzJb CgEshrwBgNGdiU8xHAm3t/T50vik4Za9TaBhEuapxu+uDJro6Gd+Hhig7Jn7h1xavo pjo4At2NcAHKDqJuLiLjQ0O+a2hlu+C5T2SEEYV6x+vsI4ZIp49UVP/4rXPh/dklL/ Bgp85ljH1RvUA4ICYtdrC1omTMncbseNh5vG0b7Q67JkaGLjWRiH8k3l8hRPNPU51h 0udvn9ZMgmv+B/4sw96rM/34f5ZFuy50w5QyyhRpqYZnOgb3cQJq1zFzXvE47V/WEX 2aaMHceYra4aw== From: "Masami Hiramatsu (Google)" To: Andrew Morton , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Sang-Heon Jeon Subject: [PATCH v2 1/4] bootconfig: Reject unexpected data after null character Date: Fri, 11 Sep 2026 23:13:06 +0900 Message-ID: <178913598628.248794.1048773774471250986.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <178913597653.248794.1237187523153227751.stgit@devnote2> References: <178913597653.248794.1237187523153227751.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) 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 Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Sang-Heon Jeon --- lib/bootconfig.c | 7 +++++++ tools/bootconfig/main.c | 4 +++- tools/bootconfig/test-bootconfig.sh | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 89c88e359179..61cae6d6e3f8 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -1119,6 +1119,13 @@ static int __init xbc_parse_tree(void) } } while (!ret); =20 + if (!ret) { + while (p < xbc_data + xbc_data_size - 1 && *p =3D=3D '\0') + p++; + if (p < xbc_data + xbc_data_size - 1) + ret =3D xbc_parse_error("Unexpected data after null character", p); + } + return ret; } =20 diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 17d971d47f87..aff169ba75b8 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -433,7 +433,9 @@ static int apply_xbc(const char *path, const char *xbc_= path) pr_err("Failed to load %s : %d\n", xbc_path, ret); return ret; } - size =3D strlen(buf) + 1; + size =3D ret; + if (size =3D=3D 0 || buf[size - 1] !=3D '\0') + size++; csum =3D xbc_calc_checksum(buf, size); =20 /* Backup the bootconfig data */ diff --git a/tools/bootconfig/test-bootconfig.sh b/tools/bootconfig/test-bo= otconfig.sh index fc69f815ce4a..530ce7e28d63 100755 --- a/tools/bootconfig/test-bootconfig.sh +++ b/tools/bootconfig/test-bootconfig.sh @@ -180,6 +180,18 @@ EOF $BOOTCONF -a $TEMPCONF $INITRD 2> $OUTFILE xpass grep -q "1:1" $OUTFILE =20 +echo "Intermediate null character test" +printf "key =3D value\n\0extra =3D data\n" > $TEMPCONF +xfail $BOOTCONF -a $TEMPCONF $INITRD +$BOOTCONF -a $TEMPCONF $INITRD 2> $OUTFILE +xpass grep -q "Unexpected" $OUTFILE + +echo "Trailing null character test" +printf "key =3D value\n\0" > $TEMPCONF +xpass $BOOTCONF -a $TEMPCONF $INITRD +$BOOTCONF $INITRD > $OUTFILE +xpass grep -q "value" $OUTFILE + echo "=3D=3D=3D expected failure cases =3D=3D=3D" for i in samples/bad-* ; do xfail $BOOTCONF -a $i $INITRD From nobody Fri Sep 25 13:53:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27BE7345EB5; Fri, 11 Sep 2026 14:13:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789136001; cv=none; b=tH8dV7IeWTgGnC0zXUjfo1+YJsGUE2YJiyic8AGE8XmmGyDpkylYrVtBrosgKM+B+iaA6rf9vHOXRtspxKoSdax16HP5gYosT6Ap12nzNLENQksw6UNGl6yenuwD2gbmI3AnGMjxDj/BFhdRRvtJ3/EYAYJlFIcgCut5Yqppb5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789136001; c=relaxed/simple; bh=RpGhfmje8DtH4utSvgsNEPl0BOr3tnmw3jdfbnBUi28=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ON4GayGaTTIzUJ2PpcbGz8wxGm/nNm3iKQrDaCAxXp2BmicRmXJGM97ci+9AtqZhGrljJ4ipCTNQZiybjKFAwOx6J99ixXdk7a5xkn1QbYYn7v0N2uAJnZZvxToTDDuGwcFmpveipE/PWybNx9+P/DIueHypVMWxla/g3q+/iYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NKJIR5/n; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NKJIR5/n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BFEF1F008A2; Fri, 11 Sep 2026 14:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789135998; bh=fl2Id8u8e/0eGxzUx0pnL/Xk1CZne/k9PIjfKtGd7ZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NKJIR5/nl8HqQcWp9JTQSFX/afUCf3z+Foj/JuOuONreSrbSlcfvpIMOZbdoK/ENA nZKiLIiT8rYbrePcZNHSqieUsemRcfpGSbBUU03qyR/YbfgU2Jrh0w27pAM8byT41I fhtQ3cfZDapKcTxDBRNXPjLO91QeKp3W0JlGlWwkLkrMFMWQIADmKam7EYcOSdtAYm C3Y5bapNJym35vSsfn7dfSXZJy/LiQ+HJqzz3LixZrmjGIwR1qxj1+zRfrGU5EpWtv qkAxl4eBmk5TEGqCjaB6AqXC6N2QL3PZYFRG71heW1vBfLrNwC81+mx4ZqpJ8ON2nY yjcmrB5q830Hw== From: "Masami Hiramatsu (Google)" To: Andrew Morton , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Sang-Heon Jeon Subject: [PATCH v2 2/4] tools/bootconfig: Consolidate xbc_init() to error message wrapper Date: Fri, 11 Sep 2026 23:13:15 +0900 Message-ID: <178913599508.248794.10388592925402087434.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <178913597653.248794.1237187523153227751.stgit@devnote2> References: <178913597653.248794.1237187523153227751.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) Use init_xbc_with_error() for all bootconfig initialization in the bootconfig tool instead of showing errors in different way. This simplifies the code logic and make it easy to maintain. Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Sang-Heon Jeon --- Changes in v2: - Remove redundant buffer copy in init_xbc_with_error(). --- tools/bootconfig/main.c | 100 ++++++++++++++++++++-----------------------= ---- 1 file changed, 43 insertions(+), 57 deletions(-) diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index aff169ba75b8..652e491b9c33 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -21,6 +21,39 @@ #define BOOTCONFIG_FOOTER_SIZE \ (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN) =20 +static void show_xbc_error(const char *data, const char *msg, int pos) +{ + int lin =3D 1, col, i; + + if (pos < 0) { + pr_err("Error: %s.\n", msg); + return; + } + + /* Note that pos starts from 0 but lin and col should start from 1. */ + col =3D pos + 1; + for (i =3D 0; i < pos; i++) { + if (data[i] =3D=3D '\n') { + lin++; + col =3D pos - i; + } + } + pr_err("Parse Error: %s at %d:%d\n", msg, lin, col); + +} + +static int init_xbc_with_error(char *buf, int len) +{ + const char *msg; + int ret, pos; + + ret =3D xbc_init(buf, len, &msg, &pos); + if (ret < 0) + show_xbc_error(buf, msg, pos); + + return ret; +} + static int xbc_show_value(struct xbc_node *node, bool semicolon) { const char *val, *eol; @@ -197,7 +230,6 @@ static int load_xbc_from_initrd(int fd, char **buf) int ret; uint32_t size =3D 0, csum =3D 0, rcsum; char magic[BOOTCONFIG_MAGIC_LEN]; - const char *msg; =20 ret =3D fstat(fd, &stat); if (ret < 0) @@ -249,52 +281,9 @@ static int load_xbc_from_initrd(int fd, char **buf) return -EINVAL; } =20 - ret =3D xbc_init(*buf, size, &msg, NULL); - /* Wrong data */ - if (ret < 0) { - pr_err("parse error: %s.\n", msg); - return ret; - } - - return size; -} - -static void show_xbc_error(const char *data, const char *msg, int pos) -{ - int lin =3D 1, col, i; - - if (pos < 0) { - pr_err("Error: %s.\n", msg); - return; - } - - /* Note that pos starts from 0 but lin and col should start from 1. */ - col =3D pos + 1; - for (i =3D 0; i < pos; i++) { - if (data[i] =3D=3D '\n') { - lin++; - col =3D pos - i; - } - } - pr_err("Parse Error: %s at %d:%d\n", msg, lin, col); + ret =3D init_xbc_with_error(*buf, size); =20 -} - -static int init_xbc_with_error(char *buf, int len) -{ - char *copy =3D strdup(buf); - const char *msg; - int ret, pos; - - if (!copy) - return -ENOMEM; - - ret =3D xbc_init(buf, len, &msg, &pos); - if (ret < 0) - show_xbc_error(copy, msg, pos); - free(copy); - - return ret; + return ret < 0 ? ret : size; } =20 static int show_xbc_kernel_cmdline(void) @@ -423,9 +412,8 @@ static int apply_xbc(const char *path, const char *xbc_= path) char *buf, *data; size_t total_size; struct stat stat; - const char *msg; uint32_t size, csum; - int pos, pad; + int pad; int ret, fd; =20 ret =3D load_xbc_file(xbc_path, &buf); @@ -438,6 +426,13 @@ static int apply_xbc(const char *path, const char *xbc= _path) size++; csum =3D xbc_calc_checksum(buf, size); =20 + /* Verify the data format */ + ret =3D init_xbc_with_error(buf, size); + if (ret < 0) { + free(buf); + return ret; + } + /* Backup the bootconfig data */ data =3D calloc(size + BOOTCONFIG_ALIGN + BOOTCONFIG_FOOTER_SIZE, 1); if (!data) { @@ -446,15 +441,6 @@ static int apply_xbc(const char *path, const char *xbc= _path) } memcpy(data, buf, size); =20 - /* Check the data format */ - ret =3D xbc_init(buf, size, &msg, &pos); - if (ret < 0) { - show_xbc_error(data, msg, pos); - free(data); - free(buf); - - return ret; - } printf("Apply %s to %s\n", xbc_path, path); xbc_get_info(&ret, NULL); printf("\tNumber of nodes: %d\n", ret); From nobody Fri Sep 25 13:53:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2173835950; Fri, 11 Sep 2026 14:13:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789136009; cv=none; b=WOIwqwiPp14rjDLbEUDxGQiFThjFp6vAs64Ckud64u3f4MIl/JKbt3uivh7BuacppQOlFl6rwjvTFY/J0p5G3esnIcosPo15YbOxkXEyEFQ6FUx8UrFTjUkzYi5iLHNxoHUruj0vJn1/jD5ddcFkJGYHvbD+ue7y2wJgiTXoTnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789136009; c=relaxed/simple; bh=gaQ5Xs18z39QaJwI9yW27cWzRZ5tq/OyB+9wrAfaws0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HbN1AGUdL6JqcNKZTqJ/aoRCrkia8SxF+1touUr2VFLQfiZupOjoXoaFRMbWzEWOPvNF5L0jfwiSmE4O5bK/yV59K8K8yRDls0U/lPEDTY6TVhtWSFngZuw/ngPntj1Y0t5wm0ZQmi3JdbYwTuzq9/JhUz3gwaLv/BVg5jtYLhc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eqkP9GEr; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eqkP9GEr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DB8F1F008A2; Fri, 11 Sep 2026 14:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789136007; bh=/HV0MLuSBgaL1qmMEBUkUTq3L2F/ZFCkWyKIdA3nReA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eqkP9GEruSBlvtmbGkL7qPBurTs91QbfUWPdGC97TW+KsJHXT62weW0bZIxFx94lK Cahw1Zz/P4CKmuVODHRG4EIeGzfYwr/rko5YGPIlKVXKmObVL2FaiPr25fDkgtQvyL Et63Edj5jqQ4EW1lDjLtZpDihUDjybEvxrbBKxxfMh0Vf2Er3AOjG+7SX1i639pDRI QVzHHgSKqausbQNOP8eT4twx3UHwhsVEFGqVP2UHmyPq3jykUtphmVRejT3wRqiVqd IVP+xsjQE3ZoAb5qTYUUp/bH5UNgv6NbLoTo7C/yVhbFMsmUoEDD/0MdZL9yLXVT9d FgAw0SKrfQLWw== From: "Masami Hiramatsu (Google)" To: Andrew Morton , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Sang-Heon Jeon Subject: [PATCH v2 3/4] bootconfig: Skip internal tree sanity checks in kernel Date: Fri, 11 Sep 2026 23:13:24 +0900 Message-ID: <178913600409.248794.12941798680046327623.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <178913597653.248794.1237187523153227751.stgit@devnote2> References: <178913597653.248794.1237187523153227751.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) In xbc_verify_tree(), the loop iterating through all nodes to check that xbc_nodes[i].next < xbc_node_num and xbc_nodes[i].child < xbc_node_num is a defensive sanity check against implementation regressions (such an out-of-bounds index cannot be produced by malformed input). Running this check in the kernel adds unnecessary boot-time overhead. Split this check out into xbc_sanity_check_tree() for userspace, so that it continues to run during userspace bootconfig validation (e.g. when applying or testing bootconfig with tools/bootconfig), but is omitted in the kernel to speed up initialization. Reported-by: Sang-Heon Jeon Closes: https://lore.kernel.org/all/20260905141637.1547429-1-ekffu200098@gm= ail.com/ Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Sang-Heon Jeon --- lib/bootconfig.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 61cae6d6e3f8..20b3d6e78fea 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -1003,9 +1003,30 @@ static int __init xbc_close_brace(char **k, char *n) return __xbc_close_brace(n - 1); } =20 +#ifndef __KERNEL__ +/* Sanity check for regression: node indices must be within bounds */ +static int __init xbc_sanity_check_tree(void) +{ + int i; + + for (i =3D 0; i < xbc_node_num; i++) { + if (xbc_nodes[i].next >=3D xbc_node_num) { + return xbc_parse_error("No closing brace", + xbc_node_get_data(xbc_nodes + i)); + } + if (xbc_nodes[i].child >=3D xbc_node_num) { + return xbc_parse_error("Broken child node", + xbc_node_get_data(xbc_nodes + i)); + } + } + + return 0; +} +#endif + static int __init xbc_verify_tree(void) { - int i, depth; + int depth; size_t len, wlen; struct xbc_node *n, *m; =20 @@ -1022,17 +1043,6 @@ static int __init xbc_verify_tree(void) return -ENOENT; } =20 - for (i =3D 0; i < xbc_node_num; i++) { - if (xbc_nodes[i].next >=3D xbc_node_num) { - return xbc_parse_error("No closing brace", - xbc_node_get_data(xbc_nodes + i)); - } - if (xbc_nodes[i].child >=3D xbc_node_num) { - return xbc_parse_error("Broken child node", - xbc_node_get_data(xbc_nodes + i)); - } - } - /* Key tree limitation check */ n =3D &xbc_nodes[0]; depth =3D 1; @@ -1203,6 +1213,10 @@ int __init xbc_init(const char *data, size_t size, c= onst char **emsg, int *epos) ret =3D xbc_parse_tree(); if (!ret) ret =3D xbc_verify_tree(); +#ifndef __KERNEL__ + if (!ret) + ret =3D xbc_sanity_check_tree(); +#endif =20 if (ret < 0) { if (epos) From nobody Fri Sep 25 13:53:51 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A37BF3515C7; Fri, 11 Sep 2026 14:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789136019; cv=none; b=WTGNozFOyxTNiJTT3tpFi3Xyle0YPHfW+d6GNCQ2hAb2x2BjJzG78exEneXqn+P/skiV7qtOR8KrL/J9/J6312IR0TiGpm9R+tm/6dJQ+AJE4tm8MTek6xTP0ALYjFu/3nQfWGfRf90f9a0G/pPRxtoMlKQxmjDU9mADKb6D9kI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789136019; c=relaxed/simple; bh=HjdMvu+amrfZ+Yjum6DNCwuv95VOPcYse8XIGVa3Hsc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kS7Z9No4b4bxY9XtVpSvCExdKgMPJMtPgspHFrXVwSNCOl//8G76O/CBljdZ2h9hLlVsx9hlWdg10nSxWUCWL9HSI7i3hI+IsfyrUNeXlHpFX8zRD4jd8DHlTBAfWlteZI9o3QYKRXtYqIU1YnDbNngJpSSLPmlTgNrIjC445KU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dW0jORBH; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dW0jORBH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 026651F008A2; Fri, 11 Sep 2026 14:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789136017; bh=5ITgpds4xl58Ygn2uPHYZZiX61DZ+QftRJbMlAz/1Js=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dW0jORBHvt7NTMCMA5myakN4a7nziqA5V2p5sdelKnBENyMAGL7ow5qQqtSyfN18B 1vOi3DrbZYYy0lCmWc52F5B8vRMw7J31ZJxxpBnLVEIar8f8NuqgWZIHXqiP3AKqiM C1sAZHb0QcGDm4voSJGTWBTd3+k9SMQN0vyjdcUPWOnzuQ0R0VTcH3qxbl9OYtOHxg SmYFH/38PhBxoz7J8/qquUy6CkCicLcEwfpRxkGx1mgGMCr2jWaVQC99MnzZ/zOqwh gzKFiL9rKEKbrJAFAb48G48X3srNp/E9p9crYZYiv5T2J1TZftv5OgcW8ET7ma3GY5 i7elDyBhblsSA== From: "Masami Hiramatsu (Google)" To: Andrew Morton , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Sang-Heon Jeon Subject: [PATCH v2 4/4] bootconfig: Move BOOTCONFIG_FOOTER_SIZE to include/linux/bootconfig.h Date: Fri, 11 Sep 2026 23:13:33 +0900 Message-ID: <178913601321.248794.4786502771058559887.stgit@devnote2> X-Mailer: git-send-email 2.43.0 In-Reply-To: <178913597653.248794.1237187523153227751.stgit@devnote2> References: <178913597653.248794.1237187523153227751.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Masami Hiramatsu (Google) BOOTCONFIG_FOOTER_SIZE was defined locally in tools/bootconfig/main.c. Move it to include/linux/bootconfig.h so that it can be shared with the kernel and user-space tools. Also, use it in init/main.c instead of the hardcoded (BOOTCONFIG_MAGIC_LEN + 8) expression when checking the initrd size. Suggested-by: Sang-Heon Jeon Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Sang-Heon Jeon --- Changes in v2: - Newly added. --- include/linux/bootconfig.h | 4 ++++ init/main.c | 2 +- tools/bootconfig/main.c | 4 ---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h index deda507500da..6f23ec11baab 100644 --- a/include/linux/bootconfig.h +++ b/include/linux/bootconfig.h @@ -27,6 +27,10 @@ bool __init cmdline_has_extra_options(void); #define BOOTCONFIG_ALIGN (1 << BOOTCONFIG_ALIGN_SHIFT) #define BOOTCONFIG_ALIGN_MASK (BOOTCONFIG_ALIGN - 1) =20 +/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */ +#define BOOTCONFIG_FOOTER_SIZE \ + (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN) + /** * xbc_calc_checksum() - Calculate checksum of bootconfig * @data: Bootconfig data. diff --git a/init/main.c b/init/main.c index 16749bb7a219..37168bd68126 100644 --- a/init/main.c +++ b/init/main.c @@ -278,7 +278,7 @@ static void * __init get_boot_config_from_initrd(size_t= *_size) int i; =20 if (!initrd_end || initrd_end < initrd_start || - initrd_end - initrd_start < BOOTCONFIG_MAGIC_LEN + 8) + initrd_end - initrd_start < BOOTCONFIG_FOOTER_SIZE) return NULL; =20 data =3D (char *)initrd_end - BOOTCONFIG_MAGIC_LEN; diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 652e491b9c33..d4aa96da970e 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -17,10 +17,6 @@ =20 #define pr_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) =20 -/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */ -#define BOOTCONFIG_FOOTER_SIZE \ - (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN) - static void show_xbc_error(const char *data, const char *msg, int pos) { int lin =3D 1, col, i;