]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
landlock: Fix TCP Fast Open connection bypass
authorMatthieu Buffet <matthieu@buffet.re>
Wed, 1 Jul 2026 21:46:27 +0000 (23:46 +0200)
committerMickaël Salaün <mic@digikod.net>
Fri, 10 Jul 2026 10:59:07 +0000 (12:59 +0200)
The documentation of the socket_connect() LSM hook states that it
controls connecting a socket to a remote address. It has not been the
case since the addition of TCP Fast Open (RFC 7413) support, which
allows opening a TCP connection (thus, setting a socket's destination
address) via the MSG_FASTOPEN flag passed to
sendto()/sendmsg()/sendmmsg(). The problem then got duplicated into
MPTCP.

Landlock did not take it into account when its TCP support was added,
leaving a bypass of TCP connect policy.

Ideally a call to the LSM hook would be added in the fastopen code path,
in order to fix this generically. But connect() hooks are designed to
run with the socket locked, unlike sendmsg() hooks.

Closes: https://github.com/landlock-lsm/linux/issues/41
Fixes: fff69fb03dde ("landlock: Support network rules with TCP bind and connect")
Signed-off-by: Matthieu Buffet <matthieu@buffet.re>
Link: https://patch.msgid.link/20260701214628.33319-1-matthieu@buffet.re
Cc: stable@vger.kernel.org
[mic: Wrap commit message]
Signed-off-by: Mickaël Salaün <mic@digikod.net>
security/landlock/net.c

index cbff59ec3abaa0ed267fe5ea5560453e7201c3bf..46c17116fcf4287f7c82c9276b392f1f1f3fa109 100644 (file)
@@ -351,6 +351,14 @@ static int hook_socket_sendmsg(struct socket *const sock,
        access_mask_t access_request;
        int ret = 0;
 
+       if ((msg->msg_flags & MSG_FASTOPEN) && address && sk_is_tcp(sock->sk)) {
+               ret = current_check_access_socket(
+                       sock, address, addrlen, LANDLOCK_ACCESS_NET_CONNECT_TCP,
+                       true);
+               if (ret != 0)
+                       return ret;
+       }
+
        if (sk_is_udp(sock->sk))
                access_request = LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP;
        else