From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Quan Sun" <m202672221@hust.edu.cn>, <bpf@vger.kernel.org>,
<kpsingh@kernel.org>
Cc: <matt@bobrowski.net>, <paul@paul-moore.com>,
<daniel@iogearbox.net>, <andrii@kernel.org>,
<emil@etsalapatis.com>
Subject: Re: [PATCH] bpf, lsm: Mark IPC control hook perm parameters nullable
Date: Mon, 30 Nov 2026 05:29:55 +0000 [thread overview]
Message-ID: <DN8AQXU03UWP.2IW43LCQS3EMQ@gmail.com> (raw)
In-Reply-To: <51ae120f0b3cd8c20dbaaf02c9c384dc2afab6bc.1795627805.git.m202672221@hust.edu.cn>
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
prev parent reply other threads:[~2026-11-30 5:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=DN8AQXU03UWP.2IW43LCQS3EMQ@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=emil@etsalapatis.com \
--cc=kpsingh@kernel.org \
--cc=m202672221@hust.edu.cn \
--cc=matt@bobrowski.net \
--cc=paul@paul-moore.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