* Re: [PATCH] bpf, lsm: Mark IPC control hook perm parameters nullable
2026-11-25 17:59 [PATCH] bpf, lsm: Mark IPC control hook perm parameters nullable Quan Sun
@ 2026-11-25 18:10 ` sashiko-bot
2026-11-25 18:25 ` bot+bpf-ci
2026-11-30 5:29 ` Alexei Starovoitov
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-25 18:10 UTC (permalink / raw)
To: Quan Sun, bpf
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] bpf, lsm: missing __nullable annotation on kacl in
bpf_lsm_inode_set_acl() [1]
--
commit 77496f1a0298baa887511d2928e2317763dbc7b6
Author: Quan Sun <m202672221@hust.edu.cn>
bpf, lsm: Mark IPC control hook perm parameters nullable
This commit adds strong overrides in kernel/bpf/bpf_lsm_proto.c for
bpf_lsm_shm_shmctl(), bpf_lsm_sem_semctl(), and
bpf_lsm_msg_queue_msgctl() to annotate their perm parameters with
__nullable.
> diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
> index b81179ae2e086..7c48af32c2d40 100644
> --- a/kernel/bpf/bpf_lsm_proto.c
> +++ b/kernel/bpf/bpf_lsm_proto.c
> @@ -5,6 +5,7 @@
>
> #include <linux/fs.h>
> #include <linux/xattr.h>
> +#include <linux/ipc.h>
> #include <linux/bpf_lsm.h>
>
> /*
> @@ -32,3 +33,31 @@ noinline int bpf_lsm_inode_init_security(struct inode *inode, struct inode *dir,
> {
> return -EOPNOTSUPP;
> }
> +
> +/*
> + * Strong definitions of the IPC control BPF LSM hooks. The informational
> + * commands have no object to authorize, so they pass a NULL struct
> + * kern_ipc_perm: shmctl_ipc_info() and shmctl_shm_info() call
> + * security_shm_shmctl(NULL, IPC_INFO | SHM_INFO), semctl_info() calls
> + * security_sem_semctl(NULL, cmd) and msgctl_info() calls
> + * security_msg_queue_msgctl(NULL, cmd). The __nullable suffix marks perm as
> + * PTR_MAYBE_NULL so that BPF LSM programs have to check it before
> + * dereferencing it. Without these overrides the hooks fall back to the
> + * __weak prototypes generated from lsm_hook_defs.h in bpf_lsm.c, which carry
> + * no annotation and let the verifier type perm as non-nullable.
> + */
> +noinline int bpf_lsm_shm_shmctl(struct kern_ipc_perm *perm__nullable, int cmd)
> +{
> + return 0;
> +}
[Severity: High]
This problem wasn't introduced by this patch, but should
bpf_lsm_inode_set_acl() also have a strong definition [1] marking
its kacl parameter with __nullable?
When setxattr() is called on a POSIX ACL attribute with size == 0,
do_set_acl() passes a NULL acl through vfs_set_acl() and
security_inode_set_acl() to bpf_lsm_inode_set_acl(). Without the
__nullable annotation, the verifier treats kacl as a trusted non-null
pointer and neither requires a NULL check nor rewrites loads to use
BPF_PROBE_MEM, allowing a BPF LSM program attached to inode_set_acl to
trigger a NULL pointer dereference.
[1] https://sashiko.dev/#/bug/linux-bc5e250e-6772-4ebe-b887-e6439d751142
--
Sashiko AI review · https://sashiko.dev/#/patchset/51ae120f0b3cd8c20dbaaf02c9c384dc2afab6bc.1795627805.git.m202672221@hust.edu.cn?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] bpf, lsm: Mark IPC control hook perm parameters nullable
2026-11-25 17:59 [PATCH] bpf, lsm: Mark IPC control hook perm parameters nullable Quan Sun
2026-11-25 18:10 ` sashiko-bot
@ 2026-11-25 18:25 ` bot+bpf-ci
2026-11-30 5:29 ` Alexei Starovoitov
2 siblings, 0 replies; 4+ messages in thread
From: bot+bpf-ci @ 2026-11-25 18:25 UTC (permalink / raw)
To: m202672221, bpf, kpsingh
Cc: matt, paul, ast, daniel, andrii, emil, m202672221, ast, andrii,
daniel, martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 3487 bytes --]
> bpf, lsm: Mark IPC control hook perm parameters nullable
TL;DR:
- Commit message may misdescribe the problem: LSM perm args are trusted, so an
unchecked NULL deref may oops, possibly a regression since c6b0337f0120
- Minor nits: EPERM vs EACCES, misleading IPC_INFO | SHM_INFO comment
> Those carry no __nullable suffix, so
> btf_ctx_access() types perm as a plain PTR_TO_BTF_ID and the verifier
> accepts a program that dereferences it unconditionally:
> [ ... ]
> This is not a regression: the parameters were never annotated, and the
> NULL argument is part of the hook contract
Is this description accurate? For an LSM program, btf_ctx_access() ORs in
PTR_TRUSTED when prog_args_trusted() is true, and prog_args_trusted()
returns bpf_lsm_is_trusted(prog) for BPF_PROG_TYPE_LSM. None of the IPC
hooks is in untrusted_lsm_hooks, so perm is PTR_TO_BTF_ID | PTR_TRUSTED.
The verifier log quoted in the commit message shows this too:
trusted_ptr_or_null_kern_ipc_perm.
The difference matters for the oops. A plain PTR_TO_BTF_ID load would not
crash:
static inline bool bpf_may_fault_on_deref(enum bpf_reg_type type)
{
return type == PTR_TO_BTF_ID || (type_flag(type) & PTR_UNTRUSTED);
}
bpf_convert_ctx_accesses() rewrites a load from a flagless PTR_TO_BTF_ID
into BPF_PROBE_MEM, which goes through the exception table and reads 0 for
a NULL+0x60 address. Only the trusted load is emitted as a direct BPF_MEM
load that faults.
LSM arguments became trusted, and trusted loads stopped being
probe-converted, in c6b0337f0120 ("bpf: Don't mark arguments to fentry/fexit
programs as trusted."). That commit replaced prog_type_args_trusted()
(TRACING || STRUCT_OPS only) with prog_args_trusted(), which has
"case BPF_PROG_TYPE_LSM: return true", and removed the PROBE_MEM conversion
for trusted loads. Before it, the same program read perm->seq through
BPF_PROBE_MEM and got 0.
So does "This is not a regression" hold for the crash itself? That seems
relevant for stable backporting, since the trigger needs no privilege.
There is also a smaller point:
> and BPF_PROG_LOAD fails with EPERM.
The path that prints "R6 invalid mem access 'trusted_ptr_or_null_'" is the
final else of check_mem_access(), which returns -EACCES, not -EPERM.
> diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
> --- a/kernel/bpf/bpf_lsm_proto.c
> +++ b/kernel/bpf/bpf_lsm_proto.c
[ ... ]
> +/*
> + * Strong definitions of the IPC control BPF LSM hooks. The informational
> + * commands have no object to authorize, so they pass a NULL struct
> + * kern_ipc_perm: shmctl_ipc_info() and shmctl_shm_info() call
> + * security_shm_shmctl(NULL, IPC_INFO | SHM_INFO), semctl_info() calls
This isn't a bug, but the comment reads as a single call with the bitwise
OR of the two commands, and no such call exists. shmctl_ipc_info() calls
security_shm_shmctl(NULL, IPC_INFO) and shmctl_shm_info() calls
security_shm_shmctl(NULL, SHM_INFO).
IPC_INFO (3) | SHM_INFO (14) is 15, which is SHM_STAT_ANY, and that command
goes through shmctl_stat() and passes a real &shp->shm_perm, not NULL.
Could the comment say "call security_shm_shmctl(NULL, IPC_INFO) and
security_shm_shmctl(NULL, SHM_INFO) respectively" instead?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45672586202
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] bpf, lsm: Mark IPC control hook perm parameters nullable
2026-11-25 17:59 [PATCH] bpf, lsm: Mark IPC control hook perm parameters nullable Quan Sun
2026-11-25 18:10 ` sashiko-bot
2026-11-25 18:25 ` bot+bpf-ci
@ 2026-11-30 5:29 ` Alexei Starovoitov
2 siblings, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2026-11-30 5:29 UTC (permalink / raw)
To: Quan Sun, bpf, kpsingh; +Cc: matt, paul, daniel, andrii, emil
On Wed, Nov 25, 2026 at 09:59 AM Quan Sun <m202672221@hust.edu.cn> wrote:
> socket_getpeersec_dgram() passes a NULL struct sock on one path too,
> but its reachability from a BPF LSM program has not been confirmed, so
> it is left out here and can be handled separately.
Pls fix them all in one patch.
diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
index 7c48af3..03a8730 100644
--- a/kernel/bpf/bpf_lsm_proto.c
+++ b/kernel/bpf/bpf_lsm_proto.c
@@ -34,18 +34,7 @@ noinline int bpf_lsm_inode_init_security(struct inode *inode, struct inode *dir,
return -EOPNOTSUPP;
}
-/*
- * Strong definitions of the IPC control BPF LSM hooks. The informational
- * commands have no object to authorize, so they pass a NULL struct
- * kern_ipc_perm: shmctl_ipc_info() and shmctl_shm_info() call
- * security_shm_shmctl(NULL, IPC_INFO | SHM_INFO), semctl_info() calls
- * security_sem_semctl(NULL, cmd) and msgctl_info() calls
- * security_msg_queue_msgctl(NULL, cmd). The __nullable suffix marks perm as
- * PTR_MAYBE_NULL so that BPF LSM programs have to check it before
- * dereferencing it. Without these overrides the hooks fall back to the
- * __weak prototypes generated from lsm_hook_defs.h in bpf_lsm.c, which carry
- * no annotation and let the verifier type perm as non-nullable.
- */
+/* perm is NULL for IPC_INFO, SHM_INFO, SEM_INFO and MSG_INFO */
noinline int bpf_lsm_shm_shmctl(struct kern_ipc_perm *perm__nullable, int cmd)
{
return 0;
@@ -61,3 +50,97 @@ noinline int bpf_lsm_msg_queue_msgctl(struct kern_ipc_perm *perm__nullable,
{
return 0;
}
+
+noinline int bpf_lsm_task_kill(struct task_struct *p,
+ struct kernel_siginfo *info__nullable, int sig,
+ const struct cred *cred__nullable)
+{
+ return 0;
+}
+
+noinline int bpf_lsm_quotactl(int cmds, int type, int id,
+ const struct super_block *sb__nullable)
+{
+ return 0;
+}
+
+noinline int bpf_lsm_settime(const struct timespec64 *ts__nullable,
+ const struct timezone *tz__nullable)
+{
+ return 0;
+}
+
+noinline int bpf_lsm_inode_init_security_anon(struct inode *inode,
+ const struct qstr *name,
+ const struct inode *context_inode__nullable)
+{
+ return 0;
+}
+
+noinline int bpf_lsm_inode_set_acl(const struct mnt_idmap *idmap,
+ struct dentry *dentry, const char *acl_name,
+ struct posix_acl *kacl__nullable)
+{
+ return 0;
+}
+
+noinline void bpf_lsm_inode_post_set_acl(struct dentry *dentry, const char *acl_name,
+ struct posix_acl *kacl__nullable)
+{
+}
+
+noinline int bpf_lsm_secid_to_secctx(u32 secid, struct lsm_context *cp__nullable)
+{
+ return -EOPNOTSUPP;
+}
+
+noinline int bpf_lsm_bpf_map_create(struct bpf_map *map, union bpf_attr *attr,
+ struct bpf_token *token__nullable, bool kernel)
+{
+ return 0;
+}
+
+noinline int bpf_lsm_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,
+ struct bpf_token *token__nullable, bool kernel)
+{
+ return 0;
+}
+
+#ifdef CONFIG_SECURITY_NETWORK
+noinline int bpf_lsm_socket_getpeersec_dgram(struct socket *sock__nullable,
+ struct sk_buff *skb__nullable,
+ u32 *secid)
+{
+ return -ENOPROTOOPT;
+}
+#endif
+
+#ifdef CONFIG_SECURITY_NETWORK_XFRM
+noinline int bpf_lsm_xfrm_policy_clone_security(struct xfrm_sec_ctx *old_ctx__nullable,
+ struct xfrm_sec_ctx **new_ctx)
+{
+ return 0;
+}
+
+noinline void bpf_lsm_xfrm_policy_free_security(struct xfrm_sec_ctx *ctx__nullable)
+{
+}
+
+noinline int bpf_lsm_xfrm_policy_delete_security(struct xfrm_sec_ctx *ctx__nullable)
+{
+ return 0;
+}
+
+noinline int bpf_lsm_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx__nullable,
+ u32 fl_secid)
+{
+ return 0;
+}
+
+noinline int bpf_lsm_xfrm_state_alloc_acquire(struct xfrm_state *x,
+ struct xfrm_sec_ctx *polsec__nullable,
+ u32 secid)
+{
+ return 0;
+}
+#endif
diff --git a/tools/testing/selftests/bpf/progs/verifier_lsm.c b/tools/testing/selftests/bpf/progs/verifier_lsm.c
index 8fbf786..7f925fb 100644
--- a/tools/testing/selftests/bpf/progs/verifier_lsm.c
+++ b/tools/testing/selftests/bpf/progs/verifier_lsm.c
@@ -188,6 +188,29 @@ int BPF_PROG(null_check, struct file *file)
return 0;
}
+SEC("lsm/shm_shmctl")
+__description("not null checking perm in bpf_lsm_shm_shmctl")
+__failure __msg("invalid mem access 'trusted_ptr_or_null_'")
+int BPF_PROG(shm_shmctl_perm, struct kern_ipc_perm *perm)
+{
+ int id = perm->id;
+
+ __sink(id);
+ return 0;
+}
+
+SEC("lsm/task_kill")
+__description("not null checking cred in bpf_lsm_task_kill")
+__failure __msg("invalid mem access 'trusted_ptr_or_null_'")
+int BPF_PROG(task_kill_cred, struct task_struct *p, struct kernel_siginfo *info,
+ int sig, const struct cred *cred)
+{
+ __u32 uid = cred->uid.val;
+
+ __sink(uid);
+ return 0;
+}
+
SEC("lsm_cgroup/file_open")
__description("sleepable lsm_cgroup program is rejected")
__failure __msg("Program of this type cannot be sleepable")
pw-bot: cr
^ permalink raw reply related [flat|nested] 4+ messages in thread