BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thiébaud Weksteen" <tweek@google.com>
Cc: selinux@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 5/5] selftests/bpf: add loader_load_fd tests
Date: Thu, 13 Aug 2026 00:36:37 +0000	[thread overview]
Message-ID: <20260813003638.4E52D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260813002618.3755631-6-tweek@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Unchecked pointer returns from libelf functions in `create_loader_elf` will cause a SIGSEGV upon allocation failure.
--

--- Patch [5]: [PATCH bpf-next 5/5] selftests/bpf: add loader_load_fd tests ---
commit b9a0b98c13acbc44d106f86733ac4cdd18481ce7
Author: Thiébaud Weksteen <tweek@google.com>

selftests/bpf: add loader_load_fd tests

This commit adds user-space selftests for the BPF_LOADER_LOAD_FD command.
The test ELF is generated based on the existing light skeleton generator,
using an awk script to extract the loader program and map.

> diff --git a/tools/testing/selftests/bpf/prog_tests/loader_load_fd.c b/tools/testing/selftests/bpf/prog_tests/loader_load_fd.c
> new file mode 100644
> index 0000000000000..ab971662dd047
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/loader_load_fd.c
[ ... ]
> +	ehdr->e_ident[EI_VERSION] = EV_CURRENT;
> +	ehdr->e_machine = EM_BPF;
> +	ehdr->e_type = ET_REL;
> +	ehdr->e_version = EV_CURRENT;
> +
> +	shstr_scn = elf_newscn(elf);
> +	shstr_shdr = elf64_getshdr(shstr_scn);
> +	shstr_shdr->sh_name = shstr_off;
> +	shstr_shdr->sh_type = SHT_STRTAB;
> +	shstr_shdr->sh_flags = 0;
> +
> +	shstr_data = elf_newdata(shstr_scn);
> +	shstr_data->d_buf = shstrtab;

[Severity: Medium]
Could this crash the test runner if libelf fails to allocate memory?

Earlier in create_loader_elf(), ASSERT_OK_PTR is used to check the return
values of elf_begin() and elf64_newehdr(). However, the pointers returned
by elf_newscn(), elf64_getshdr(), and elf_newdata() are dereferenced here
without prior validation.

If these functions return NULL, the test will abort with a segmentation
fault, preventing subsequent tests from running. This pattern also appears
to be repeated for the .prog, .map, and license sections below.

Would it be better to add ASSERT_OK_PTR checks for these allocations?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260813002618.3755631-1-tweek@google.com?part=5

  reply	other threads:[~2026-08-13  0:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13  0:26 [PATCH bpf-next 0/5] bpf: Introduce LOADER_LOAD_FD Thiébaud Weksteen
2026-08-13  0:26 ` [PATCH bpf-next 1/5] fs/kernel_read_file,selinux: Add BPF_LOADER constant Thiébaud Weksteen
2026-08-13  0:36   ` sashiko-bot
2026-08-13  1:25   ` bot+bpf-ci
2026-08-13  0:26 ` [PATCH bpf-next 2/5] bpf: Introduce BPF_LOADER_LOAD_FD command Thiébaud Weksteen
2026-08-13  0:42   ` sashiko-bot
2026-08-13  1:40   ` bot+bpf-ci
2026-08-13  0:26 ` [PATCH bpf-next 3/5] selinux: use kernel sid in security_bpf_* Thiébaud Weksteen
2026-08-13  0:40   ` sashiko-bot
2026-08-13  1:25   ` bot+bpf-ci
2026-08-13  0:26 ` [PATCH bpf-next 4/5] selinux: Add BPF_LOADER_LOAD_FD syscall permission Thiébaud Weksteen
2026-08-13  0:41   ` sashiko-bot
2026-08-13  0:26 ` [PATCH bpf-next 5/5] selftests/bpf: add loader_load_fd tests Thiébaud Weksteen
2026-08-13  0:36   ` sashiko-bot [this message]
2026-08-13  1:25   ` 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=20260813003638.4E52D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=selinux@vger.kernel.org \
    --cc=tweek@google.com \
    /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