* [PATCH] selinux: initialize sport/dport in __ad_net_init()
@ 2026-11-23 11:37 Eduard Orehov
0 siblings, 0 replies; only message in thread
From: Eduard Orehov @ 2026-11-23 11:37 UTC (permalink / raw)
To: Paul Moore, Stephen Smalley
Cc: Ondrej Mosnacek, selinux, linux-kernel, lvc-project, Eduard Orehov
Since commit dd51fcd42fd6 ("selinux: introduce and use lsm_ad_net_init*()
helpers") the struct lsm_network_audit used by the SELinux network hooks
is no longer zeroed; __ad_net_init() sets only netif, sk and family.
The addresses are always filled in by selinux_parse_skb(), but sport
and dport are set by selinux_parse_skb_ipv4()/selinux_parse_skb_ipv6()
only for TCP, UDP and SCTP. For any other protocol (e.g. a raw
socket with IPPROTO_IGMP, UDP-Lite) and for non-first fragments they
are left uninitialized.
When such a packet hits an AVC denial (e.g. with NetLabel or secmark
peer labeling enabled), dump_common_audit_data() passes the garbage
ports to print_ipv4_addr()/print_ipv6_addr(), which leaks up to four
bytes of kernel stack into the audit log as "src=" / "dest=" and is
reported by KMSAN:
BUG: KMSAN: uninit-value in common_lsm_audit+0x2196/0x2ff0
print_ipv6_addr security/lsm_audit.c:178 [inline]
dump_common_audit_data security/lsm_audit.c:373 [inline]
common_lsm_audit+0x2196/0x2ff0 security/lsm_audit.c:458
slow_avc_audit+0x17f/0x1d0 security/selinux/avc.c:773
avc_has_perm+0x2d6/0x360 security/selinux/avc.c:1191
selinux_inet_sys_rcv_skb+0x116/0x280 security/selinux/hooks.c:5326
selinux_socket_sock_rcv_skb+0xaae/0x1270 security/selinux/hooks.c:5408
security_sock_rcv_skb+0x79/0x120 security/security.c:4853
sk_filter_trim_cap+0x18b/0xa60 net/core/filter.c:151
sock_queue_rcv_skb_reason+0x46/0x1a0 net/core/sock.c:522
rawv6_rcv+0x1b17/0x1c20 net/ipv6/raw.c:371
...
Local variable net created at:
selinux_socket_sock_rcv_skb+0x118/0x1270 security/selinux/hooks.c
Initialize sport and dport in __ad_net_init(). Zeroing only these two
fields keeps the cost low, which was the point of dd51fcd42fd6.
Found by Ideco on behalf of Linux Verification Center
(linuxtesting.org) with Syzkaller.
Fixes: dd51fcd42fd6 ("selinux: introduce and use lsm_ad_net_init*() helpers")
Cc: stable@vger.kernel.org
Signed-off-by: Eduard Orehov <e.orehov@ideco.ru>
---
Tested on a 6.12.114-based kernel with KMSAN: the reproducer (NetLabel
static default label + raw IPv4/IPv6 socket with protocol 2, and UDP-Lite
over IPv6) triggers the report on the unpatched kernel and no longer does
with the fix. Mainline was not booted; the affected code there is
identical.
security/selinux/hooks.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 9950f89dfaa2..9029e2ab072a 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -242,6 +242,8 @@ static void __ad_net_init(struct common_audit_data *ad,
net->netif = ifindex;
net->sk = sk;
net->family = family;
+ net->sport = 0;
+ net->dport = 0;
}
static void ad_net_init_from_sk(struct common_audit_data *ad,
--
2.56.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-23 11:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 11:37 [PATCH] selinux: initialize sport/dport in __ad_net_init() Eduard Orehov
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®