* Re: [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments
@ 2026-11-27 16:11 kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-11-27 16:11 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp, Dan Carpenter
Unfiltered warning: this smatch report is sent as-is and has not been
reviewed for false positives, so please treat it with due skepticism.
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20261123223227.745345-2-almagui@kernel.org>
References: <20261123223227.745345-2-almagui@kernel.org>
TO: Alan Maguire <almagui@kernel.org>
TO: ast@kernel.org
TO: daniel@iogearbox.net
TO: andrii@kernel.org
CC: eddyz87@gmail.com
CC: memxor@gmail.com
CC: martin.lau@linux.dev
CC: song@kernel.org
CC: yonghong.song@linux.dev
CC: jolsa@kernel.org
CC: emil@etsalapatis.com
CC: ihor.solodrai@linux.dev
CC: john.fastabend@gmail.com
CC: bpf@vger.kernel.org
CC: Alan Maguire <almagui@kernel.org>
Hi Alan,
kernel test robot noticed the following build warnings:
[auto build test WARNING on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Alan-Maguire/libbpf-Support-CO-RE-relocation-of-tracing-program-arguments/20261123-223221
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link: https://lore.kernel.org/r/20261123223227.745345-2-almagui%40kernel.org
patch subject: [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments
:::::: branch date: 4 days ago
:::::: commit date: 4 days ago
config: arm-randconfig-2200-20261126 (https://download.01.org/0day-ci/archive/20261127/20261127170440.mE7JCAST-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 8.5.0
smatch: v0.5.0-9187-g5189e3fb
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/20261127170440.mE7JCAST-lkp@intel.com/
smatch warnings:
kernel/bpf/../../tools/lib/bpf/relo_core.c:1337 bpf_core_calc_relo() error: we previously assumed 'targ_spec' could be null (see line 1322)
vim +/targ_spec +1337 kernel/bpf/../../tools/lib/bpf/relo_core.c
2a6fa26be8e26a Alan Maguire 2026-11-23 1292
b0588390dbcedc Alexei Starovoitov 2021-07-20 1293 static int bpf_core_calc_relo(const char *prog_name,
b0588390dbcedc Alexei Starovoitov 2021-07-20 1294 const struct bpf_core_relo *relo,
b0588390dbcedc Alexei Starovoitov 2021-07-20 1295 int relo_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20 1296 const struct bpf_core_spec *local_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20 1297 const struct bpf_core_spec *targ_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20 1298 struct bpf_core_relo_res *res)
b0588390dbcedc Alexei Starovoitov 2021-07-20 1299 {
b0588390dbcedc Alexei Starovoitov 2021-07-20 1300 int err = -EOPNOTSUPP;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1301
b0588390dbcedc Alexei Starovoitov 2021-07-20 1302 res->orig_val = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1303 res->new_val = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1304 res->poison = false;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1305 res->validate = true;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1306 res->fail_memsz_adjust = false;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1307 res->orig_sz = res->new_sz = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1308 res->orig_type_id = res->new_type_id = 0;
2a6fa26be8e26a Alan Maguire 2026-11-23 1309 res->widen_func_arg = false;
2a6fa26be8e26a Alan Maguire 2026-11-23 1310 res->func_arg_signed = false;
2a6fa26be8e26a Alan Maguire 2026-11-23 1311 res->func_arg_slot_off = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1312
b0588390dbcedc Alexei Starovoitov 2021-07-20 1313 if (core_relo_is_field_based(relo->kind)) {
b0588390dbcedc Alexei Starovoitov 2021-07-20 1314 err = bpf_core_calc_field_relo(prog_name, relo, local_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20 1315 &res->orig_val, &res->orig_sz,
b0588390dbcedc Alexei Starovoitov 2021-07-20 1316 &res->orig_type_id, &res->validate);
b0588390dbcedc Alexei Starovoitov 2021-07-20 1317 err = err ?: bpf_core_calc_field_relo(prog_name, relo, targ_spec,
b0588390dbcedc Alexei Starovoitov 2021-07-20 1318 &res->new_val, &res->new_sz,
b0588390dbcedc Alexei Starovoitov 2021-07-20 1319 &res->new_type_id, NULL);
b0588390dbcedc Alexei Starovoitov 2021-07-20 1320 if (err)
b0588390dbcedc Alexei Starovoitov 2021-07-20 1321 goto done;
2a6fa26be8e26a Alan Maguire 2026-11-23 @1322 if (relo->kind == BPF_CORE_FIELD_BYTE_OFFSET && targ_spec &&
2a6fa26be8e26a Alan Maguire 2026-11-23 1323 bpf_core_is_be_small_func_arg(targ_spec, &res->func_arg_signed)) {
2a6fa26be8e26a Alan Maguire 2026-11-23 1324 /* context slots are 8-byte aligned */
2a6fa26be8e26a Alan Maguire 2026-11-23 1325 res->widen_func_arg = true;
2a6fa26be8e26a Alan Maguire 2026-11-23 1326 res->func_arg_slot_off = res->new_val & ~7ULL;
2a6fa26be8e26a Alan Maguire 2026-11-23 1327 }
b0588390dbcedc Alexei Starovoitov 2021-07-20 1328 /* Validate if it's safe to adjust load/store memory size.
b0588390dbcedc Alexei Starovoitov 2021-07-20 1329 * Adjustments are performed only if original and new memory
b0588390dbcedc Alexei Starovoitov 2021-07-20 1330 * sizes differ.
b0588390dbcedc Alexei Starovoitov 2021-07-20 1331 */
b0588390dbcedc Alexei Starovoitov 2021-07-20 1332 res->fail_memsz_adjust = false;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1333 if (res->orig_sz != res->new_sz) {
b0588390dbcedc Alexei Starovoitov 2021-07-20 1334 const struct btf_type *orig_t, *new_t;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1335
74753e1462e773 Alexei Starovoitov 2021-12-01 1336 orig_t = btf_type_by_id(local_spec->btf, res->orig_type_id);
74753e1462e773 Alexei Starovoitov 2021-12-01 @1337 new_t = btf_type_by_id(targ_spec->btf, res->new_type_id);
b0588390dbcedc Alexei Starovoitov 2021-07-20 1338
b0588390dbcedc Alexei Starovoitov 2021-07-20 1339 /* There are two use cases in which it's safe to
b0588390dbcedc Alexei Starovoitov 2021-07-20 1340 * adjust load/store's mem size:
b0588390dbcedc Alexei Starovoitov 2021-07-20 1341 * - reading a 32-bit kernel pointer, while on BPF
b0588390dbcedc Alexei Starovoitov 2021-07-20 1342 * size pointers are always 64-bit; in this case
b0588390dbcedc Alexei Starovoitov 2021-07-20 1343 * it's safe to "downsize" instruction size due to
b0588390dbcedc Alexei Starovoitov 2021-07-20 1344 * pointer being treated as unsigned integer with
b0588390dbcedc Alexei Starovoitov 2021-07-20 1345 * zero-extended upper 32-bits;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1346 * - reading unsigned integers, again due to
b0588390dbcedc Alexei Starovoitov 2021-07-20 1347 * zero-extension is preserving the value correctly.
b0588390dbcedc Alexei Starovoitov 2021-07-20 1348 *
b0588390dbcedc Alexei Starovoitov 2021-07-20 1349 * In all other cases it's incorrect to attempt to
b0588390dbcedc Alexei Starovoitov 2021-07-20 1350 * load/store field because read value will be
b0588390dbcedc Alexei Starovoitov 2021-07-20 1351 * incorrect, so we poison relocated instruction.
b0588390dbcedc Alexei Starovoitov 2021-07-20 1352 */
b0588390dbcedc Alexei Starovoitov 2021-07-20 1353 if (btf_is_ptr(orig_t) && btf_is_ptr(new_t))
b0588390dbcedc Alexei Starovoitov 2021-07-20 1354 goto done;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1355 if (btf_is_int(orig_t) && btf_is_int(new_t) &&
b0588390dbcedc Alexei Starovoitov 2021-07-20 1356 btf_int_encoding(orig_t) != BTF_INT_SIGNED &&
b0588390dbcedc Alexei Starovoitov 2021-07-20 1357 btf_int_encoding(new_t) != BTF_INT_SIGNED)
b0588390dbcedc Alexei Starovoitov 2021-07-20 1358 goto done;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1359
b0588390dbcedc Alexei Starovoitov 2021-07-20 1360 /* mark as invalid mem size adjustment, but this will
b0588390dbcedc Alexei Starovoitov 2021-07-20 1361 * only be checked for LDX/STX/ST insns
b0588390dbcedc Alexei Starovoitov 2021-07-20 1362 */
b0588390dbcedc Alexei Starovoitov 2021-07-20 1363 res->fail_memsz_adjust = true;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1364 }
b0588390dbcedc Alexei Starovoitov 2021-07-20 1365 } else if (core_relo_is_type_based(relo->kind)) {
4b443bc1785f28 Andrii Nakryiko 2021-12-12 1366 err = bpf_core_calc_type_relo(relo, local_spec, &res->orig_val, &res->validate);
4b443bc1785f28 Andrii Nakryiko 2021-12-12 1367 err = err ?: bpf_core_calc_type_relo(relo, targ_spec, &res->new_val, NULL);
b0588390dbcedc Alexei Starovoitov 2021-07-20 1368 } else if (core_relo_is_enumval_based(relo->kind)) {
b0588390dbcedc Alexei Starovoitov 2021-07-20 1369 err = bpf_core_calc_enumval_relo(relo, local_spec, &res->orig_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20 1370 err = err ?: bpf_core_calc_enumval_relo(relo, targ_spec, &res->new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20 1371 }
b0588390dbcedc Alexei Starovoitov 2021-07-20 1372
b0588390dbcedc Alexei Starovoitov 2021-07-20 1373 done:
b0588390dbcedc Alexei Starovoitov 2021-07-20 1374 if (err == -EUCLEAN) {
b0588390dbcedc Alexei Starovoitov 2021-07-20 1375 /* EUCLEAN is used to signal instruction poisoning request */
b0588390dbcedc Alexei Starovoitov 2021-07-20 1376 res->poison = true;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1377 err = 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1378 } else if (err == -EOPNOTSUPP) {
b0588390dbcedc Alexei Starovoitov 2021-07-20 1379 /* EOPNOTSUPP means unknown/unsupported relocation */
df3153758ddba5 Andrii Nakryiko 2026-06-24 1380 pr_warn("prog '%s': relo #%d: unrecognized CO-RE relocation %s (%u) at insn #%u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20 1381 prog_name, relo_idx, core_relo_kind_str(relo->kind),
b0588390dbcedc Alexei Starovoitov 2021-07-20 1382 relo->kind, relo->insn_off / 8);
b0588390dbcedc Alexei Starovoitov 2021-07-20 1383 }
b0588390dbcedc Alexei Starovoitov 2021-07-20 1384
b0588390dbcedc Alexei Starovoitov 2021-07-20 1385 return err;
b0588390dbcedc Alexei Starovoitov 2021-07-20 1386 }
b0588390dbcedc Alexei Starovoitov 2021-07-20 1387
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH bpf-next 0/7] libbpf, bpf: Utilize CO-RE for BPF program parameter presence, ordering
@ 2026-11-23 22:32 Alan Maguire
[not found] ` <20261123223227.745345-2-almagui@kernel.org>
0 siblings, 1 reply; 4+ messages in thread
From: Alan Maguire @ 2026-11-23 22:32 UTC (permalink / raw)
To: ast, daniel, andrii
Cc: eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil,
ihor.solodrai, john.fastabend, bpf, Alan Maguire
Currently the BPF_PROG() family of macros greatly facilitates
BPF tracing/LSM program writing by allowing specification
of function, tracepoint or LSM hook arguments directly by
name and type. These are then mapped to a context struct
consisting of a u64 array, with one value for each argument,
with by-value structs > 8 bytes taking two slots.
By instead creating a structure with named members, we can
bring a Compile Once, Run Everywhere experience to parameter
specifications via a new BPF_PROG_CORE() macro. This will
better handle cases like the following:
Problem: A tracing program only needs to use one parameter
from a multi-parameter kernel function signature, but verification
can fail if the function signature changes due to added or removed
parameters which are irrelevant to the case in hand.
Solution: Only specify the needed parameter in BPF_PROG_CORE()
Example:
/*
* Prototype for filename_unlinkat is:
* int filename_unlinkat(int dfd, struct filename * name);
*/
SEC("fentry/filename_unlinkat")
int BPF_PROG_CORE(handle, struct filename *, name)
{
if (bpf_func_arg_exists(name))
...
Problem: Ordering of parameters changes for a BPF LSM program
Solution: Again use BPF_PROG_CORE() which is resilient to
ordering changes as these become CO-RE relocations in the
context structure. Return values should be tagged with
__bpf_func_ret .
Problem: A parameter type changes
Solution: Use ___<new> named variants with old and new
types:
int BPF_PROG_CORE(handle, struct vm_area_struct *vma,
struct mm_area *vma___new)
{
if (bpf_func_arg_exists(vma___new))
...
else if (bpf_func_arg_exists(vma)
Because the solution is purely in libbpf, the support needs
no kernel changes, aside from the light skeleton case,
where CO-RE relocation is done in-kernel (support for the
latter is added in patch 2). Patch 5 provides a test
that programs can use to see if support is present.
Support covers fentry, fexit, fmod_ret, fsession, tp_btf,
lsm_cgroup and BPF LSM programs.
In short, we are making use of BPF CO-RE to extend a CO-RE
experience to program parameter ordering, presence and
handling of parameter type changes.
Limitations: tp_btf programs require >= 5.10 kernel since
it is the first kernel that makes tp_btf parameter names
available, while on big-endian (s390x) platforms, signed values
smaller than 8 bytes cannot be read.
This support requires BTF declaration tag support in clang/gcc
to work; because gcc does not support declaration tags on types
we add a marker within the struct itself.
Patch 1 adds libbpf support.
Patch 2 adds kernel-based lskel support.
Patch 3 tests tracing program support.
Patch 4 tests BPF LSM support.
Patch 5 provides a test BPF program writers can use -
bpf_func_args_supported() - to probe for support.
Patch 6 tests that probe.
Patch 7 documents the support.
Alan Maguire (7):
libbpf: Support CO-RE relocation of tracing program arguments
bpf: Support CO-RE relocation of tracing program arguments
selftests/bpf: Test CO-RE relocation of tracing program arguments
selftests/bpf: Test CO-RE relocation of BPF LSM program arguments
libbpf: Report function argument relocation support via type existence
selftests/bpf: Test detection of function argument relocation support
Documentation/bpf: Describe CO-RE relocation of function arguments
Documentation/bpf/libbpf/libbpf_overview.rst | 190 ++++++++
Documentation/bpf/llvm_reloc.rst | 95 ++++
include/linux/bpf.h | 2 +
kernel/bpf/btf.c | 38 ++
kernel/bpf/check_btf.c | 1 +
tools/lib/bpf/bpf_tracing.h | 195 ++++++++
tools/lib/bpf/libbpf.c | 142 +++++-
tools/lib/bpf/relo_core.c | 458 +++++++++++++++++-
tools/lib/bpf/relo_core.h | 29 ++
tools/testing/selftests/bpf/Makefile.skel | 3 +-
.../selftests/bpf/prog_tests/func_args_core.c | 325 +++++++++++++
.../selftests/bpf/progs/func_args_core.c | 241 +++++++++
.../selftests/bpf/progs/func_args_core_lsm.c | 156 ++++++
.../bpf/progs/func_args_core_lsm_cgroup.c | 40 ++
14 files changed, 1905 insertions(+), 10 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/func_args_core.c
create mode 100644 tools/testing/selftests/bpf/progs/func_args_core.c
create mode 100644 tools/testing/selftests/bpf/progs/func_args_core_lsm.c
create mode 100644 tools/testing/selftests/bpf/progs/func_args_core_lsm_cgroup.c
--
2.56.0
^ permalink raw reply [flat|nested] 4+ messages in thread[parent not found: <20261123223227.745345-2-almagui@kernel.org>]
* Re: [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments [not found] ` <20261123223227.745345-2-almagui@kernel.org> @ 2026-11-23 22:53 ` sashiko-bot 2026-11-23 23:23 ` bot+bpf-ci 1 sibling, 0 replies; 4+ messages in thread From: sashiko-bot @ 2026-11-23 22:53 UTC (permalink / raw) To: Alan Maguire; +Cc: bpf Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] libbpf: wrong big-endian relocation for signed sub-8-byte tp_btf args - [Medium] libbpf: pointer argument size and offset mismatch on 32-bit target BTF - [Low] libbpf: multi-line comment style and misplaced comment in relo_core.c -- commit 966987a90447045d3ff50e58c43a513399cdbc27 Author: Alan Maguire <almagui@kernel.org> libbpf: Support CO-RE relocation of tracing program arguments This commit adds CO-RE relocation support for tracing program arguments described by structs tagged with __bpf_func_args and introduces the BPF_PROG_CORE() convenience macro. > diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c > index 2672623a41989..2f6627952220b 100644 > --- a/tools/lib/bpf/relo_core.c > +++ b/tools/lib/bpf/relo_core.c [ ... ] > + /* sub-8-byte arguments live in the low-order bytes of their slot, > + * including structs and unions passed by value, which, e.g., s390 > + * passes in registers like integers of the same size > + */ > + sz = btf__resolve_size(targ_btf, type_id); > + if (btf_is_big_endian(targ_btf) && sz > 0 && sz < 8) > + slot_off += 8 - sz; [ ... ] > @@ -734,10 +1092,17 @@ static int bpf_core_calc_field_relo(const char *prog_name, > return 0; > } > > - m = btf_members(t) + acc->idx; > - mt = skip_mods_and_typedefs(spec->btf, m->type, &field_type_id); > + if (btf_kind(t) == BTF_KIND_FUNC) { > + /* function argument (or return value), never a bitfield */ > + mt = skip_mods_and_typedefs(spec->btf, func_arg_type(spec->btf, t, acc->idx), > + &field_type_id); > + bit_sz = 0; > + } else { > + m = btf_members(t) + acc->idx; > + mt = skip_mods_and_typedefs(spec->btf, m->type, &field_type_id); > + bit_sz = btf_member_bitfield_size(t, acc->idx); > + } [Severity: Medium] Does relocating a pointer argument against 32-bit target BTF downsize the context load to 4 bytes and misalign the offset on 32-bit big-endian targets? Unlike func_arg_slot_sz(), which checks btf_is_ptr(t) and returns 8, bpf_core_calc_field_relo() falls through to btf__resolve_size() for BTF_KIND_FUNC arguments. On 32-bit target BTF, btf__resolve_size() returns 4 for BTF_KIND_PTR, so bpf_core_patch_insn() shrinks the 8-byte context load to BPF_W, and bpf_core_match_func_arg() adds 4 to slot_off on big-endian targets. However, context slots are always u64 and btf_ctx_access() requires pointer loads from the context array to be 8-byte aligned with size == sizeof(u64), so the verifier will reject the program. [ ... ] > @@ -893,6 +1258,38 @@ static int bpf_core_calc_enumval_relo(const struct bpf_core_relo *relo, > * with each other. Otherwise, libbpf will refuse to proceed due to ambiguity. > * If instruction has to be poisoned, *poison will be set to true. > */ > +/* Whether a target spec refers to an integer or enum function argument (or > + * return value), rather than to a member of a struct passed by value, that is > + * smaller than 8 bytes on a big-endian target. Such arguments are in the > + * low-order bytes of their context slot, where the verifier doesn't allow > + * loads, but the calling conventions of big-endian architectures with BPF > + * trampolines (s390x, powerpc64) extend them to 64 bits. > + */ [Severity: Low] This isn't a bug, but bpf_core_is_be_small_func_arg() is inserted between the function comment for bpf_core_calc_relo() and bpf_core_calc_relo() itself. Also, the new multi-line comments in tools/lib/bpf/libbpf.c, tools/lib/bpf/relo_core.c, and tools/lib/bpf/relo_core.h place text on the opening /* line rather than putting /* on its own line per BPF comment style. > +static bool bpf_core_is_be_small_func_arg(const struct bpf_core_spec *spec, > + bool *is_signed) > +{ > + const struct bpf_core_accessor *acc; > + const struct btf_type *t; > + __u32 id; > + __s64 sz; > + > + if (spec->len != 2 || !btf_is_big_endian(spec->btf)) > + return false; > + acc = &spec->spec[1]; > + t = btf_type_by_id(spec->btf, acc->type_id); > + if (!t || btf_kind(t) != BTF_KIND_FUNC) > + return false; > + t = skip_mods_and_typedefs(spec->btf, func_arg_type(spec->btf, t, acc->idx), &id); > + if (!t || (!btf_is_int(t) && !btf_is_any_enum(t))) > + return false; > + sz = btf__resolve_size(spec->btf, id); > + if (sz <= 0 || sz >= 8) > + return false; > + *is_signed = (btf_is_any_enum(t) && BTF_INFO_KFLAG(t->info)) || > + (btf_is_int(t) && (btf_int_encoding(t) & BTF_INT_SIGNED)); > + return true; > +} [ ... ] > @@ -1100,6 +1506,38 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn, > return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx); > } > > + if (res->widen_func_arg && class == BPF_LDX) { > + __u8 mode = BPF_MODE(insn->code); > + > + if (insn_bpf_size_to_bytes(insn) != res->orig_sz) { > + pr_warn("prog '%s': relo #%d: insn #%d (LDX) unexpected mem size: got %d, exp %u\n", > + prog_name, relo_idx, insn_idx, > + insn_bpf_size_to_bytes(insn), res->orig_sz); > + return -EINVAL; > + } > + /* An 8-byte load of the whole slot yields the argument > + * as extended to 64 bits by the calling convention, > + * which is what the original load yields only if it > + * extends it the same way. > + */ > + if (!(mode == BPF_MEM && !res->func_arg_signed) && > + !(mode == BPF_MEMSX && res->func_arg_signed && > + res->orig_sz == res->new_sz)) { > + pr_warn("prog '%s': relo #%d: insn #%d (LDX) can't load function argument smaller than 8 bytes on big-endian target. " > + "Make sure to use zero-extending loads of unsigned integers or sign-extending loads of signed ones.\n", > + prog_name, relo_idx, insn_idx); > + return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx); > + } > + > + orig_val = insn->off; > + insn->off = res->func_arg_slot_off; > + insn->code = BPF_LDX | BPF_MEM | BPF_DW; [Severity: Medium] For tp_btf programs on big-endian targets, does widening a BPF_MEMSX load of a signed sub-8-byte argument to BPF_DW corrupt negative values? Unlike BPF trampolines, raw tracepoint probes populate context slots via __CAST_TO_U64() in include/trace/bpf_probe.h: include/trace/bpf_probe.h:__CAST_TO_U64() { #define __CAST_TO_U64(x) ({ \ typeof(x) __src = (x); \ UINTTYPE(sizeof(x)) __dst; \ memcpy(&__dst, &__src, sizeof(__dst)); \ (u64)__dst; }) } Because __CAST_TO_U64() copies the argument into an unsigned integer of the same width before casting to u64, sub-8-byte signed tracepoint arguments are always zero-extended in their 64-bit context slot rather than sign-extended. Treating res->func_arg_signed as true for tp_btf candidates causes bpf_core_patch_insn() to rewrite BPF_MEMSX loads into BPF_DW loads that leave zeros in the upper 32/48/56 bits of negative values, while poisoning BPF_MEM loads that would have read the zero-extended slot value as expected. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261123223227.745345-1-almagui@kernel.org?part=1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments [not found] ` <20261123223227.745345-2-almagui@kernel.org> 2026-11-23 22:53 ` [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments sashiko-bot @ 2026-11-23 23:23 ` bot+bpf-ci 2026-11-24 20:17 ` Andrey Grodzovsky 1 sibling, 1 reply; 4+ messages in thread From: bot+bpf-ci @ 2026-11-23 23:23 UTC (permalink / raw) To: almagui, ast, daniel, andrii Cc: eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai, john.fastabend, bpf, almagui, ast, andrii, daniel, martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai [-- Attachment #1: Type: text/plain, Size: 4857 bytes --] > libbpf: Support CO-RE relocation of tracing program arguments TL;DR: - Changing attach target or type after bpf_object__prepare() may silently load stale argument offsets, reading the wrong arguments - bpf_tracing.h comments advise by-value struct member access that can fail to load (non-8-byte-aligned offsets) > diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h > --- a/tools/lib/bpf/bpf_tracing.h > +++ b/tools/lib/bpf/bpf_tracing.h [ ... ] > + * On big-endian architectures (e.g., s390x), the verifier only allows loads > + * of whole 8-byte context slots, so loads of integer and enum arguments (and > + * return values) smaller than 8 bytes are widened to their slot. That only [ ... ] > + * Structs passed by value that are larger than 8 bytes can't be copied out > + * of the program context as a whole, so they can't be used as arguments of > + * BPF_PROG_CORE; use an explicit __bpf_func_args struct and access their > + * members individually instead. Is this advice accurate for every struct? btf_ctx_access() rejects any context offset that is not a multiple of 8, on all architectures: if (off % 8) { bpf_log(log, "func '%s' offset %d is not multiple of 8\n", tname, off); return false; } Nested member matching produces slot_offset + member_offset, so a member of a by-value struct argument at a non-8-byte-aligned offset can never be read. For example, with bpf_testmod_test_struct_arg_9(..., struct bpf_testmod_struct_arg_5 h, long i), where the struct is { char a; short b; int c; long d; }: struct args9 { struct bpf_testmod_struct_arg_5 h; } __bpf_func_args; ... return args->h.c; /* ctx offset 7*8 + 4 = 60 */ This fails to load with "offset 60 is not multiple of 8", yet it is what the comment recommends. BPF_PROG2() handles this struct by loading whole u64 slots. The same applies to by-value structs of 8 bytes or less with members at a non-zero offset, such as { int a; int b; }. Also, the big-endian paragraph says "the verifier only allows loads of whole 8-byte context slots". bpf_tracing_ctx_access() only requires off % size == 0, so narrow loads at the start of a slot are accepted. The actual constraint is 8-byte-aligned offsets, which is how the commit message describes it ("only allows 8-byte-aligned context accesses"). Could both comments describe the 8-byte-aligned offset rule instead? > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c [ ... ] > +/* Find the BTF type of the attach target of a BTF-attached tracing program */ > +static int bpf_prog_attach_target(const struct bpf_program *prog, > + const struct btf **btf, __u32 *btf_id) > +{ [ ... ] > + if (prog->attach_btf_id) { > + /* set via bpf_program__set_attach_target() */ > + btf_obj_fd = prog->attach_btf_obj_fd; > + btf_type_id = prog->attach_btf_id; > + } else { > + const char *attach_name = strchr(prog->sec_name, '/'); Function-argument relocations are now resolved during bpf_object__prepare(): bpf_object__prepare() -> bpf_object__relocate() -> bpf_object__relocate_core() -> bpf_core_resolve_relo() -> bpf_core_args_find_cands() -> bpf_prog_attach_target() bpf_program__set_attach_target() and bpf_program__set_expected_attach_type() only reject obj->state >= OBJ_LOADED, so both still succeed in OBJ_PREPARED. Before this patch nothing in prepare read the attach target, so open -> bpf_object__prepare() -> bpf_program__set_attach_target() -> bpf_object__load() worked. With __bpf_func_args or BPF_PROG_CORE() in use, that sequence now loads instructions whose context offsets and sizes were computed for the old target. At load time libbpf_prepare_prog_load() skips resolution because prog->attach_btf_id is non-zero, and the new attach_btf_id is passed to the kernel, so nothing is redone and nothing reports an error. For example, SEC("fentry/foo") with struct args { int a; int b; } and foo(int a, int b). After prepare, bpf_program__set_attach_target(prog, 0, "bar") with bar(int b, int a) loads fine, and args->a reads bar's slot 0, which is b. The verifier accepts it because both slots are scalars. Changing fentry to fexit via set_expected_attach_type() after prepare similarly leaves a __bpf_func_ret member resolved as missing. Can these setters be refused in OBJ_PREPARED for programs with function argument relocations, or can the target used during relocation be recorded and compared at load/clone time? The commit message does not mention this limitation, and no later commit in the series changes it. --- 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/45283084474 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments 2026-11-23 23:23 ` bot+bpf-ci @ 2026-11-24 20:17 ` Andrey Grodzovsky 0 siblings, 0 replies; 4+ messages in thread From: Andrey Grodzovsky @ 2026-11-24 20:17 UTC (permalink / raw) To: bot+bpf-ci Cc: almagui, ast, daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai, john.fastabend, bpf, martin.lau, mason On Mon, Nov 23, 2026 at 6:23 PM <bot+bpf-ci@kernel.org> wrote: > > > libbpf: Support CO-RE relocation of tracing program arguments > > TL;DR: > - Changing attach target or type after bpf_object__prepare() may silently load > stale argument offsets, reading the wrong arguments > - bpf_tracing.h comments advise by-value struct member access that can fail to > load (non-8-byte-aligned offsets) > > > diff --git a/tools/lib/bpf/bpf_tracing.h b/tools/lib/bpf/bpf_tracing.h > > --- a/tools/lib/bpf/bpf_tracing.h > > +++ b/tools/lib/bpf/bpf_tracing.h > > [ ... ] > > > + * On big-endian architectures (e.g., s390x), the verifier only allows loads > > + * of whole 8-byte context slots, so loads of integer and enum arguments (and > > + * return values) smaller than 8 bytes are widened to their slot. That only > > [ ... ] > > > + * Structs passed by value that are larger than 8 bytes can't be copied out > > + * of the program context as a whole, so they can't be used as arguments of > > + * BPF_PROG_CORE; use an explicit __bpf_func_args struct and access their > > + * members individually instead. > > Is this advice accurate for every struct? > > btf_ctx_access() rejects any context offset that is not a multiple of 8, on > all architectures: > > if (off % 8) { > bpf_log(log, "func '%s' offset %d is not multiple of 8\n", tname, off); > return false; > } > > Nested member matching produces slot_offset + member_offset, so a member of > a by-value struct argument at a non-8-byte-aligned offset can never be read. > For example, with bpf_testmod_test_struct_arg_9(..., struct > bpf_testmod_struct_arg_5 h, long i), where the struct is { char a; short b; > int c; long d; }: > > struct args9 { struct bpf_testmod_struct_arg_5 h; } __bpf_func_args; > ... return args->h.c; /* ctx offset 7*8 + 4 = 60 */ > > This fails to load with "offset 60 is not multiple of 8", yet it is what the > comment recommends. BPF_PROG2() handles this struct by loading whole u64 > slots. The same applies to by-value structs of 8 bytes or less with members > at a non-zero offset, such as { int a; int b; }. > > Also, the big-endian paragraph says "the verifier only allows loads of whole > 8-byte context slots". bpf_tracing_ctx_access() only requires off % size == > 0, so narrow loads at the start of a slot are accepted. The actual > constraint is 8-byte-aligned offsets, which is how the commit message > describes it ("only allows 8-byte-aligned context accesses"). > > Could both comments describe the 8-byte-aligned offset rule instead? > > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > > --- a/tools/lib/bpf/libbpf.c > > +++ b/tools/lib/bpf/libbpf.c > > [ ... ] > > > +/* Find the BTF type of the attach target of a BTF-attached tracing program */ > > +static int bpf_prog_attach_target(const struct bpf_program *prog, > > + const struct btf **btf, __u32 *btf_id) > > +{ > > [ ... ] > > > + if (prog->attach_btf_id) { > > + /* set via bpf_program__set_attach_target() */ > > + btf_obj_fd = prog->attach_btf_obj_fd; > > + btf_type_id = prog->attach_btf_id; > > + } else { > > + const char *attach_name = strchr(prog->sec_name, '/'); > > Function-argument relocations are now resolved during bpf_object__prepare(): > > bpf_object__prepare() -> bpf_object__relocate() -> bpf_object__relocate_core() > -> bpf_core_resolve_relo() -> bpf_core_args_find_cands() > -> bpf_prog_attach_target() > > bpf_program__set_attach_target() and bpf_program__set_expected_attach_type() > only reject obj->state >= OBJ_LOADED, so both still succeed in OBJ_PREPARED. > Before this patch nothing in prepare read the attach target, so open -> > bpf_object__prepare() -> bpf_program__set_attach_target() -> > bpf_object__load() worked. This also means one unresolvable MANUAL program fails the whole object, it would manifest now during the early bpf_object_prepare() instead of only during later bpf_program__load() which might even never come at all if the user doens't need this specific program. So in total this somewhat increases fragility/decrease robustness against load failures that manual loading previously provided. Andrey > > With __bpf_func_args or BPF_PROG_CORE() in use, that sequence now loads > instructions whose context offsets and sizes were computed for the old > target. At load time libbpf_prepare_prog_load() skips resolution because > prog->attach_btf_id is non-zero, and the new attach_btf_id is passed to the > kernel, so nothing is redone and nothing reports an error. > > For example, SEC("fentry/foo") with struct args { int a; int b; } and foo(int > a, int b). After prepare, bpf_program__set_attach_target(prog, 0, "bar") > with bar(int b, int a) loads fine, and args->a reads bar's slot 0, which is > b. The verifier accepts it because both slots are scalars. Changing fentry > to fexit via set_expected_attach_type() after prepare similarly leaves a > __bpf_func_ret member resolved as missing. > > Can these setters be refused in OBJ_PREPARED for programs with function > argument relocations, or can the target used during relocation be recorded > and compared at load/clone time? The commit message does not mention this > limitation, and no later commit in the series changes it. > > > --- > AI reviewed your patch. Please fix the bug or email reply why it's not a bug. > See: https://urldefense.com/v3/__https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md__;!!BmdzS3_lV9HdKG8!w-hd0PfhYJsIrtg22Giy2FnAvkiYA7LGfOELMjPH8a2ryQInaef28p4GeE55YdQMRWRwtRe0FeqVsZVHDfyK7NCmfxnc9Vjl$ > > CI run summary: https://urldefense.com/v3/__https://github.com/kernel-patches/bpf/actions/runs/45283084474__;!!BmdzS3_lV9HdKG8!w-hd0PfhYJsIrtg22Giy2FnAvkiYA7LGfOELMjPH8a2ryQInaef28p4GeE55YdQMRWRwtRe0FeqVsZVHDfyK7NCmf4lscwP2$ ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-27 16:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 16:11 [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2026-11-23 22:32 [PATCH bpf-next 0/7] libbpf, bpf: Utilize CO-RE for BPF program parameter presence, ordering Alan Maguire
[not found] ` <20261123223227.745345-2-almagui@kernel.org>
2026-11-23 22:53 ` [PATCH bpf-next 1/7] libbpf: Support CO-RE relocation of tracing program arguments sashiko-bot
2026-11-23 23:23 ` bot+bpf-ci
2026-11-24 20:17 ` Andrey Grodzovsky
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.