From: sashiko-bot@kernel.org
To: "Andrii Nakryiko" <andrii@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Add linked_externs test for externs in allocated sections
Date: Fri, 25 Sep 2026 22:58:09 +0000 [thread overview]
Message-ID: <20260925225809.B4AE01F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260925224631.1490488-2-andrii@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] bpf: TOCTOU and missing error check for mkstemp in test_relink()
- [Medium] bpf: Missing NULL check for bpf_object__btf() in test_relink()
--
commit 2e7da3dcbd552604f0f6c052dc8cda7a3628ffb8
Author: Andrii Nakryiko <andrii@kernel.org>
selftests/bpf: Add linked_externs test for externs in allocated sections
This commit adds two objects that define an arena global each and declare the
other one's as extern, linking them into a single skeleton. It also introduces
a test to drive the libbpf linker directly to verify the relinking process.
> diff --git a/tools/testing/selftests/bpf/prog_tests/linked_externs.c b/tools/testing/selftests/bpf/prog_tests/linked_externs.c
> new file mode 100644
> index 0000000000000..29358c82dc356
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/linked_externs.c
[ ... ]
> +/* link in1 on its own first, then link the result with in2 */
> +static void test_relink(const char *in1, const char *in2, const char *sec_name)
> +{
> + char out1[] = "/tmp/linked_externs.XXXXXX", out2[] = "/tmp/linked_externs.XXXXXX";
> + const struct btf_var_secinfo *vi;
> + struct bpf_object *obj = NULL;
> + const struct btf_type *t;
> + struct btf *btf;
> + int i, id, n;
> +
> + close(mkstemp(out1));
> + close(mkstemp(out2));
[Severity: Medium]
Could this result in a Time-Of-Check to Time-Of-Use (TOCTOU) race condition
and silently ignore failures?
mkstemp() can fail, returning -1 and leaving the template unchanged. Because
the return value is discarded, could concurrent test runs end up using the
identical fallback filename "/tmp/linked_externs.XXXXXX" and corrupt each
other's output?
Additionally, even on success, does immediately closing the temporary file and
reopening it by name in a world-writable directory (/tmp) introduce a classic
TOCTOU race condition?
> +
> + if (!ASSERT_OK(link_objs(out1, in1, NULL), "link_stage1") ||
> + !ASSERT_OK(link_objs(out2, out1, in2), "link_stage2"))
> + goto cleanup;
> +
> + obj = bpf_object__open_file(out2, NULL);
> + if (!ASSERT_OK_PTR(obj, "obj_open"))
> + goto cleanup;
> +
> + btf = bpf_object__btf(obj);
> + id = btf__find_by_name_kind(btf, sec_name, BTF_KIND_DATASEC);
[Severity: Medium]
Does this code dereference a potentially NULL pointer?
bpf_object__btf(obj) can return NULL if the loaded BPF object lacks BTF
information. The returned btf pointer is then passed to
btf__find_by_name_kind(), which dereferences it internally (btf->start_id).
Could this lead to a segmentation fault on malformed objects instead of a
graceful test failure (e.g., via ASSERT_OK_PTR())?
> + if (!ASSERT_GT(id, 0, "find_datasec"))
> + goto cleanup;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260925224631.1490488-1-andrii@kernel.org?part=2
next prev parent reply other threads:[~2026-09-25 22:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 22:46 [PATCH bpf-next 1/2] libbpf: Fix static linking of externs placed in allocated sections Andrii Nakryiko
2026-09-25 22:46 ` [PATCH bpf-next 2/2] selftests/bpf: Add linked_externs test for externs " Andrii Nakryiko
2026-09-25 22:58 ` sashiko-bot [this message]
2026-09-25 23:32 ` Andrii Nakryiko
2026-09-25 23:35 ` bot+bpf-ci
2026-09-25 23:35 ` [PATCH bpf-next 1/2] libbpf: Fix static linking of externs placed " bot+bpf-ci
2026-09-25 23:46 ` Andrii Nakryiko
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=20260925225809.B4AE01F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox