From: sashiko-bot@kernel.org
To: "Tiezhu Yang" <yangtiezhu@loongson.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 2/2] selftests/bpf: Handle unaligned access failure in fexit_bpf2bpf
Date: Mon, 02 Nov 2026 08:23:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-193100@kernel.org> (raw)
In-Reply-To: <20261102081230.7063-3-yangtiezhu@loongson.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] selftests/bpf: fexit_bpf2bpf skips tests instead of aligning subprog offset
- [Medium] selftests/bpf: get_unaligned_access_enabled() masks EACCES verifier errors
--
commit 7711595f0d56f0638a8acca1420d5b1c4401c310
Author: Tiezhu Yang <yangtiezhu@loongson.cn>
selftests/bpf: Handle unaligned access failure in fexit_bpf2bpf
This commit adds a get_unaligned_access_enabled() helper and uses it in
fexit_bpf2bpf to skip subtests when bpf_prog_test_load() fails with -EACCES
and CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is not enabled.
> diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
> index d2f2dcc0f2e11..1c0e93dcb3ce5 100644
> --- a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
> +++ b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
[ ... ]
> @@ -76,6 +77,11 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
>
> err = bpf_prog_test_load(target_obj_file, BPF_PROG_TYPE_UNSPEC,
> &tgt_obj, &tgt_fd);
> + if (err < 0 && errno == EACCES && !get_unaligned_access_enabled()) {
> + test__skip();
> + return;
> + }
[Severity: Medium]
Should the packet offset alignment in test_pkt_write_access_subprog() and
new_test_pkt_write_access_subprog() be constrained instead of skipping these
subtests in test_fexit_bpf2bpf_common() and test_fmod_ret_freplace()?
The five subtests (target_yes_callees, func_replace, func_replace_multi,
fmod_ret_freplace, and func_replace_global_func) test BPF-to-BPF fexit,
freplace, and fmod_ret rather than unaligned packet access.
In tools/testing/selftests/bpf/progs/test_pkt_access.c, the caller
test_pkt_access() passes a 2-byte-aligned packet offset (void *)tcp - data.
However, because test_pkt_write_access_subprog() is a global function, the
verifier checks it standalone with an arbitrary scalar off bounded only by
off <= 54:
tools/testing/selftests/bpf/progs/test_pkt_access.c:test_pkt_write_access_subprog() {
...
if (off > sizeof(struct ethhdr) + sizeof(struct ipv6hdr))
return -1;
tcp = data + off;
if (tcp + 1 > data_end)
return -1;
/* make modification to the packet data */
tcp->check++;
...
}
And the replacement program in
tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c has the same pattern in
new_test_pkt_write_access_subprog():
tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c:new_test_pkt_write_access_subprog() {
...
if (off > sizeof(struct ethhdr) + sizeof(struct ipv6hdr))
return -1;
tcp = data + off;
if (tcp + 1 > data_end)
return -1;
/* make modifications to the packet data */
tcp->check++;
...
}
Skipping these tests in fexit_bpf2bpf drops fexit and freplace coverage on
strict-alignment architectures while leaving the other selftests that load
test_pkt_access.bpf.o (pkt_access, dynptr, kfree_skb, and prog_run_opts)
failing with the same -EACCES verifier error.
Would constraining the alignment of off (or performing a 1-byte modification)
in test_pkt_write_access_subprog() and new_test_pkt_write_access_subprog()
allow all of these tests to run on strict-alignment systems?
[ ... ]
> diff --git a/tools/testing/selftests/bpf/unpriv_helpers.c b/tools/testing/selftests/bpf/unpriv_helpers.c
> index c8dd5d8485841..54ce342b3fe41 100644
> --- a/tools/testing/selftests/bpf/unpriv_helpers.c
> +++ b/tools/testing/selftests/bpf/unpriv_helpers.c
> @@ -161,3 +161,8 @@ bool get_kasan_multi_shot_enabled(void)
> {
> return cmdline_contains("kasan_multi_shot");
> }
> +
> +bool get_unaligned_access_enabled(void)
> +{
> + return config_contains("CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y") == 1;
> +}
[Severity: Medium]
Can get_unaligned_access_enabled() cause test_fexit_bpf2bpf_common() and
test_fmod_ret_freplace() to mask genuine -EACCES verifier regressions as
skips?
In tools/testing/selftests/bpf/unpriv_helpers.c, open_config() returns NULL
and config_contains() returns -1 when neither /boot/config-$(uname -r) nor
/proc/config.gz is available in the test environment. Because
get_unaligned_access_enabled() checks for equality with 1, a -1 error return
is treated the same as CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS being disabled,
even on architectures where it is enabled.
In addition, EACCES is the generic error code returned by the BPF verifier for
most verification failures, and test_fexit_bpf2bpf_common() also loads target
objects that do not perform unaligned packet accesses
(./test_pkt_md_access.bpf.o, ./connect4_prog.bpf.o, and
./test_global_func7.bpf.o). Whenever get_unaligned_access_enabled() returns
false, wouldn't any verifier regression returning -EACCES in those programs be
silently reported as skipped instead of failing?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102081230.7063-1-yangtiezhu@loongson.cn?part=2
next prev parent reply other threads:[~2026-11-02 8:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 8:12 [PATCH bpf-next v1 0/2] selftests/bpf: Make some tests skipped Tiezhu Yang
2026-11-02 8:12 ` [PATCH bpf-next v1 1/2] selftests/bpf: Handle EOPNOTSUPP gracefully in test_loader Tiezhu Yang
2026-11-02 8:28 ` sashiko-bot
2026-11-03 2:01 ` Tiezhu Yang
2026-11-02 8:12 ` [PATCH bpf-next v1 2/2] selftests/bpf: Handle unaligned access failure in fexit_bpf2bpf Tiezhu Yang
2026-11-02 8:23 ` sashiko-bot [this message]
2026-11-03 2:06 ` Tiezhu Yang
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=sashiko-outbox-193100@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yangtiezhu@loongson.cn \
/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