Skip to content

Commit 05174c9

Browse files
Paolo Abenipcmoore
authored andcommitted
selinux: do not report error on connect(AF_UNSPEC)
calling connect(AF_UNSPEC) on an already connected TCP socket is an established way to disconnect() such socket. After commit 68741a8 ("selinux: Fix ltp test connect-syscall failure") it no longer works and, in the above scenario connect() fails with EAFNOSUPPORT. Fix the above explicitly early checking for AF_UNSPEC family, and returning success in that case. Reported-by: Tom Deseyn <[email protected]> Cc: [email protected] Fixes: 68741a8 ("selinux: Fix ltp test connect-syscall failure") Suggested-by: Paul Moore <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 35a196b commit 05174c9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

security/selinux/hooks.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4637,6 +4637,14 @@ static int selinux_socket_connect_helper(struct socket *sock,
46374637
err = sock_has_perm(sk, SOCKET__CONNECT);
46384638
if (err)
46394639
return err;
4640+
if (addrlen < offsetofend(struct sockaddr, sa_family))
4641+
return -EINVAL;
4642+
4643+
/* connect(AF_UNSPEC) has special handling, as it is a documented
4644+
* way to disconnect the socket
4645+
*/
4646+
if (address->sa_family == AF_UNSPEC)
4647+
return 0;
46404648

46414649
/*
46424650
* If a TCP, DCCP or SCTP socket, check name_connect permission
@@ -4657,8 +4665,6 @@ static int selinux_socket_connect_helper(struct socket *sock,
46574665
* need to check address->sa_family as it is possible to have
46584666
* sk->sk_family = PF_INET6 with addr->sa_family = AF_INET.
46594667
*/
4660-
if (addrlen < offsetofend(struct sockaddr, sa_family))
4661-
return -EINVAL;
46624668
switch (address->sa_family) {
46634669
case AF_INET:
46644670
addr4 = (struct sockaddr_in *)address;

0 commit comments

Comments
 (0)