All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yonghong Song" <yonghong.song@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 17/20] libbpf: Let the static linker carry .bpf_cleanup relocations
Date: Fri, 18 Sep 2026 05:01:35 +0000	[thread overview]
Message-ID: <20260918050136.2A6DA1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260918044327.3292986-1-yonghong.song@linux.dev>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] bpf/linker: NULL pointer deref in linker_append_elf_relos()
- [Medium] bpf/linker: unaligned memory access in data relocations
- [Low] bpf/linker: multi-line comment style violation
--

commit 2eadf13e135621b2e34d8946fe67664cd72e0e3d
Author: Yonghong Song <yonghong.song@linux.dev>

libbpf: Let the static linker carry .bpf_cleanup relocations

This commit updates the BPF static linker to support .bpf_cleanup relocations.
It specifically adds handling for R_BPF_64_NODYLD32 and R_BPF_64_ABS32 to
process compiler-emitted exception cleanup tables.

> diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c
> index 78f92c39290af..e5c06023cb5b1 100644
> --- a/tools/lib/bpf/linker.c
> +++ b/tools/lib/bpf/linker.c

[ ... ]

> @@ -2274,6 +2275,22 @@ 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 (sym_type == R_BPF_64_NODYLD32 ||
> +					   sym_type == R_BPF_64_ABS32) {
> +					__u32 *val;
> +
> +					/* Two spellings of the one thing: LLVM

[Severity: Low]
This isn't a bug, but does this violate the BPF subsystem multi-line comment
style? The preferred kernel style is to have the opening /* on its own line
rather than putting text on the same line as the marker.

> +					 * emits NODYLD32 for a .long against a
> +					 * section symbol, GNU as emits ABS32
> +					 * (bpf_reloc_type_lookup() maps
> +					 * BFD_RELOC_32 to it), and the value
> +					 * they describe is the same.
> +					 */
> +					val = dst_linked_sec->raw_data + dst_rel->r_offset;

[Severity: High]
Could this lead to a NULL pointer dereference? Looking at
linker_sanity_check_elf_relos(), SHT_NOBITS sections are explicitly allowed
as relocatable sections.

For SHT_NOBITS sections (like .bss), extend_sec() typically skips allocating
raw_data, leaving it as NULL. If we process a relocation against such a
section here, we might compute val = NULL + dst_rel->r_offset and then
dereference it on the next line when handling sec->dst_off.

[Severity: Medium]
Is it also possible to hit an unaligned memory access here?

While executable sections enforce alignment checks in
linker_sanity_check_elf_relos(), there doesn't seem to be an equivalent
alignment check for data section offsets. If an ELF provides an unaligned
r_offset, the direct dereference of the unaligned val pointer might
cause a crash on architectures with strict memory alignment requirements.

> +					if (linker->swapped_endian)
> +						*val = bswap_32(bswap_32(*val) + sec->dst_off);
> +					else
> +						*val += sec->dst_off;
>  				} else {
>  					pr_warn("relocation against STT_SECTION in non-exec section is not supported!\n");
>  					return -EINVAL;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260918044156.3283973-1-yonghong.song@linux.dev?part=17

  reply	other threads:[~2026-09-18  5:01 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18  4:41 [PATCH bpf-next v2 00/20] bpf: Run exception cleanup landing pads when bpf_throw() unwinds Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 01/20] bpf: Accept the compiler's exception cleanup table at program load Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 02/20] bpf: Add the bpf_unwind_resume() kfunc Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 03/20] bpf: Add lookups for exception cleanup resumes and landing pads Yonghong Song
2026-09-18  5:44   ` bot+bpf-ci
2026-09-19  4:55     ` Alexei Starovoitov
2026-09-19 17:42       ` Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 04/20] bpf: Mark the call sites an exception cleanup table covers Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 05/20] bpf: Make exception landing pads reachable in the CFG Yonghong Song
2026-09-18  4:59   ` sashiko-bot
2026-09-19 19:17     ` Yonghong Song
2026-09-18  5:44   ` bot+bpf-ci
2026-09-19 19:32     ` Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 06/20] bpf: Explore the landing pads no call site reaches Yonghong Song
2026-09-18  5:44   ` bot+bpf-ci
2026-09-19 19:32     ` Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 07/20] bpf: Refuse exception cleanup shapes bpf_throw() cannot dispatch Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 08/20] bpf: Walk the exception unwind in the verifier Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 09/20] bpf: Refuse a private stack for a program with an exception cleanup table Yonghong Song
2026-09-18  5:44   ` bot+bpf-ci
2026-09-19 19:37     ` Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 10/20] bpf: Dispatch exception cleanup pads from bpf_throw() Yonghong Song
2026-09-18  5:58   ` bot+bpf-ci
2026-09-19 19:54     ` Yonghong Song
2026-09-18  4:42 ` [PATCH bpf-next v2 11/20] bpf, x86: Dispatch exception cleanup pads at run time Yonghong Song
2026-09-18  5:03   ` sashiko-bot
2026-09-19 20:00     ` Yonghong Song
2026-09-18  5:44   ` bot+bpf-ci
2026-09-19 20:04     ` Yonghong Song
2026-09-18  4:43 ` [PATCH bpf-next v2 12/20] bpf, arm64: " Yonghong Song
2026-09-18  5:44   ` bot+bpf-ci
2026-09-19 20:07     ` Yonghong Song
2026-09-18  4:43 ` [PATCH bpf-next v2 13/20] libbpf: Resolve the compiler's _Unwind_Resume to the kernel's kfunc Yonghong Song
2026-09-18  4:43 ` [PATCH bpf-next v2 14/20] libbpf: Add cleanup_info to bpf_prog_load_opts Yonghong Song
2026-09-18  4:57   ` sashiko-bot
2026-09-19 20:18     ` Yonghong Song
2026-09-18  4:43 ` [PATCH bpf-next v2 15/20] libbpf: Collect .bpf_cleanup records and pass them to the kernel Yonghong Song
2026-09-18  5:00   ` sashiko-bot
2026-09-19 20:21     ` Yonghong Song
2026-09-18  4:43 ` [PATCH bpf-next v2 16/20] libbpf: Carry the exception cleanup table through the light skeleton Yonghong Song
2026-09-18  5:02   ` sashiko-bot
2026-09-19 20:27     ` Yonghong Song
2026-09-18  4:43 ` [PATCH bpf-next v2 17/20] libbpf: Let the static linker carry .bpf_cleanup relocations Yonghong Song
2026-09-18  5:01   ` sashiko-bot [this message]
2026-09-19 20:31     ` Yonghong Song
2026-09-18  5:44   ` bot+bpf-ci
2026-09-19 20:32     ` Yonghong Song
2026-09-18  4:43 ` [PATCH bpf-next v2 18/20] selftests/bpf: Add an end-to-end .bpf_cleanup exception test Yonghong Song
2026-09-18  4:59   ` sashiko-bot
2026-09-18  5:58   ` bot+bpf-ci
2026-09-19 20:34     ` Yonghong Song
2026-09-18  4:43 ` [PATCH bpf-next v2 19/20] selftests/bpf: Cover the exception cleanup shapes the chain does not reach Yonghong Song
2026-09-18  5:01   ` sashiko-bot
2026-09-18  5:44   ` bot+bpf-ci
2026-09-19 21:13     ` Yonghong Song
2026-09-18  4:43 ` [PATCH bpf-next v2 20/20] selftests/bpf: Load an exception cleanup program from a light skeleton Yonghong Song

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=20260918050136.2A6DA1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.