From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47AC134107D; Thu, 2 Jul 2026 16:50:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783011019; cv=none; b=GRx8mnRrOxGehBxnLu5nqqHb2Dog5zUmYRM6nDhA/fNcuaEVKo+TVb4RBlfncFoQm9C0Bc7I06c7jH0CTXOiTY/yFYA19FHplwEczX56Cm3rpJExldxi3Jir0h1pyufdsWQFVyiYSiENgXdqDIjeKkLn7cKjSmPrB0PxcPjiOoM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783011019; c=relaxed/simple; bh=u+FVNYxV2gQKiRwfkNiGGXX5St5ekknR3/DjgEDfyek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BgiUEzuAxf9PV+ixKzkGSd+Z7AzCzF6URlAKNbdK9ead9u5Q7jXmFkYZnsk08yHQ16DM1mT4R9+iUPAw3UIVRVcKfWHeyeOofe4E3iB1a1Dsx0rCUfs9lzca/SLRkzscgVhIwcEcju6KWqJFDODDE+8K0Y4X4Td+a2Dm8yXHrws= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cgV9df9E; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cgV9df9E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEC7C1F00A3A; Thu, 2 Jul 2026 16:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1783011018; bh=AcaLntLihHD5xCa9G0UoKYbLRLo3TvAVLYeMwdJDYss=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cgV9df9E5JyWPWrbwi/KFjxNevunmIHORkxUB8of6BWgFgSaZCzwKH/wEiBdeEYE7 mrr35YkqnSB8XO9BPiAkr51d9IfuvUXno5nOKrOfxNHzWlQejF5YEYVLIdBz/Vg8Np 15+85b1tioLgG+c7llMI4fULXyYful0JV7hUWCwU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bryam Vargas , John Johansen Subject: [PATCH 6.6 124/175] apparmor: mediate the implicit connect of TCP fast open sendmsg Date: Thu, 2 Jul 2026 18:20:25 +0200 Message-ID: <20260702155118.364727394@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260702155115.766838875@linuxfoundation.org> References: <20260702155115.766838875@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bryam Vargas commit 4d587cd8a72155089a627130bbd4716ec0856e21 upstream. 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. Fixes: cf60af03ca4e ("net-tcp: Fast Open client - sendmsg(MSG_FASTOPEN)") Cc: stable@vger.kernel.org Signed-off-by: Bryam Vargas Signed-off-by: John Johansen Signed-off-by: Greg Kroah-Hartman --- security/apparmor/lsm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1033,7 +1033,21 @@ static int aa_sock_msg_perm(const char * 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; } /**