From: sashiko-bot@kernel.org
To: "Tiezhu Yang" <yangtiezhu@loongson.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1] selftests/bpf: Add test for indirect struct_ops trampoline
Date: Fri, 28 Aug 2026 04:36:35 +0000 [thread overview]
Message-ID: <20260828043635.D16DC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828042715.16546-1-yangtiezhu@loongson.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Use-After-Free and data races due to statically assigned and uncleared struct_ops pointer.
--
commit 23e6150eb62c7059e7721142219a9a87264e2e46
Author: Tiezhu Yang <yangtiezhu@loongson.cn>
selftests/bpf: Add test for indirect struct_ops trampoline
This commit adds a test case to verify that arguments passed on the stack
are correctly read by the indirect struct_ops trampoline. It ensures the
correctness of stack offsets on architectures like LoongArch and RISC-V.
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_trampoline.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_trampoline.c
> new file mode 100644
> index 0000000000000..5a21aedd02fc5
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_trampoline.c
> @@ -0,0 +1,41 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <test_progs.h>
> +#include "struct_ops_trampoline.skel.h"
> +
> +#if defined(__loongarch__) || defined(__riscv)
> +static void run_struct_ops_trampoline(void)
> +{
[ ... ]
> + bpf_link__destroy(link);
> +cleanup:
> + struct_ops_trampoline__destroy(skel);
[Severity: High]
Does this call to struct_ops_trampoline__destroy() free the map?
Later in this diff, we see that st_ops_trampoline in bpf_testmod.c is
assigned dynamically allocated memory from this map. When the map is freed
here, st_ops_trampoline appears to become a dangling pointer.
> +}
> +#endif
[ ... ]
> diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> index 850cf4f830c48..be96bbc1b7c04 100644
> --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
> +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
[ ... ]
> @@ -637,6 +640,9 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
>
> bpf_testmod_test_struct_ops3();
>
> + if (st_ops_trampoline && st_ops_trampoline->test_trampoline)
> + st_ops_trampoline->test_trampoline(1, 2, 3, 4, 5, 6, 7, 8, 9999);
[Severity: High]
Since st_ops_trampoline is never cleared after the map is freed, could this
result in a use-after-free?
Any subsequent or parallel test in the suite that triggers
trigger_module_test_read() will invoke bpf_testmod_test_read(), incorrectly
evaluate st_ops_trampoline as valid, and dereference the freed memory.
> +
> struct_arg3 = kmalloc((sizeof(struct bpf_testmod_struct_arg_3) +
> sizeof(int)), GFP_KERNEL);
[ ... ]
> @@ -1619,6 +1625,10 @@ static int bpf_testmod_ops_init_member(const struct btf_type *t,
> ((struct bpf_testmod_ops *)kdata)->data = ((struct bpf_testmod_ops *)udata)->data;
> return 1;
> }
> +
> + if (member->offset == offsetof(struct bpf_testmod_ops, test_trampoline) * 8)
> + st_ops_trampoline = (struct bpf_testmod_ops *)kdata;
[Severity: High]
Is it safe to unconditionally assign this global pointer to the map's
dynamically allocated memory during initialization without setting up a
cleanup mechanism?
Additionally, this assignment appears to occur without locking at map creation
time, meaning parallel test runs could race to overwrite this pointer.
> +
> return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260828042715.16546-1-yangtiezhu@loongson.cn?part=1
next prev parent reply other threads:[~2026-08-28 4:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 4:27 [PATCH bpf-next v1] selftests/bpf: Add test for indirect struct_ops trampoline Tiezhu Yang
2026-08-28 4:36 ` sashiko-bot [this message]
2026-08-28 9:12 ` Tiezhu Yang
2026-08-28 5:29 ` bot+bpf-ci
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=20260828043635.D16DC1F000E9@smtp.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 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.