From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796016597; b=vWUZizOkLDeMmsJ9nuSJAubkUQS0D95O6FOau4OmuxDrY2gGVYEkHxym1uY9FgWX+i6l ZuesuZ7CUwHATRg63Dbug1c67hOWm5qMghYlNFM3sOO0Tzf1jCBc8eSay92VqOgFP11J+ VgW1LoGL1/kACva3i2LwiUg7kBFxJi1Vw3Li82xf2SWpGFDlGTs4JyZQGIXLkMbgcsvo8 OMZX/J0iIWWmvP5gYgfFbGhW58UQBQjQK/3G+mLsZLo1FfrvdGm1cxVF6C4Z+SOKNuA6t o10cZen5aSCm0y9xU52RBmxm/PINf32lMyWdd6+//tEhCeRslpGiK66cT9x7361UpwA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796016597; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Content-Type:Date:Message-Id:Cc:Subject:From:To:In-Reply-To: References:Content-Transfer-Encoding:MIME-Version; bh=CVhVTJ75XVw61Abe61/9ZO0SWhWoI01qZo0Qks+uP84=; b=yugfU1Ump1qlW4Qaf79KuCSoCdivnIOgwZeMc9Ux5T4Y8vBjKpLZPmpnJjAkNUpQ8CSz zTIiKdS2v4klM65fsIlzCznbsInKr/g/mHZf5lJJxBrZf0+z3ZqUCuF6lH75nZUIfFFTI 8rRbyOQXHlqhq1mzvrTbw75+HbhOsHIhDlq48cDB9tx0ZZGxH8fj5dicgaY0yX6hCpyzZ uyQgDmP70x9G6SqWwK+cNr+9y8DzxR+Q1uX5n6IwlPRpKVgVhMaXaxAqfXpekS0rbbLOW iw886/O8yKoaIgynnmb4VPHTqo+rxUiiXccVU5EUUHYNh/tG1DysXdggcePoaS0wrUA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AhnhJ1oz; arc=none smtp.remote-ip=209.85.216.51 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 794B0606A31C for ; Mon, 30 Nov 2026 05:29:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 794B0606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AhnhJ1oz Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-3b413997581so6974420a91.2 for ; Sun, 29 Nov 2026 21:29:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796016597; x=1796621397; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:from:to:cc:subject :date:message-id:reply-to:content-type; bh=CVhVTJ75XVw61Abe61/9ZO0SWhWoI01qZo0Qks+uP84=; b=AhnhJ1oz344oSTxB4+fAq/RjH+Sz1Ffdc3Eq2RwYelm5pgm6tEKS0EIsn5B4EbbNnk aneTYoXQoYZzeBNi/p48hfRJjNSmO9NZn1tlThuFMcPD28fgpivup50oDWSTy6NL0MXt zBw7iWttH5HgbDvdVFEcDeGvKA9diqdF9iztjRuG+FrcHmJ5rfIt1sJSdu6GaoQ1wQeu QCuXUF9hU3vJNaomz4l3p4SoAtqp702VAFBZkIMKmIwY2aaxcArMff3Eoi25Fbtnu1Hm Pi9nRPrU3xLJtymIjFLD2O9ZYofvhjwS1ShLaG9kOA/XrQxwPaKfTFncR2/SOrNHmWvF MS0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796016597; x=1796621397; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CVhVTJ75XVw61Abe61/9ZO0SWhWoI01qZo0Qks+uP84=; b=ZmSQi58tbsxVcoVaihIv/N+941BYGVvq16fpEngsP8nhoiW3qVi19KEsOpLQRnZnBO Gfz2/L/UWMwBvZM54LV+j/oYS4jxh+IwAAfbqP6+yM3M8VDkWqWH/5REMuWY0gQ/AIMI kABShmh6l0bf04ck9o9359xgin+RM6a465DEOqd+ySNL1PerU6KujfgMJ/8GO4ZPSm9Y qeVHZquLhYX85ePqPqIMHK9YM39ZuzxVP43TTXS7hRAHJL54ZXN032XckZMvaTqDGD3d ufvNDYCsJdx/RcFUrkA3AYXbOjh+XmYd5t+LcpR55K9TVbQU0BE2GYEZMXQMEkqkWl+P 5dIQ== X-Forwarded-Encrypted: i=1; AL+hErEAQ+0BrEIoPKXKjk3xPJWBbVTxn9KWD7D+M33AslB8azD1Va/lKH1MdjgAChbhCaSJhG4=@vger.kernel.org X-Gm-Message-State: APuU4Z8FPizpKI/gnbwLUq2LyKeITA+qKcQNG+l+n2EclCXgVsSRJgSa PDmoFtjPR4Cr19wuKpMahGfoEcfpay3jMS9PTg+NV1ajtsnn4DXaODHM X-Gm-Gg: AZFdTZcG2qVAq9lkNJCj1Ihf3C24AvHcF535FDcIY4dElwDNOzVIzK66mX8DiiN60q2 mTXstS43UONMpa9H29PUorTIp1Ft2VfJGqvzeXQf0z8DYttR2U/iEpyY5vWzymwY1eQARIsNyjR blP4UA+XkUaMR/a28E6yf+RIblqU6TKMf5q4HAfWmLSaLGNKvvNpagBNFv57+f/j7oYLVOaxSDy G4xOm7Q9MVr9bEks6u1SBr6LaIj9dm+q6pdNWN0WCBLLtueJumvNyKMY24z5LCieVSA4pVa1DEX 5+iIxSB1czJ2+K1awbJYOpHYrHnVE7MzJcfTffcL/wo9fm0w8qq2hAgOvFV7fTQH9FBjVkI4AeV YJ9nMjpoaO1cO0zghFIutnaFA45OXB4V0QEEr2eBkQ7w588l8i6Jr6GDJ0hDoTKp+8fRYwbLjSq HNnE53iVaTKHlu6vMIyYKNq7WoVQpso8ju9UBd9LjZhvVw8lo5gQ8XOLdrKl4a41N8jrAWlYJ57 SV+H1Y6/+S+B3w0tbQfUiIdL7kKj2kkk4VVbdE+dDCDH7SKoAK8XCF62kZcC2/vpK2HpWlwJPTN LQCD9Rr3Zf/AUFiKWXUq3AIo8ahiQby84Ni/rBMDg59J+TnOM8sXmWr1vZIGebqlBKsb1rtwc/A uJGX1qJWiMJpD75XAYV09N5vfHmIJeOprkw== X-Received: by 2002:a17:90b:4d86:b0:3ad:4a8b:c6fd with SMTP id 98e67ed59e1d1-3b41c93b159mr27495538a91.28.1796016596650; Sun, 29 Nov 2026 21:29:56 -0800 (PST) Received: from localhost ([153.61.198.250]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b420e1307csm49915402a91.7.2026.11.29.21.29.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Nov 2026 21:29:56 -0800 (PST) Content-Type: text/plain; charset=UTF-8 Date: Mon, 30 Nov 2026 05:29:55 +0000 Message-Id: Cc: , , , , Subject: Re: [PATCH] bpf, lsm: Mark IPC control hook perm parameters nullable From: "Alexei Starovoitov" To: "Quan Sun" , , In-Reply-To: <51ae120f0b3cd8c20dbaaf02c9c384dc2afab6bc.1795627805.git.m202672221@hust.edu.cn> References: <51ae120f0b3cd8c20dbaaf02c9c384dc2afab6bc.1795627805.git.m202672221@hust.edu.cn> Content-Transfer-Encoding: 8bit X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Wed, Nov 25, 2026 at 09:59 AM Quan Sun 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