bootconfig: Fixes for v7.4-rc5
Subsystems (5)
Masami Hiramatsu (Google)
maintainerHi Linus,
Bootconfig fixes for v7.4-rc5:
- bootconfig: Exclude alignment padding from bootconfig max size Separate the padded trailer size limit from XBC_DATA_MAX and strip up to 3 trailing NUL alignment bytes before xbc_init() so valid max-size configs are not rejected depending on initrd alignment.
- bootconfig: Free the initrd memory used by bootconfig
Save the original initrd_end before trimming the bootconfig and restore it when freeing initrd memory so pages previously occupied by bootconfig data are not leaked.
- bootconfig: Parser fixes and tests according to LEAN check
. Fix xbc_verify_tree() to check subkeys of valued keys
Use xbc_node_get_subkey() when descending so subkeys under mixed value+subkey nodes cannot bypass XBC_DEPTH_MAX and XBC_KEYLEN_MAX.
. Fix xbc_node_compose_key_after() for value nodes
Walk parent pointers across chained array value nodes before checking @root so composed keys exclude array values and NUL-terminate @buf.
. Avoid out-of-bounds pointer arithmetic in xbc_snprint_cmdline_filter()
Pass NULL to snprintf() when len >= size so buf + len is not formed past the buffer end on overflow.
. Add tests for unclosed brace position and mixed-kv limits
Expand test-bootconfig.sh to cover unclosed brace error positions and mixed value+subkey depth and key-length limits.
- tools/bootconfig: Use registered global tracing parameter names Update boottime-trace.rst and ftrace2bconf.sh to use the registered global tracing parameter names, while keeping fallback support in bconf2ftrace.sh for existing configs.
- tools/bootconfig: Fix read/write error handling in bootconfig tool . Reject short reads of configuration data in load_xbc_fd() and free the allocated buffer on failure so partial reads are never parsed or checksummed.
. Check write() return values for negative errors before comparing
against unsigned size_t counts so initrd append failures are reported.
Please pull the latest bootconfig-fixes-v7.4-rc5 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
bootconfig-fixes-v7.4-rc5
Tag SHA1: 5aaf5e882e3d5a9940b5183554e260523f5fee41 Head SHA1: 56bb11fe6aacc7666938e8e6765b44aa0cf1fcdd
Eduardo Mucelli Rezende Oliveira (1):
tools/bootconfig: Use the registered global tracing parameter names
Masami Hiramatsu (Google) (6):
bootconfig: Exclude alignment padding from bootconfig max size
bootconfig: Free the initrd memory used by bootconfig
bootconfig: Fix xbc_verify_tree() to check subkeys of valued keys
bootconfig: Fix xbc_node_compose_key_after() for value nodes
bootconfig: Avoid out-of-bounds pointer arithmetic in xbc_snprint_cmdline_filter() tools/bootconfig: Add tests for unclosed brace position and mixed-kv limits
Zhu Jun (2):
tools/bootconfig: Reject short reads of configuration data tools/bootconfig: Report initrd append failures
----
Documentation/trace/boottime-trace.rst | 8 ++--- include/linux/bootconfig.h | 24 +++++++++++++++ include/linux/initrd.h | 2 ++ init/initramfs.c | 10 +++++++ init/main.c | 31 ++++++++++++++------ lib/bootconfig.c | 17 ++++++----- tools/bootconfig/main.c | 38 +++++++++++++++--------- tools/bootconfig/scripts/bconf2ftrace.sh | 21 ++++++++++---- tools/bootconfig/scripts/ftrace2bconf.sh | 5 ++-- tools/bootconfig/test-bootconfig.sh | 50 ++++++++++++++++++++++++++++++-- 10 files changed, 163 insertions(+), 43 deletions(-)
---------------------------
Documentation/trace/boottime-trace.rst +4 -4
@@ -36,20 +36,20 @@ these options are passed as a part of kernel legacy command line. kernel.tp_printk Output trace-event data on printk buffer too. -kernel.dump_on_oops [= MODE] +kernel.ftrace_dump_on_oops [= MODE] Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops. kernel.traceoff_on_warning Stop tracing if WARN_ON() occurs. -kernel.fgraph_max_depth = MAX_DEPTH +kernel.ftrace_graph_max_depth = MAX_DEPTH Set MAX_DEPTH to maximum depth of fgraph tracer. -kernel.fgraph_filters = FILTER[, FILTER2...] +kernel.ftrace_graph_filter = FILTER[, FILTER2...] Add fgraph tracing function filters. -kernel.fgraph_notraces = FILTER[, FILTER2...] +kernel.ftrace_graph_notrace = FILTER[, FILTER2...] Add fgraph non-tracing function filters.
include/linux/bootconfig.h +24 -0
@@ -63,6 +63,30 @@ struct xbc_node {#define XBC_VALUE (1 << 15)/* Maximum size of boot config is 32KB - 1 */ #define XBC_DATA_MAX (XBC_VALUE - 1) +/* Maximum size of padded boot config in initrd trailer */ +#define XBC_DATA_MAX_PADDED (XBC_DATA_MAX + BOOTCONFIG_ALIGN - 1) + +/** +* xbc_exclude_padding() - Exclude trailing null padding bytes from size +* @data: Bootconfig data (including padding). +* @size: The size of @data from the bootconfig footer. +* +* Exclude up to BOOTCONFIG_ALIGN - 1 trailing null padding bytes while +* keeping the terminal null byte of the bootconfig data, and return the +* unpadded bootconfig size. +*/ +static inline __init uint32_t xbc_exclude_padding (const char *data,uint32_t size) +{ +int i; + +for (i =0 ; i <BOOTCONFIG_ALIGN -1 ; i++) { +if (size <=1 || data[size -1 ] !='\0' || data[size -2 ] !='\0' ) +break ; + size--; + } + +return size; +}#define XBC_NODE_MAX 8192#define XBC_KEYLEN_MAX 256
include/linux/initrd.h +2 -0
@@ -17,6 +17,8 @@ extern unsigned long initrd_start, initrd_end;extern void free_initrd_mem (unsigned long ,unsigned long );#ifdef CONFIG_BLK_DEV_INITRD +/* initrd_end before trailing data (e.g. bootconfig) was trimmed off */ +extern unsigned long initrd_mem_end;extern void __init reserve_initrd_mem (void );extern void wait_for_initramfs (void );#else
init/initramfs.c +10 -0
@@ -582,6 +582,7 @@ char * __init unpack_to_rootfs(char *buf, unsigned long len) }static int __initdata do_retain_initrd; +unsigned long initrd_mem_end__initdata ;static int __init retain_initrd_param (char *str) {
@@ -750,6 +751,15 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)security_initramfs_populated (); } +/* +* The bootconfig loader trims the bootconfig off initrd_end. Restore +* it to free the memory used by the bootconfig too, unless the initrd +* is retained (which must not expose the bootconfig). +*/ +if (!do_retain_initrd && initrd_start && initrd_end < initrd_mem_end) + initrd_end = initrd_mem_end; + initrd_mem_end =0 ; +/* * If the initrd region is overlapped with crashkernel reserved region, * free only memory that is not part of crashkernel region.
init/main.c +22 -9
@@ -268,7 +268,7 @@ early_param("loglevel", loglevel);#ifdef CONFIG_BLK_DEV_INITRD static void *__init get_boot_config_from_initrd (size_t *_size) { -u32 size, csum; +u32 size, raw_size, csum;char *data;u8 *hdr;int i;
@@ -294,29 +294,42 @@ static void * __init get_boot_config_from_initrd(size_t *_size)if ((unsigned long )hdr < initrd_start)return NULL ; - size =get_unaligned_le32 (hdr); + raw_size =get_unaligned_le32 (hdr); csum =get_unaligned_le32 (hdr +4 ); -if (size >XBC_DATA_MAX ) { +if (raw_size >XBC_DATA_MAX_PADDED ) {pr_err ("bootconfig size %u is greater than max size %d\n" , - size,XBC_DATA_MAX ); + raw_size,XBC_DATA_MAX );return NULL ; } -if (size > ((unsigned long )hdr - initrd_start)) { +if (raw_size > ((unsigned long )hdr - initrd_start)) {pr_err ("bootconfig size %u is greater than initrd size %lu\n" , - size, initrd_end - initrd_start); + raw_size, initrd_end - initrd_start);return NULL ; } - data = ((void *)hdr) - size; + data = ((void *)hdr) - raw_size; + + size =xbc_exclude_padding (data, raw_size); +if (size >XBC_DATA_MAX ) { +pr_err ("bootconfig size %u is greater than max size %d\n" , + size,XBC_DATA_MAX ); +return NULL ; + } -if (xbc_calc_checksum (data, size) != csum) { +if (xbc_calc_checksum (data, raw_size) != csum) {pr_err ("bootconfig checksum failed\n" );return NULL ; } -/* Remove bootconfig from initramfs/initrd */ +/* +* Remove bootconfig from initramfs/initrd. Since the initrd memory +* (including the bootconfig) is freed with initrd_end, save the +* original end to free the whole region later. +*/ +if (!initrd_mem_end) + initrd_mem_end = initrd_end; initrd_end = (unsigned long )data;if (_size) *_size = size;
lib/bootconfig.c +9 -8
@@ -421,12 +421,12 @@ int __init xbc_node_compose_key_after(struct xbc_node *root,uint16_t keys[XBC_DEPTH_MAX ];int depth =0 , ret =0 , total =0 ; +while (node &&xbc_node_is_value (node)) + node =xbc_node_get_parent (node); +if (!node || node == root)return -EINVAL ; -if (xbc_node_is_value (node)) - node =xbc_node_get_parent (node); -while (node && node != root) {if (depth ==XBC_DEPTH_MAX )return -ERANGE ;
@@ -587,8 +587,8 @@ int __init xbc_snprint_cmdline_filter(char *buf, size_t size, struct xbc_node *r vnode =xbc_node_get_child (knode);if (!vnode) { - ret =snprintf (buf ? buf + len :NULL ,rest (len, size), -"%s " , xbc_namebuf); + ret =snprintf (buf && len < size ? buf + len :NULL , +rest (len, size),"%s " , xbc_namebuf);if (ret <0 )return ret; len += ret;
@@ -601,7 +601,8 @@ int __init xbc_snprint_cmdline_filter(char *buf, size_t size, struct xbc_node *r* whitespace. */ q =strpbrk (val," \t\r\n" ) ?"\"" :"" ; - ret =snprintf (buf ? buf + len :NULL ,rest (len, size), + ret =snprintf (buf && len < size ? buf + len :NULL , +rest (len, size),"%s=%s%s%s " , xbc_namebuf, q, val, q);if (ret <0 )return ret;
@@ -1058,8 +1059,8 @@ static int __init xbc_verify_tree(void)return xbc_parse_error ("Too long key length" ,xbc_node_get_data (n)); - m =xbc_node_get_child (n); -if (m &&xbc_node_is_key (m)) { + m =xbc_node_get_subkey (n); +if (m) { n = m; depth++;if (depth >XBC_DEPTH_MAX )
tools/bootconfig/main.c +25 -13
@@ -182,7 +182,7 @@ static int load_xbc_fd(int fd, char **buf, int size) {int ret; -if (size <0 || size >XBC_DATA_MAX ) +if (size <0 || size >XBC_DATA_MAX_PADDED )return -EINVAL ; *buf =malloc (size +1 );
@@ -190,8 +190,12 @@ static int load_xbc_fd(int fd, char **buf, int size)return -ENOMEM ; ret =read (fd, *buf, size); -if (ret <0 ) -return -errno; +if (ret != size) { + ret = ret <0 ? -errno : -EIO ; +free (*buf); + *buf =NULL ; +return ret; + } (*buf)[size] ='\0' ;return ret;
@@ -237,7 +241,7 @@ static int load_xbc_from_initrd(int fd, char **buf) {struct stat stat;int ret; -uint32_t size =0 , csum =0 , rcsum; +uint32_t size =0 , data_size, csum =0 , rcsum;char magic[BOOTCONFIG_MAGIC_LEN ]; ret =fstat (fd, &stat);
@@ -269,7 +273,7 @@ static int load_xbc_from_initrd(int fd, char **buf) csum =le32toh (csum);/* Wrong size error */ -if (size >XBC_DATA_MAX || +if (size >XBC_DATA_MAX_PADDED || size > stat.st_size -BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ;
@@ -283,6 +287,12 @@ static int load_xbc_from_initrd(int fd, char **buf)if (ret <0 )return ret; + data_size =xbc_exclude_padding (*buf, size); +if (data_size >XBC_DATA_MAX ) { +pr_err ("bootconfig size is too big\n" ); +return -E2BIG ; + } +/* Wrong Checksum */ rcsum =xbc_calc_checksum (*buf, size);if (csum != rcsum) {
@@ -290,7 +300,7 @@ static int load_xbc_from_initrd(int fd, char **buf)return -EINVAL ; } - ret =init_xbc_with_error (*buf, size); + ret =init_xbc_with_error (*buf, data_size);return ret <0 ? ret : size; }
@@ -499,14 +509,16 @@ static int apply_xbc(const char *path, const char *xbc_path) total_size = size +BOOTCONFIG_FOOTER_SIZE ; ret =write (fd, data, total_size); -if (ret < total_size) { -if (ret <0 ) - ret = -errno; +if (ret <0 ) { + ret = -errno;pr_err ("Failed to apply a boot config: %d\n" , ret); -if (ret >=0 ) - goto out_rollback; - }else - ret =0 ; + goto out; + } +if ((size_t )ret != total_size) { +pr_err ("Failed to apply a boot config: %d\n" , ret); + goto out_rollback; + } + ret =0 ; out:close (fd);
tools/bootconfig/scripts/bconf2ftrace.sh +16 -5
@@ -275,15 +275,26 @@ setup_instance() { # [instance] } # ftrace global configs (kernel.*) -if xbc_has_key "kernel.dump_on_oops"; then - dump_mode=`xbc_get_val "kernel.dump_on_oops" 1` +# Prefer the kernel parameter names and accept the old script keys as fallbacks. +dump_key=kernel.ftrace_dump_on_oops +xbc_has_key "$dump_key" || dump_key=kernel.dump_on_oops +if xbc_has_key "$dump_key"; then + dump_mode=`xbc_get_val "$dump_key" 1` [ "$dump_mode" ] && dump_mode=`eval echo $dump_mode` || dump_mode=1 run_cmd "echo \"$dump_mode\" > /proc/sys/kernel/ftrace_dump_on_oops" fi -set_value_of kernel.fgraph_max_depth $TRACEFS/max_graph_depth -set_array_of kernel.fgraph_filters $TRACEFS/set_graph_function -set_array_of kernel.fgraph_notraces $TRACEFS/set_graph_notrace +graph_depth_key=kernel.ftrace_graph_max_depth +xbc_has_key "$graph_depth_key" || graph_depth_key=kernel.fgraph_max_depth +set_value_of "$graph_depth_key" $TRACEFS/max_graph_depth + +graph_filter_key=kernel.ftrace_graph_filter +xbc_has_key "$graph_filter_key" || graph_filter_key=kernel.fgraph_filters +set_array_of "$graph_filter_key" $TRACEFS/set_graph_function + +graph_notrace_key=kernel.ftrace_graph_notrace +xbc_has_key "$graph_notrace_key" || graph_notrace_key=kernel.fgraph_notraces +set_array_of "$graph_notrace_key" $TRACEFS/set_graph_notrace # Per-instance/per-event configs if ! xbc_has_branch "ftrace" ; then
tools/bootconfig/scripts/ftrace2bconf.sh +3 -2
@@ -46,10 +46,11 @@ emit_kv() { # key =|+= value global_options() { val=`cat $TRACEFS/max_graph_depth` - [ $val != 0 ] && emit_kv kernel.fgraph_max_depth = $val + [ $val != 0 ] && emit_kv kernel.ftrace_graph_max_depth = $val if grep -qv "^#" $TRACEFS/set_graph_function $TRACEFS/set_graph_notrace ; then cat 1>&2 << EOF -# WARN: kernel.fgraph_filters and kernel.fgraph_notrace are not supported, since the wild card expression was expanded and lost from memory. +# WARN: Cannot export kernel.ftrace_graph_filter and kernel.ftrace_graph_notrace. +# Only the expanded function list is available. EOF fi }
tools/bootconfig/test-bootconfig.sh +48 -2
64 lines not on this page · raw message
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
The pull request you sent on Wed, 25 Nov 2026 07:52:07 +0900:
The pull request you sent on Wed, 25 Nov 2026 07:52:07 +0900:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.gitbootconfig-fixes-v7.4-rc5
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/3d4ed0e55cf54d9d05b5d8603593125cadd2e3db
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html