Skip to content

Commit

Permalink
selinux: Check address length before reading address family
Browse files Browse the repository at this point in the history
KMSAN will complain if valid address length passed to bind()/connect() is
shorter than sizeof("struct sockaddr"->sa_family) bytes.

Signed-off-by: Tetsuo Handa <[email protected]>
Signed-off-by: Paul Moore <[email protected]>
  • Loading branch information
Tetsuo Handa authored and pcmoore committed Apr 15, 2019
1 parent 1537ad1 commit c750e69
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -4512,7 +4512,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
struct lsm_network_audit net = {0,};
struct sockaddr_in *addr4 = NULL;
struct sockaddr_in6 *addr6 = NULL;
u16 family_sa = address->sa_family;
u16 family_sa;
unsigned short snum;
u32 sid, node_perm;

Expand All @@ -4522,6 +4522,9 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
* 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;
family_sa = address->sa_family;
switch (family_sa) {
case AF_UNSPEC:
case AF_INET:
Expand Down Expand Up @@ -4654,6 +4657,8 @@ 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 c750e69

Please sign in to comment.