From: bot+bpf-ci@kernel.org
To: piliu@redhat.com,kexec@lists.infradead.org
Cc: piliu@redhat.com,davem@davemloft.net,ast@kernel.org,daniel@iogearbox.net,john.fastabend@gmail.com,andrii@kernel.org,martin.lau@linux.dev,eddyz87@gmail.com,song@kernel.org,yonghong.song@linux.dev,jeremy.linton@arm.com,catalin.marinas@arm.com,will@kernel.org,ardb@kernel.org,horms@kernel.org,kraxel@redhat.com,vkuznets@redhat.com,prudo@redhat.com,vmalik@redhat.com,kernel@jfarr.cc,bhe@redhat.com,dyoung@redhat.com,akpm@linux-foundation.org,bpf@vger.kernel.org,systemd-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [PATCHv6 13/13] tools/kexec: Add a zboot image building tool
Date: Mon, 19 Jan 2026 18:45:38 +0000 (UTC) [thread overview]
Message-ID: <2742c5333700b577bda375a3bf80f55ca5aa92bdd66ecc85e85a8f762d94c277@mail.kernel.org> (raw)
In-Reply-To: <20260119032424.10781-14-piliu@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2634 bytes --]
> diff --git a/tools/kexec/pe.h b/tools/kexec/pe.h
> new file mode 100644
> index 000000000000..c2273d3fc3bb
> --- /dev/null
> +++ b/tools/kexec/pe.h
[ ... ]
> +/*
> + * Return -1 if not PE, else offset of the PE header
> + */
> +static int get_pehdr_offset(const char *buf)
> +{
> + int pe_hdr_offset;
> +
> + pe_hdr_offset = *((int *)(buf + 0x3c));
> + buf += pe_hdr_offset;
> + if (!!memcmp(buf, "PE\0\0", 4)) {
> + printf("Not a PE file\n");
> + return -1;
> + }
> +
> + return pe_hdr_offset;
> +}
This function returns int and can return -1 on error, but the caller stores
the result in a uint32_t without checking for errors (see below).
> diff --git a/tools/kexec/zboot_image_builder.c b/tools/kexec/zboot_image_builder.c
> new file mode 100644
> index 000000000000..c0a785074970
> --- /dev/null
> +++ b/tools/kexec/zboot_image_builder.c
[ ... ]
> +int main(int argc, char **argv)
> +{
> + uint32_t payload_new_offset, payload_sect_off;
> + uint32_t payload_size;
> + uint32_t payload_sect_idx;
^^^^^^^^^^^^^^^^
Are payload_sect_idx and payload_sect_off intentionally left uninitialized
here? If the loop below never finds a matching section, these variables
will contain garbage values.
[ ... ]
> + uint32_t pe_hdr_offset = get_pehdr_offset((const char *)base_start_addr);
> + base_cur = base_start_addr + pe_hdr_offset;
Is there a missing check for the return value of get_pehdr_offset()? The
function returns -1 on error (printing "Not a PE file"), but this code
stores it in a uint32_t and uses it directly. If get_pehdr_offset()
returns -1, pe_hdr_offset becomes 0xFFFFFFFF, and base_cur will point far
past the mapped region.
[ ... ]
> + /* Decide the section idx and the payload offset within the section */
> + for (i = 0; i < num_sections; i++) {
> + sect = &base_sections[i];
> + if (zheader->payload_offset >= sect->data_addr &&
> + zheader->payload_offset < (sect->data_addr + sect->raw_data_size)) {
> + payload_sect_idx = i;
> + payload_sect_off = zheader->payload_offset - sect->data_addr;
> + }
> + }
If the condition is never true (payload_offset not within any section),
payload_sect_idx and payload_sect_off remain uninitialized. They are used
later in:
payload_new_offset = new_sections[payload_sect_idx].data_addr + payload_sect_off;
Could this cause undefined behavior with a malformed input file?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21147860407
next prev parent reply other threads:[~2026-01-19 18:45 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-19 3:24 [PATCHv6 00/13] kexec: Use BPF lskel to enable kexec to load PE format boot image Pingfan Liu
2026-01-19 3:24 ` [PATCHv6 01/13] bpf: Introduce kfuncs to parser buffer content Pingfan Liu
2026-01-19 18:45 ` bot+bpf-ci
2026-01-19 3:24 ` [PATCHv6 02/13] kexec_file: Move signature validation ahead Pingfan Liu
2026-01-19 18:45 ` bot+bpf-ci
2026-02-26 13:37 ` Philipp Rudo
2026-02-27 2:33 ` Pingfan Liu
2026-01-19 3:24 ` [PATCHv6 03/13] kexec_file: Introduce routines to parse PE file Pingfan Liu
2026-01-19 18:45 ` bot+bpf-ci
2026-01-19 3:24 ` [PATCHv6 04/13] kexec_file: Use bpf-prog to decompose image Pingfan Liu
2026-01-19 18:45 ` bot+bpf-ci
2026-02-26 13:37 ` Philipp Rudo
2026-02-27 2:40 ` Pingfan Liu
2026-01-19 3:24 ` [PATCHv6 05/13] lib/decompress: Keep decompressor when CONFIG_KEEP_DECOMPRESSOR Pingfan Liu
2026-01-19 3:24 ` [PATCHv6 06/13] kexec_file: Implement decompress method for parser Pingfan Liu
2026-01-19 18:45 ` bot+bpf-ci
2026-01-19 3:24 ` [PATCHv6 07/13] kexec_file: Implement copy " Pingfan Liu
2026-01-19 3:24 ` [PATCHv6 08/13] kexec_file: Introduce a bpf-prog lskel to parse PE file Pingfan Liu
2026-01-19 3:24 ` [PATCHv6 09/13] kexec_file: Factor out routine to find a symbol in ELF Pingfan Liu
2026-01-19 3:24 ` [PATCHv6 10/13] kexec_file: Integrate bpf light skeleton to load image with bpf-prog Pingfan Liu
2026-01-19 18:45 ` bot+bpf-ci
2026-01-19 3:24 ` [PATCHv6 11/13] arm64/kexec: Select KEXEC_BPF to support UEFI-style kernel image Pingfan Liu
2026-01-19 8:23 ` kernel test robot
2026-01-19 18:45 ` bot+bpf-ci
2026-01-19 3:24 ` [PATCHv6 12/13] tools/kexec: Introduce a bpf-prog to parse zboot image format Pingfan Liu
2026-01-19 18:45 ` bot+bpf-ci
2026-01-19 3:24 ` [PATCHv6 13/13] tools/kexec: Add a zboot image building tool Pingfan Liu
2026-01-19 18:45 ` bot+bpf-ci [this message]
2026-02-26 13:36 ` [PATCHv6 00/13] kexec: Use BPF lskel to enable kexec to load PE format boot image Philipp Rudo
2026-02-27 6:03 ` Pingfan Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2742c5333700b577bda375a3bf80f55ca5aa92bdd66ecc85e85a8f762d94c277@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ardb@kernel.org \
--cc=ast@kernel.org \
--cc=bhe@redhat.com \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dyoung@redhat.com \
--cc=eddyz87@gmail.com \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=jeremy.linton@arm.com \
--cc=john.fastabend@gmail.com \
--cc=kernel@jfarr.cc \
--cc=kexec@lists.infradead.org \
--cc=kraxel@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=piliu@redhat.com \
--cc=prudo@redhat.com \
--cc=song@kernel.org \
--cc=systemd-devel@lists.freedesktop.org \
--cc=vkuznets@redhat.com \
--cc=vmalik@redhat.com \
--cc=will@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®