Skip to content

Commit 4d587cd

Browse files
bryamzxzjrjohansen
authored andcommitted
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. Fixes: cf60af0 ("net-tcp: Fast Open client - sendmsg(MSG_FASTOPEN)") Cc: stable@vger.kernel.org Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me> Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent 1ed40bd commit 4d587cd

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

security/apparmor/lsm.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,21 @@ static int aa_sock_msg_perm(const char *op, u32 request, struct socket *sock,
14221422
static int apparmor_socket_sendmsg(struct socket *sock,
14231423
struct msghdr *msg, int size)
14241424
{
1425-
return aa_sock_msg_perm(OP_SENDMSG, AA_MAY_SEND, sock, msg, size);
1425+
int error = aa_sock_msg_perm(OP_SENDMSG, AA_MAY_SEND, sock, msg, size);
1426+
1427+
if (error)
1428+
return error;
1429+
1430+
/* TCP fast open carries connect() semantics in sendmsg(); mediate
1431+
* the implicit connect so it cannot bypass the connect permission.
1432+
*/
1433+
if ((msg->msg_flags & MSG_FASTOPEN) && msg->msg_name &&
1434+
(sk_is_tcp(sock->sk) ||
1435+
(sk_is_inet(sock->sk) && sock->sk->sk_type == SOCK_STREAM &&
1436+
sock->sk->sk_protocol == IPPROTO_MPTCP)))
1437+
error = aa_sk_perm(OP_CONNECT, AA_MAY_CONNECT, sock->sk);
1438+
1439+
return error;
14261440
}
14271441

14281442
static int apparmor_socket_recvmsg(struct socket *sock,

0 commit comments

Comments
 (0)