From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 778FA25A2A2 for ; Fri, 17 Apr 2026 01:04:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776387896; cv=none; b=ZqRlyb6m6ZW2ZchtarfpDeigohkFMRktTmOrDF6jFN//8xmT/pZHg1im19BN0pCc6Oi1Gg8hnzVE4XVnBzbRbSAWxHYOvBeb1zZjgwhOeRFcZjK/NjbwHjqXv8YuYlizJNKYb0auazfKBxEz/ZHuq1f6NQ2f4gl9idDKwCosAaw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776387896; c=relaxed/simple; bh=NncydvtMRG28DkGwJLo7avZcCraVrvfXVKmR/EmpXgo=; h=Date:From:To:Cc:Subject:Message-Id:Mime-Version:Content-Type; b=NVTFYMSX0ZKxlEPR01LchyZoPcWNDUy6BjLqiBzteHHifwiBZT4Vmn2UcAWPo//Xp1L2QOTPJEEDVFJfLc5rdIOLAeqMIdAaWFh+Ck3qd9Pl6p/mAV5Dv2vzQeCgBtqY8OK7RXrY7GOQg2dRgPys5Qhk6w5oV+l//EIIP8/uxEQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=np5d98Kj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="np5d98Kj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D268BC2BCB5; Fri, 17 Apr 2026 01:04:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776387896; bh=NncydvtMRG28DkGwJLo7avZcCraVrvfXVKmR/EmpXgo=; h=Date:From:To:Cc:Subject:From; b=np5d98KjXS9VnOqCq+c0Hzu6HnOiIV9t9D8gh8gdWACew3RNj+V+q9pOMfIC0VgN+ oF12dxOw5aftvErR34gHbG1QXaH4HPqL5Ak0Lx+0Dambt6huUhwrD4lR6Ccw8iqAnr ohvSvJNRTnb3G768/mt7SaxeF9oHjJmt++S2ytRITPrjrLYUJ3eBbbIBnesA0Y+LnS bLNA8M2/QSmGqRimb3wyy7HBrdwVSIeR3//x6PI+e3jbMrTddEDkVqg68x5Y0O0QiM gJxFIwe7bJq+b8DkUkcd51D93T3J9gEXpOTOI0LpUNDazNEs6uXC4ojm6QxjJT2cQ3 DcxsNwYOYmPVg== Date: Fri, 17 Apr 2026 10:04:52 +0900 From: Masami Hiramatsu (Google) To: Linus Torvalds Cc: Josh Law , Steven Rostedt , Masami Hiramatsu , linux-kernel@vger.kernel.org Subject: [GIT PULL] bootconfig: Updates for v7.1 Message-Id: <20260417100452.7b2522f57ead1b7979ca1ae7@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit Hi Linus, Bootconfig for v7.1: - bootconfig: Minor fixes for handling errors, which includes the following commits: . fix off-by-one in xbc_verify_tree() next node check . increment xbc_node_num after node init succeeds . validate child node index in xbc_verify_tree() - bootconfig: Code cleanups (mainly type/attribute changes), which includes the following commits. . clean up comment typos and bracing . drop redundant memset of xbc_nodes . replace linux/kernel.h with specific includes . narrow flag parameter type from uint32_t to uint16_t . constify xbc_calc_checksum() data parameter . fix signed comparison in xbc_node_get_data() . use size_t for strlen result in xbc_node_match_prefix() . use signed type for offset in xbc_init_node() . use size_t for key length tracking in xbc_verify_tree() . change xbc_node_index() return type to uint16_t Please pull the latest bootconfig-v7.1 tree, which can be found at: git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git bootconfig-v7.1 Tag SHA1: caea779c2ccca218e1440502472550e899f4858b Head SHA1: 6eb255d019b810614c5cbd99b9ef281b7b9361e3 Josh Law (13): lib/bootconfig: clean up comment typos and bracing lib/bootconfig: narrow flag parameter type from uint32_t to uint16_t lib/bootconfig: fix off-by-one in xbc_verify_tree() next node check lib/bootconfig: increment xbc_node_num after node init succeeds lib/bootconfig: drop redundant memset of xbc_nodes bootconfig: constify xbc_calc_checksum() data parameter lib/bootconfig: replace linux/kernel.h with specific includes lib/bootconfig: validate child node index in xbc_verify_tree() lib/bootconfig: fix signed comparison in xbc_node_get_data() lib/bootconfig: use size_t for strlen result in xbc_node_match_prefix() lib/bootconfig: use signed type for offset in xbc_init_node() lib/bootconfig: use size_t for key length tracking in xbc_verify_tree() lib/bootconfig: change xbc_node_index() return type to uint16_t ---- include/linux/bootconfig.h | 6 ++--- lib/bootconfig.c | 62 +++++++++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 29 deletions(-) --------------------------- diff --git a/include/linux/bootconfig.h b/include/linux/bootconfig.h index 25df9260d206..692a5acc2ffc 100644 --- a/include/linux/bootconfig.h +++ b/include/linux/bootconfig.h @@ -36,9 +36,9 @@ bool __init cmdline_has_extra_options(void); * The checksum will be used with the BOOTCONFIG_MAGIC and the size for * embedding the bootconfig in the initrd image. */ -static inline __init uint32_t xbc_calc_checksum(void *data, uint32_t size) +static inline __init uint32_t xbc_calc_checksum(const void *data, uint32_t size) { - unsigned char *p = data; + const unsigned char *p = data; uint32_t ret = 0; while (size--) @@ -66,7 +66,7 @@ struct xbc_node { /* Node tree access raw APIs */ struct xbc_node * __init xbc_root_node(void); -int __init xbc_node_index(struct xbc_node *node); +uint16_t __init xbc_node_index(struct xbc_node *node); struct xbc_node * __init xbc_node_get_parent(struct xbc_node *node); struct xbc_node * __init xbc_node_get_child(struct xbc_node *node); struct xbc_node * __init xbc_node_get_next(struct xbc_node *node); diff --git a/lib/bootconfig.c b/lib/bootconfig.c index e88d0221a826..01966ab9a8b5 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -17,7 +17,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -71,7 +73,7 @@ static inline void __init xbc_free_mem(void *addr, size_t size, bool early) static inline void *xbc_alloc_mem(size_t size) { - return malloc(size); + return calloc(1, size); } static inline void xbc_free_mem(void *addr, size_t size, bool early) @@ -79,6 +81,7 @@ static inline void xbc_free_mem(void *addr, size_t size, bool early) free(addr); } #endif + /** * xbc_get_info() - Get the information of loaded boot config * @node_size: A pointer to store the number of nodes. @@ -112,7 +115,7 @@ static int __init xbc_parse_error(const char *msg, const char *p) * xbc_root_node() - Get the root node of extended boot config * * Return the address of root node of extended boot config. If the - * extended boot config is not initiized, return NULL. + * extended boot config is not initialized, return NULL. */ struct xbc_node * __init xbc_root_node(void) { @@ -128,9 +131,9 @@ struct xbc_node * __init xbc_root_node(void) * * Return the index number of @node in XBC node list. */ -int __init xbc_node_index(struct xbc_node *node) +uint16_t __init xbc_node_index(struct xbc_node *node) { - return node - &xbc_nodes[0]; + return (uint16_t)(node - &xbc_nodes[0]); } /** @@ -180,7 +183,7 @@ struct xbc_node * __init xbc_node_get_next(struct xbc_node *node) */ const char * __init xbc_node_get_data(struct xbc_node *node) { - int offset = node->data & ~XBC_VALUE; + size_t offset = node->data & ~XBC_VALUE; if (WARN_ON(offset >= xbc_data_size)) return NULL; @@ -192,7 +195,7 @@ static bool __init xbc_node_match_prefix(struct xbc_node *node, const char **prefix) { const char *p = xbc_node_get_data(node); - int len = strlen(p); + size_t len = strlen(p); if (strncmp(*prefix, p, len)) return false; @@ -364,7 +367,7 @@ struct xbc_node * __init xbc_node_find_next_leaf(struct xbc_node *root, node = xbc_node_get_parent(node); if (node == root) return NULL; - /* User passed a node which is not uder parent */ + /* User passed a node which is not under parent */ if (WARN_ON(!node)) return NULL; } @@ -407,11 +410,11 @@ const char * __init xbc_node_find_next_key_value(struct xbc_node *root, /* XBC parse and tree build */ -static int __init xbc_init_node(struct xbc_node *node, char *data, uint32_t flag) +static int __init xbc_init_node(struct xbc_node *node, char *data, uint16_t flag) { - unsigned long offset = data - xbc_data; + long offset = data - xbc_data; - if (WARN_ON(offset >= XBC_DATA_MAX)) + if (WARN_ON(offset < 0 || offset >= XBC_DATA_MAX)) return -EINVAL; node->data = (uint16_t)offset | flag; @@ -421,16 +424,17 @@ static int __init xbc_init_node(struct xbc_node *node, char *data, uint32_t flag return 0; } -static struct xbc_node * __init xbc_add_node(char *data, uint32_t flag) +static struct xbc_node * __init xbc_add_node(char *data, uint16_t flag) { struct xbc_node *node; if (xbc_node_num == XBC_NODE_MAX) return NULL; - node = &xbc_nodes[xbc_node_num++]; + node = &xbc_nodes[xbc_node_num]; if (xbc_init_node(node, data, flag) < 0) return NULL; + xbc_node_num++; return node; } @@ -451,7 +455,7 @@ static inline __init struct xbc_node *xbc_last_child(struct xbc_node *node) return node; } -static struct xbc_node * __init __xbc_add_sibling(char *data, uint32_t flag, bool head) +static struct xbc_node * __init __xbc_add_sibling(char *data, uint16_t flag, bool head) { struct xbc_node *sib, *node = xbc_add_node(data, flag); @@ -472,23 +476,24 @@ static struct xbc_node * __init __xbc_add_sibling(char *data, uint32_t flag, boo sib->next = xbc_node_index(node); } } - } else + } else { xbc_parse_error("Too many nodes", data); + } return node; } -static inline struct xbc_node * __init xbc_add_sibling(char *data, uint32_t flag) +static inline struct xbc_node * __init xbc_add_sibling(char *data, uint16_t flag) { return __xbc_add_sibling(data, flag, false); } -static inline struct xbc_node * __init xbc_add_head_sibling(char *data, uint32_t flag) +static inline struct xbc_node * __init xbc_add_head_sibling(char *data, uint16_t flag) { return __xbc_add_sibling(data, flag, true); } -static inline __init struct xbc_node *xbc_add_child(char *data, uint32_t flag) +static inline __init struct xbc_node *xbc_add_child(char *data, uint16_t flag) { struct xbc_node *node = xbc_add_sibling(data, flag); @@ -655,9 +660,9 @@ static int __init __xbc_add_key(char *k) if (unlikely(xbc_node_num == 0)) goto add_node; - if (!last_parent) /* the first level */ + if (!last_parent) { /* the first level */ node = find_match_node(xbc_nodes, k); - else { + } else { child = xbc_node_get_child(last_parent); /* Since the value node is the first child, skip it. */ if (child && xbc_node_is_value(child)) @@ -665,9 +670,9 @@ static int __init __xbc_add_key(char *k) node = find_match_node(child, k); } - if (node) + if (node) { last_parent = node; - else { + } else { add_node: node = xbc_add_child(k, XBC_KEY); if (!node) @@ -798,7 +803,8 @@ static int __init xbc_close_brace(char **k, char *n) static int __init xbc_verify_tree(void) { - int i, depth, len, wlen; + int i, depth; + size_t len, wlen; struct xbc_node *n, *m; /* Brace closing */ @@ -815,10 +821,14 @@ static int __init xbc_verify_tree(void) } for (i = 0; i < xbc_node_num; i++) { - if (xbc_nodes[i].next > xbc_node_num) { + if (xbc_nodes[i].next >= xbc_node_num) { return xbc_parse_error("No closing brace", xbc_node_get_data(xbc_nodes + i)); } + if (xbc_nodes[i].child >= xbc_node_num) { + return xbc_parse_error("Broken child node", + xbc_node_get_data(xbc_nodes + i)); + } } /* Key tree limitation check */ @@ -980,7 +990,6 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) _xbc_exit(true); return -ENOMEM; } - memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX); ret = xbc_parse_tree(); if (!ret) @@ -992,8 +1001,9 @@ int __init xbc_init(const char *data, size_t size, const char **emsg, int *epos) if (emsg) *emsg = xbc_err_msg; _xbc_exit(true); - } else + } else { ret = xbc_node_num; + } return ret; } -- Masami Hiramatsu (Google)