Re: [PATCH v2] selinux: fix uninit-value in selinux_socket_connect_helper()
From: Paul Moore
Date: Tue Dec 01 2026 - 22:39:22 EST
On Nov 30, 2026 sashiko-bot@xxxxxxxxxx wrote:
>
> 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 addrlen validation for AF_INET and AF_INET6 before the TCP/SCTP
> block, folding in the existing AF_UNSPEC early return. Drop the
> now-redundant checks from inside the TCP/SCTP block.
>
> Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
>
> Fixes: 014ab19a69c3 ("selinux: Set socket NetLabel based on connection endpoint")
This doesn't look correct, I'm going to drop this "Fixes:" marking from
the patch when merging, but otherwise this looks good.
Merged into selinux/stable-7.4, thanks!
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Petr Vaganov <petrvaganoff@xxxxxxxxx>
> ---
> v2: remove redundant addrlen checks from the TCP/SCTP block (now dead
> code after the unconditional check above); consolidate AF_UNSPEC
> early return into the new switch. Suggested by Sashiko AI review.
>
> Link to v1: https://lore.kernel.org/all/20261130165425.79011-1-petrvaganoff@xxxxxxxxx/
>
> security/selinux/hooks.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
--
paul-moore.com