FAILED: patch "[PATCH] apparmor: mediate the implicit connect of TCP fast open" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 4d587cd8a72155089a627130bbd4716ec0856e21
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026070241-upper-credible-fb47@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 4d587cd8a72155089a627130bbd4716ec0856e21 Mon Sep 17 00:00:00 2001
From: Bryam Vargas <[email protected]>
Date: Mon, 22 Jun 2026 15:57:38 -0500
Subject: [PATCH] apparmor: mediate the implicit connect of TCP fast open
sendmsg
sendmsg()/sendto() with MSG_FASTOPEN is a combination of connect(2) and write(2): it opens the connection in the SYN. apparmor_socket_sendmsg() only checks AA_MAY_SEND, so a profile that grants send but denies connect lets a confined task open an outbound TCP/MPTCP connection that connect(2) would have refused, bypassing connect mediation.
Mediate the implicit connect when MSG_FASTOPEN is set and a destination is supplied. Add it to apparmor_socket_sendmsg() (not the shared aa_sock_msg_perm() helper, which recvmsg also uses) and call aa_sk_perm() directly, mirroring the selinux and tomoyo fixes. sk_is_tcp() does not cover MPTCP fast open, so the SOCK_STREAM/IPPROTO_MPTCP arm is explicit.
security/apparmor/lsm.c +15 -1
@@ -1422,7 +1422,21 @@ static int aa_sock_msg_perm(const char *op, u32 request, struct socket *sock,static int apparmor_socket_sendmsg (struct socket *sock,struct msghdr *msg,int size) { -return aa_sock_msg_perm (OP_SENDMSG ,AA_MAY_SEND , sock, msg, size); +int error =aa_sock_msg_perm (OP_SENDMSG ,AA_MAY_SEND , sock, msg, size); + +if (error) +return error; + +/* TCP fast open carries connect() semantics in sendmsg(); mediate +* the implicit connect so it cannot bypass the connect permission. +*/ +if ((msg->msg_flags &MSG_FASTOPEN ) && msg->msg_name && + (sk_is_tcp (sock->sk) || + (sk_is_inet (sock->sk) && sock->sk->sk_type ==SOCK_STREAM && + sock->sk->sk_protocol ==IPPROTO_MPTCP ))) + error =aa_sk_perm (OP_CONNECT ,AA_MAY_CONNECT , sock->sk); + +return error; } static int apparmor_socket_recvmsg(struct socket *sock,
Sasha Levin
maintainerPATCH 1/1 apparmor: mediate the implicit connect of TCP fast open sendmsg
From: Bryam Vargas <[email protected]>
[ Upstream commit 4d587cd8a72155089a627130bbd4716ec0856e21 ]
sendmsg()/sendto() with MSG_FASTOPEN is a combination of connect(2) and write(2): it opens the connection in the SYN. apparmor_socket_sendmsg() only checks AA_MAY_SEND, so a profile that grants send but denies connect lets a confined task open an outbound TCP/MPTCP connection that connect(2) would have refused, bypassing connect mediation.
Mediate the implicit connect when MSG_FASTOPEN is set and a destination is supplied. Add it to apparmor_socket_sendmsg() (not the shared aa_sock_msg_perm() helper, which recvmsg also uses) and call aa_sk_perm() directly, mirroring the selinux and tomoyo fixes. sk_is_tcp() does not cover MPTCP fast open, so the SOCK_STREAM/IPPROTO_MPTCP arm is explicit.
--- security/apparmor/lsm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
security/apparmor/lsm.c +15 -1
@@ -960,7 +960,21 @@ static int aa_sock_msg_perm(const char *op, u32 request, struct socket *sock,static int apparmor_socket_sendmsg (struct socket *sock,struct msghdr *msg,int size) { -return aa_sock_msg_perm (OP_SENDMSG ,AA_MAY_SEND , sock, msg, size); +int error =aa_sock_msg_perm (OP_SENDMSG ,AA_MAY_SEND , sock, msg, size); + +if (error) +return error; + +/* TCP fast open carries connect() semantics in sendmsg(); mediate +* the implicit connect so it cannot bypass the connect permission. +*/ +if ((msg->msg_flags &MSG_FASTOPEN ) && msg->msg_name && + (sk_is_inet (sock->sk) && sock->sk->sk_type ==SOCK_STREAM && + (sock->sk->sk_protocol ==IPPROTO_TCP || + sock->sk->sk_protocol ==IPPROTO_MPTCP ))) + error =aa_sk_perm (OP_CONNECT ,AA_MAY_CONNECT , sock->sk); + +return error; }/**
Signature · 1 line
2.53.0