Skip to content

Commit

Permalink
selinux: do not report error on connect(AF_UNSPEC)
Browse files Browse the repository at this point in the history
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 <tdeseyn@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 68741a8 ("selinux: Fix ltp test connect-syscall failure")
Suggested-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
Paolo Abeni authored and pcmoore committed May 21, 2019
1 parent 35a196b commit 05174c9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -4637,6 +4637,14 @@ static int selinux_socket_connect_helper(struct socket *sock,
err = sock_has_perm(sk, SOCKET__CONNECT);
if (err)
return err;
if (addrlen < offsetofend(struct sockaddr, sa_family))
return -EINVAL;

/* connect(AF_UNSPEC) has special handling, as it is a documented
* way to disconnect the socket
*/
if (address->sa_family == AF_UNSPEC)
return 0;

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

0 comments on commit 05174c9

Please sign in to comment.