* [PATCH] selinux: fix uninit-value in selinux_socket_connect_helper()
@ 2026-11-30 16:54 Petr Vaganov
0 siblings, 0 replies; only message in thread
From: Petr Vaganov @ 2026-11-30 16:54 UTC (permalink / raw)
To: Paul Moore, Stephen Smalley, selinux
Cc: Petr Vaganov, Ondrej Mosnáček, James Morris,
linux-kernel, lvc-project, stable
During fuzz testing, the following issue was discovered:
BUG: KMSAN: uninit-value in netlbl_conn_setattr+0x3cc/0x5d0
net/netlabel/netlabel_kapi.c:1144
netlbl_conn_setattr+0x3cc/0x5d0 net/netlabel/netlabel_kapi.c:1144
selinux_netlbl_socket_connect_helper security/selinux/netlabel.c:569 [inline]
selinux_netlbl_socket_connect_locked security/selinux/netlabel.c:597 [inline]
selinux_netlbl_socket_connect+0x23b/0x320 security/selinux/netlabel.c:615
selinux_socket_connect+0xe8/0x140 security/selinux/hooks.c:5052
security_socket_connect+0x83/0x130 security/security.c:4708
__sys_connect_file net/socket.c:2049 [inline]
__sys_connect+0x19f/0x270 net/socket.c:2066
__x64_sys_connect+0x3e/0x50 net/socket.c:2072
Local variable address created at:
__sys_connect+0x94/0x270 net/socket.c:2061
selinux_socket_connect_helper() does not validate addrlen against
sizeof(struct sockaddr_in) for UDP and RAW sockets, unlike TCP/SCTP.
A short connect(2) with addrlen=2 causes netlbl_conn_setattr() to read
uninitialized sin_addr from the kernel stack.
Add an addrlen validation switch before the TCP/SCTP block to ensure
sin_addr and sin6_addr are reachable before netlbl accesses them.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Fixes: 014ab19a69c3 ("selinux: Set socket NetLabel based on connection endpoint")
Cc: stable@vger.kernel.org
Signed-off-by: Petr Vaganov <petrvaganoff@gmail.com>
---
security/selinux/hooks.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 6c4c64d6e904..f8854bfa62ce 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5290,6 +5290,17 @@ static int selinux_socket_connect_helper(struct sock *sk,
if (address->sa_family == AF_UNSPEC)
return 0;
+ switch (address->sa_family) {
+ case AF_INET:
+ if (addrlen < sizeof(struct sockaddr_in))
+ return -EINVAL;
+ break;
+ case AF_INET6:
+ if (addrlen < SIN6_LEN_RFC2133)
+ return -EINVAL;
+ break;
+ }
+
/*
* If a TCP or SCTP socket, check name_connect permission
* for the port.
--
2.56.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-30 16:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 16:54 [PATCH] selinux: fix uninit-value in selinux_socket_connect_helper() Petr Vaganov
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®