tomoyo: Check address length before reading address family
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fri, 12 Apr 2019 10:59:36 +0000 (19:59 +0900)
committerJames Morris <jamorris@linux.microsoft.com>
Fri, 10 May 2019 21:58:25 +0000 (14:58 -0700)
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 <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: James Morris <jamorris@linux.microsoft.com>
security/tomoyo/network.c

index 9094f4b3b367b5d37332727d11722602bed03e5a..f9ff121d7e1eb4e9251d43d43f1f90bbd1a76cd1 100644 (file)
@@ -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)
@@ -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;