Skip to content

Commit c750e69

Browse files
Tetsuo Handapcmoore
authored andcommitted
selinux: Check address length before reading address family
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]>
1 parent 1537ad1 commit c750e69

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

security/selinux/hooks.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4512,7 +4512,7 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
45124512
struct lsm_network_audit net = {0,};
45134513
struct sockaddr_in *addr4 = NULL;
45144514
struct sockaddr_in6 *addr6 = NULL;
4515-
u16 family_sa = address->sa_family;
4515+
u16 family_sa;
45164516
unsigned short snum;
45174517
u32 sid, node_perm;
45184518

@@ -4522,6 +4522,9 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
45224522
* need to check address->sa_family as it is possible to have
45234523
* sk->sk_family = PF_INET6 with addr->sa_family = AF_INET.
45244524
*/
4525+
if (addrlen < offsetofend(struct sockaddr, sa_family))
4526+
return -EINVAL;
4527+
family_sa = address->sa_family;
45254528
switch (family_sa) {
45264529
case AF_UNSPEC:
45274530
case AF_INET:
@@ -4654,6 +4657,8 @@ static int selinux_socket_connect_helper(struct socket *sock,
46544657
* need to check address->sa_family as it is possible to have
46554658
* sk->sk_family = PF_INET6 with addr->sa_family = AF_INET.
46564659
*/
4660+
if (addrlen < offsetofend(struct sockaddr, sa_family))
4661+
return -EINVAL;
46574662
switch (address->sa_family) {
46584663
case AF_INET:
46594664
addr4 = (struct sockaddr_in *)address;

0 commit comments

Comments
 (0)