Skip to content

Commit c7e0d6c

Browse files
Paolo Abenidavem330
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 falling back to the generic/old code when the address family is not AF_INET{4,6}, but leave the SCTP code path untouched, as it has specific constraints. Fixes: 68741a8 ("selinux: Fix ltp test connect-syscall failure") Reported-by: Tom Deseyn <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c264ed4 commit c7e0d6c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

security/selinux/hooks.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4649,7 +4649,7 @@ static int selinux_socket_connect_helper(struct socket *sock,
46494649
struct lsm_network_audit net = {0,};
46504650
struct sockaddr_in *addr4 = NULL;
46514651
struct sockaddr_in6 *addr6 = NULL;
4652-
unsigned short snum;
4652+
unsigned short snum = 0;
46534653
u32 sid, perm;
46544654

46554655
/* sctp_connectx(3) calls via selinux_sctp_bind_connect()
@@ -4674,12 +4674,12 @@ static int selinux_socket_connect_helper(struct socket *sock,
46744674
break;
46754675
default:
46764676
/* Note that SCTP services expect -EINVAL, whereas
4677-
* others expect -EAFNOSUPPORT.
4677+
* others must handle this at the protocol level:
4678+
* connect(AF_UNSPEC) on a connected socket is
4679+
* a documented way disconnect the socket.
46784680
*/
46794681
if (sksec->sclass == SECCLASS_SCTP_SOCKET)
46804682
return -EINVAL;
4681-
else
4682-
return -EAFNOSUPPORT;
46834683
}
46844684

46854685
err = sel_netport_sid(sk->sk_protocol, snum, &sid);

0 commit comments

Comments
 (0)