From: Anastasios Papagiannis <tasos.papagiannnis@gmail.com>
To: bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
akpm@linux-foundation.org, david@kernel.org, ast@kernel.org,
daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com,
memxor@gmail.com, kpsingh@kernel.org, matt@bobrowski.net,
song@kernel.org, tasos.papagiannnis@gmail.com
Subject: [PATCH bpf-next 4/5] selftests/bpf: Test trusted-or-null linux_binprm->mm
Date: Tue, 11 Aug 2026 14:21:53 +0300 [thread overview]
Message-ID: <20260811112154.94053-5-tasos.papagiannnis@gmail.com> (raw)
In-Reply-To: <20260811112154.94053-1-tasos.papagiannnis@gmail.com>
Add verifier coverage for the linux_binprm->mm trusted-or-null
annotation. Verify that bpf_copy_from_user_mm() accepts the pointer
after a NULL check and rejects it without one.
Signed-off-by: Anastasios Papagiannis <tasos.papagiannnis@gmail.com>
---
.../selftests/bpf/progs/verifier_lsm.c | 31 +++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_lsm.c b/tools/testing/selftests/bpf/progs/verifier_lsm.c
index c724bf389f5c..4fc835432af0 100644
--- a/tools/testing/selftests/bpf/progs/verifier_lsm.c
+++ b/tools/testing/selftests/bpf/progs/verifier_lsm.c
@@ -5,6 +5,10 @@
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"
+extern int bpf_copy_from_user_mm(void *dst, u32 dst__sz,
+ const void *unsafe_ptr__ign,
+ struct mm_struct *mm, u64 flags) __ksym;
+
SEC("lsm/file_permission")
__description("lsm bpf prog with -4095~0 retval. test 1")
__success
@@ -212,4 +216,31 @@ __naked int retval_load_resets_bounds(void *ctx)
::: __clobber_all);
}
+SEC("lsm.s/bprm_check_security")
+__description("null checking trusted-or-null linux_binprm mm")
+__success
+int BPF_PROG(copy_from_user_mm_with_null_check, struct linux_binprm *bprm, int ret)
+{
+ struct mm_struct *mm;
+ char dst[8];
+
+ mm = bprm->mm;
+ if (!mm)
+ return 0;
+
+ bpf_copy_from_user_mm(dst, sizeof(dst), (void *)bprm->p, mm, 0);
+ return 0;
+}
+
+SEC("lsm.s/bprm_check_security")
+__description("not null checking trusted-or-null linux_binprm mm")
+__failure __msg("Possibly NULL pointer passed to trusted R4")
+int BPF_PROG(copy_from_user_mm_without_null_check, struct linux_binprm *bprm, int ret)
+{
+ char dst[8];
+
+ bpf_copy_from_user_mm(dst, sizeof(dst), (void *)bprm->p, bprm->mm, 0);
+ return 0;
+}
+
char _license[] SEC("license") = "GPL";
--
2.55.0
next prev parent reply other threads:[~2026-08-11 11:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 11:21 [PATCH bpf-next 0/5] bpf: Add user memory access kfuncs for mm_struct Anastasios Papagiannis
2026-08-11 11:21 ` [PATCH bpf-next 1/5] mm: Add copy_remote_mm_str() Anastasios Papagiannis
2026-08-11 12:40 ` bot+bpf-ci
2026-08-11 11:21 ` [PATCH bpf-next 2/5] bpf: Add user memory access kfuncs for mm_struct Anastasios Papagiannis
2026-08-11 12:40 ` bot+bpf-ci
2026-08-11 11:21 ` [PATCH bpf-next 3/5] bpf: Mark linux_binprm->mm as trusted-or-null Anastasios Papagiannis
2026-08-11 12:40 ` bot+bpf-ci
2026-08-11 11:21 ` Anastasios Papagiannis [this message]
2026-08-11 11:21 ` [PATCH bpf-next 5/5] selftests/bpf: Test mm_struct user memory kfuncs with linux_binprm Anastasios Papagiannis
2026-08-11 13:28 ` [PATCH bpf-next 0/5] bpf: Add user memory access kfuncs for mm_struct Anastasios Papagiannis
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=20260811112154.94053-5-tasos.papagiannnis@gmail.com \
--to=tasos.papagiannnis@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=david@kernel.org \
--cc=eddyz87@gmail.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=matt@bobrowski.net \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
/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
all inboxes | Powered by JetHome®