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 B728A349CDB; Thu, 2 Jul 2026 16:41:59 +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=1783010520; cv=none; b=W6VMJDocoZi1NLfCdOOxKWk6ri/EJIE6Sncra0QIMaZshQMCfCaRhP/dC2vxk07Mwli9O9PPxmkWgjaEbtuMe/4TCOtNOQyT1qd1ke1MsfeCQtPY6KcquzRECGRcaDKqVdurzRNeGuiIMBlNbYnQsldyFYXG/+dBtdlTf8Ncwz8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783010520; c=relaxed/simple; bh=Ewvg/wgytIq0GG9hScf8OHQAKnOz1BseE1ZVFGdfS0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mvdcPNOqk7jDlSWounRHAW9jdfJJZTLoQvUH6OFpKSnc3TdvQrq0pasRkVXlp3pZzGvpVBGyrxh7scdSYuLKpap1Yugm6khGCCN7Xzs+Gf/RVH3HGMcLYyc4Y/LhDPgWuT5iPU+d5YE135e3PsIeUVpLlW/UEYpdKvPpSEmAJYs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ag2ixOP+; 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="ag2ixOP+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0D131F000E9; Thu, 2 Jul 2026 16:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1783010519; bh=LXMahY4VQjQwf95UkH/Us6R5PrGWFC3GHnXJ+o7Obiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ag2ixOP+PFRKnclzKOe7nE/56bKqu9MpljusHPuJycOZGmOvcX9rUgazLKVRsD5xX lf5tBcllz0vjQZzV+LCwvSE38xBNJOEarIj5nxydUJF2SpqfvSwLNVsE8gnnC12Y+z XKL/Vk6N0SJfoBaxB9OL+CJQFjq1hWO9Ts1VrkIU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bryam Vargas , John Johansen Subject: [PATCH 6.12 139/204] apparmor: mediate the implicit connect of TCP fast open sendmsg Date: Thu, 2 Jul 2026 18:19:56 +0200 Message-ID: <20260702155121.570672519@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260702155118.667618796@linuxfoundation.org> References: <20260702155118.667618796@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.12-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 @@ -1207,7 +1207,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; } static int apparmor_socket_recvmsg(struct socket *sock,