From: Petr Vaganov <petrvaganoff@gmail.com>
To: Paul Moore <paul@paul-moore.com>,
Stephen Smalley <stephen.smalley.work@gmail.com>,
selinux@vger.kernel.org
Cc: "Petr Vaganov" <petrvaganoff@gmail.com>,
"Ondrej Mosnáček" <omosnacek@gmail.com>,
"James Morris" <jmorris@namei.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH v2] selinux: fix uninit-value in selinux_socket_connect_helper()
Date: Tue, 1 Dec 2026 00:51:09 +0700 [thread overview]
Message-ID: <20261130175134.88024-1-petrvaganoff@gmail.com> (raw)
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")
Cc: stable@vger.kernel.org
Signed-off-by: Petr Vaganov <petrvaganoff@gmail.com>
---
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@gmail.com/
security/selinux/hooks.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 6c4c64d6e904..9affbbdf557c 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5284,11 +5284,21 @@ static int selinux_socket_connect_helper(struct sock *sk,
if (addrlen < offsetofend(struct sockaddr, sa_family))
return -EINVAL;
- /* connect(AF_UNSPEC) has special handling, as it is a documented
- * way to disconnect the socket
- */
- if (address->sa_family == AF_UNSPEC)
+ switch (address->sa_family) {
+ case AF_UNSPEC:
+ /* connect(AF_UNSPEC) has special handling, as it is a documented
+ * way to disconnect the socket
+ */
return 0;
+ 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
@@ -5311,14 +5321,10 @@ static int selinux_socket_connect_helper(struct sock *sk,
switch (address->sa_family) {
case AF_INET:
addr4 = (struct sockaddr_in *)address;
- if (addrlen < sizeof(struct sockaddr_in))
- return -EINVAL;
snum = ntohs(addr4->sin_port);
break;
case AF_INET6:
addr6 = (struct sockaddr_in6 *)address;
- if (addrlen < SIN6_LEN_RFC2133)
- return -EINVAL;
snum = ntohs(addr6->sin6_port);
break;
default:
--
2.56.1
reply other threads:[~2026-11-30 17:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130175134.88024-1-petrvaganoff@gmail.com \
--to=petrvaganoff@gmail.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
--cc=omosnacek@gmail.com \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=stephen.smalley.work@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®