selinux: check connect-related permissions on TCP Fast Open
Subsystems (2)
Stephen Smalley
maintainerPATCH 1/1 selinux: check connect-related permissions on TCP Fast Open
Similar to Landlock, SELinux was not updated when TCP Fast Open support was introduced to ensure connect-related permissions are checked when using TCP Fast Open. Update its socket_sendmsg() hook to call selinux_socket_connect() when MSG_FASTOPEN is passed.
---
NB Build-tested only so far.
security/selinux/hooks.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
security/selinux/hooks.c +17 -1
@@ -5270,7 +5270,23 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock)static int selinux_socket_sendmsg (struct socket *sock,struct msghdr *msg,int size) { -return sock_has_perm (sock->sk,SOCKET__WRITE ); +int rc; +struct sockaddr *const addr = msg->msg_name; +const int addrlen = msg->msg_namelen; + + rc =sock_has_perm (sock->sk,SOCKET__WRITE ); +if (rc) +return rc; + +if (addr && (msg->msg_flags &MSG_FASTOPEN ) && (sk_is_tcp (sock->sk) || + (sk_is_inet (sock->sk) && sock->sk->sk_type ==SOCK_STREAM && + sock->sk->sk_protocol ==IPPROTO_MPTCP ))) { + rc =selinux_socket_connect (sock, addr, addrlen); +if (rc) +return rc; + } + +return 0 ; } static int selinux_socket_recvmsg(struct socket *sock, struct msghdr *msg,
Signature · 1 line
2.54.0
Stephen Smalley
maintainerQuoted 6 lines · Stephen Smalley
Similar to Landlock, SELinux was not updated when TCP Fast Open support was introduced to ensure connect-related permissions are checked when using TCP Fast Open. Update its
socket_sendmsg()hook to callselinux_socket_connect()whenMSG_FASTOPENis passed.
Quoted 8 lines
Reported-by Bryam Vargas <[email protected]>Reported-by Matthieu Buffet <[email protected]>Reported-by Mikhail Ivanov <[email protected]>Signed-off-by Stephen Smalley <[email protected]>---
NB Build-tested only so far.
Note that I have subsequently tested the selinux-testsuite with this applied, both with and without the new tests in:
https://lore.kernel.org/selinux/[email protected]/T/#u
Quoted 36 lines
security/selinux/hooks.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)security/selinux/hooks.c +17
-2@@ -5270,7 +5270,23 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock)static int selinux_socket_sendmsg (struct socket *sock,struct msghdr *msg,int size) { -return sock_has_perm (sock->sk,SOCKET__WRITE ); +int rc; +struct sockaddr *const addr = msg->msg_name; +const int addrlen = msg->msg_namelen; + + rc =sock_has_perm (sock->sk,SOCKET__WRITE ); +if (rc) +return rc; + +if (addr && (msg->msg_flags &MSG_FASTOPEN ) && (sk_is_tcp (sock->sk) || + (sk_is_inet (sock->sk) && sock->sk->sk_type ==SOCK_STREAM && + sock->sk->sk_protocol ==IPPROTO_MPTCP ))) { + rc =selinux_socket_connect (sock, addr, addrlen); +if (rc) +return rc; + } + +return 0 ; } static int selinux_socket_recvmsg(struct socket *sock, struct msghdr *msg, --2.54.0
Tested this on x86-64. I built mainline with and without the patch and ran it under a SELinux domain (enforcing) that lacks the tcp_socket connect permission.
Unpatched, connect(2) is denied but sendto(MSG_FASTOPEN) still reaches the listener. With the patch the fastopen send is denied too, and the AVC shows the connect check firing on the sendmsg path. Same for TCP, TCP6 and MPTCP. The TCP_FASTOPEN_CONNECT path was already mediated at connect(2), and a domain that allows connect is unaffected.
A/B logs on request.
Paul Moore
maintainerQuoted 13 lines · On Jun 18, 2026 Stephen Smalley <[email protected]> wrote:
Similar to Landlock, SELinux was not updated when TCP Fast Open support was introduced to ensure connect-related permissions are checked when using TCP Fast Open. Update its
socket_sendmsg()hook to callselinux_socket_connect()whenMSG_FASTOPENis passed.Reported-by Bryam Vargas <[email protected]>Reported-by Matthieu Buffet <[email protected]>Reported-by Mikhail Ivanov <[email protected]>Signed-off-by Stephen Smalley <[email protected]>Tested-by Bryam Vargas <[email protected]>
Quoted 5 lines
---
NB Build-tested only so far.security/selinux/hooks.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
I tweaked the alignment of the if-conditional to better follow the scope/parens, but otherwise this looks good to me. Thanks everyone for the report, the fix, and the testing!
I've tagged this for stable and I'm merging it into the selinux/stable-7.2 branch to send up to Linus after some soak time in linux-next.
Quoted 31 lines
security/selinux/hooks.c +17
-1@@ -5270,7 +5270,23 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock)static int selinux_socket_sendmsg (struct socket *sock,struct msghdr *msg,int size) { -return sock_has_perm (sock->sk,SOCKET__WRITE ); +int rc; +struct sockaddr *const addr = msg->msg_name; +const int addrlen = msg->msg_namelen; + + rc =sock_has_perm (sock->sk,SOCKET__WRITE ); +if (rc) +return rc; + +if (addr && (msg->msg_flags &MSG_FASTOPEN ) && (sk_is_tcp (sock->sk) || + (sk_is_inet (sock->sk) && sock->sk->sk_type ==SOCK_STREAM && + sock->sk->sk_protocol ==IPPROTO_MPTCP ))) { + rc =selinux_socket_connect (sock, addr, addrlen); +if (rc) +return rc; + } + +return 0 ; } static int selinux_socket_recvmsg(struct socket *sock, struct msghdr *msg,Signature · 1 line
2.54.0
--
paul-moore.com