Skip to content

Commit

Permalink
selinux: Fix error priority for bind with AF_UNSPEC on PF_INET6 socket
Browse files Browse the repository at this point in the history
[ Upstream commit bbf5a1d ]

The IPv6 network stack first checks the sockaddr length (-EINVAL error)
before checking the family (-EAFNOSUPPORT error).

This was discovered thanks to commit a549d05 ("selftests/landlock:
Add network tests").

Cc: Eric Paris <[email protected]>
Cc: Konstantin Meskhidze <[email protected]>
Cc: Paul Moore <[email protected]>
Cc: Stephen Smalley <[email protected]>
Reported-by: Muhammad Usama Anjum <[email protected]>
Closes: https://lore.kernel.org/r/[email protected]
Fixes: 0f8db8c ("selinux: add AF_UNSPEC and INADDR_ANY checks to selinux_socket_bind()")
Signed-off-by: Mickaël Salaün <[email protected]>
Tested-by: Muhammad Usama Anjum <[email protected]>
Signed-off-by: Paul Moore <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
l0kod authored and gregkh committed Jan 25, 2024
1 parent d8ac253 commit 5e37fa0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -4774,6 +4774,13 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
return -EINVAL;
addr4 = (struct sockaddr_in *)address;
if (family_sa == AF_UNSPEC) {
if (family == PF_INET6) {
/* Length check from inet6_bind_sk() */
if (addrlen < SIN6_LEN_RFC2133)
return -EINVAL;
/* Family check from __inet6_bind() */
goto err_af;
}
/* see __inet_bind(), we only want to allow
* AF_UNSPEC if the address is INADDR_ANY
*/
Expand Down

0 comments on commit 5e37fa0

Please sign in to comment.