BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Kuohai" <xukuohai@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [RFC PATCH bpf-next 01/12] libbpf: Prepare bpf SDT probe section for the linker
Date: Sat, 27 Jun 2026 17:05:56 +0000	[thread overview]
Message-ID: <20260627170557.03E381F000E9@smtp.kernel.org> (raw)
In-Reply-To: <addc1860d60c2eee409f187805b6cfbc5382e82a.1782571533.git.xukuohai@huawei.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [High] Cross-endian linking corrupts target-endian addresses in `.bpf_sdt_notes`.
- [High] Unaligned memory access via direct pointer cast of `.bpf_sdt_notes` relocations causes undefined behavior.
- [Medium] Blind assumption of 64-bit relocation type for `.bpf_sdt_notes` can cause memory corruption.
- [Medium] Redundant symbol validation bypass allows malicious global symbols in `.bpf_sdt_notes`.

Pre-existing issues:
- [High] Missing bounds check for ELF relocation offsets allows out-of-bounds heap memory access.
--

commit c10bd6264b90c8115e40b5bcf69e608dd418c585
Author: Xu Kuohai <xukuohai@huawei.com>

libbpf: Prepare bpf SDT probe section for the linker

This patch prepares the BPF linker to handle the .bpf_sdt_notes section,
treating it similarly to jumptables. It bypasses section-type checks for
SDT symbols and relocates 64-bit absolute addresses inside each entry.

> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index 04cd303fb5a87..ed7a587a61ca4 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
[ ... ]
> diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
> index 78f92c39290af..3a72276244c72 100644
> --- a/tools/lib/bpf/linker.c
> +++ b/tools/lib/bpf/linker.c
> @@ -2028,6 +2028,8 @@ static int linker_append_elf_sym(struct bpf_linker *linker, struct src_obj *obj,
>  
>  		if (strcmp(src_sec->sec_name, JUMPTABLES_SEC) == 0)
>  			goto add_sym;
> +		if (strcmp(src_sec->sec_name, SDT_NOTES_SEC) == 0)
> +			goto add_sym;

[Severity: Medium]
Could this bypass of global symbol resolution cause issues? If a symbol in
the SDT notes section has STB_GLOBAL binding, it will hit this branch and
skip the deduplication and resolution logic entirely. 

For STB_LOCAL symbols, this check appears to be redundant because of the
subsequent check for STB_LOCAL binding.

>  	}
>  
>  	if (sym_bind == STB_LOCAL)
[ ... ]
> @@ -2274,6 +2276,13 @@ static int linker_append_elf_relos(struct bpf_linker *linker, struct src_obj *ob
>  						insn->imm += sec->dst_off / sizeof(struct bpf_insn);
>  					else
>  						insn->imm += sec->dst_off;
> +				} else if (strcmp(src_linked_sec->sec_name, SDT_NOTES_SEC) == 0) {
> +					/* .bpf_sdt_notes contains R_BPF_64_ABS64 relocations
> +					 * referencing code section symbols. Adjust the 64-bit
> +					 * address by dst_off.
> +					 */
> +					__u64 *addr = dst_linked_sec->raw_data + dst_rel->r_offset;

[Severity: High]
This is a pre-existing issue, but does this lack a bounds check for the
relocation offset? The code uses the r_offset from the relocation to index
into raw_data. If a malformed ELF provides an r_offset that exceeds the
section size, it could result in an out-of-bounds heap memory access.

[Severity: High]
Can this direct pointer cast result in unaligned memory access? The r_offset
value might not be naturally aligned, which could lead to undefined
behavior or crashes on strict-alignment architectures when dereferencing the
cast pointer.

> +					*addr += sec->dst_off;

[Severity: High]
Does this perform host-endian arithmetic on target-endian data without
conversion? The data section is not byte-swapped to native endianness, so
modifying the address using native host-endian addition could corrupt the
relocated address during cross-compiling.

[Severity: Medium]
Is it safe to blindly assume the relocation type is 64-bit? If an ELF object
contains a 32-bit relocation type targeting this section, unconditionally
reading and writing 64 bits without verifying the relocation type from
the relocation info could corrupt adjacent data.

>  				} else {
>  					pr_warn("relocation against STT_SECTION in non-exec section is not supported!\n");
>  					return -EINVAL;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1782571533.git.xukuohai@huawei.com?part=1

  reply	other threads:[~2026-06-27 17:05 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-27 22:51 [RFC PATCH bpf-next 00/12] bpf: Introduce static-defined tracing probe for BPF Xu Kuohai
2026-06-27 20:51 ` [syzbot ci] " syzbot ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 01/12] libbpf: Prepare bpf SDT probe section for the linker Xu Kuohai
2026-06-27 17:05   ` sashiko-bot [this message]
2026-06-27 22:51 ` [RFC PATCH bpf-next 02/12] libbpf: Introduce bpf SDT probe macros Xu Kuohai
2026-06-27 15:01   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 03/12] libbpf: Add bpf_sdt_notes section parser Xu Kuohai
2026-06-27 15:03   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 04/12] bpf: Create insn_array map for bpf SDT probe Xu Kuohai
2026-06-27 15:18   ` sashiko-bot
2026-06-27 15:34   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 05/12] bpf: Collect SDT probe BTF IDs from BTF decl tags Xu Kuohai
2026-06-27 15:20   ` sashiko-bot
2026-06-27 15:34   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 06/12] bpf: Add type check for SDT probe site Xu Kuohai
2026-06-27 15:04   ` sashiko-bot
2026-06-27 15:22   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 07/12] bpf: Record probe name in SDT map Xu Kuohai
2026-06-27 15:06   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 08/12] libbpf: Add libbpf support to load SDT observer program Xu Kuohai
2026-06-27 15:12   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 09/12] bpf: Add kernel " Xu Kuohai
2026-06-27 15:12   ` sashiko-bot
2026-06-27 15:22   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 10/12] bpf: Support attach and detach for " Xu Kuohai
2026-06-27 17:12   ` sashiko-bot
2026-06-27 22:51 ` [RFC PATCH bpf-next 11/12] bpf, x86: Add JIT support SDT for probe Xu Kuohai
2026-06-27 15:13   ` sashiko-bot
2026-06-27 15:22   ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 12/12] selftests/bpf: Add tests for bpf SDT probe Xu Kuohai
2026-06-27 15:25   ` sashiko-bot

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=20260627170557.03E381F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xukuohai@huaweicloud.com \
    /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