[PATCH] selinux: initialize sport/dport in __ad_net_init()

From: Eduard Orehov

Date: Mon Nov 23 2026 - 06:38:25 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Eduard Orehov <e.orehov@xxxxxxxx>
---
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