Skip to content

Commit

Permalink
tomoyo: 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()/
sendmsg() is shorter than sizeof("struct sockaddr"->sa_family) bytes.

Signed-off-by: Tetsuo Handa <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
Tetsuo Handa authored and James Morris committed May 10, 2019
1 parent e80b185 commit e6193f7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions security/tomoyo/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ static int tomoyo_check_inet_address(const struct sockaddr *addr,
{
struct tomoyo_inet_addr_info *i = &address->inet;

if (addr_len < offsetofend(struct sockaddr, sa_family))
return 0;
switch (addr->sa_family) {
case AF_INET6:
if (addr_len < SIN6_LEN_RFC2133)
Expand Down Expand Up @@ -594,6 +596,8 @@ static int tomoyo_check_unix_address(struct sockaddr *addr,
{
struct tomoyo_unix_addr_info *u = &address->unix0;

if (addr_len < offsetofend(struct sockaddr, sa_family))
return 0;
if (addr->sa_family != AF_UNIX)
return 0;
u->addr = ((struct sockaddr_un *) addr)->sun_path;
Expand Down

0 comments on commit e6193f7

Please sign in to comment.