net: fool proof dev_valid_name()
authorEric Dumazet <edumazet@google.com>
Thu, 5 Apr 2018 13:39:26 +0000 (06:39 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 Apr 2018 17:48:34 +0000 (19:48 +0200)
[ Upstream commit a9d48205d0aedda021fc3728972a9e9934c2b9de ]

We want to use dev_valid_name() to validate tunnel names,
so better use strnlen(name, IFNAMSIZ) than strlen(name) to make
sure to not upset KASAN.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/core/dev.c

index 1259587370b82397fc2184c345da9fe6d08f3ca3..3d9190c2940d3d7fb75641a17cca4d8b2a461ae6 100644 (file)
@@ -993,7 +993,7 @@ bool dev_valid_name(const char *name)
 {
        if (*name == '\0')
                return false;
-       if (strlen(name) >= IFNAMSIZ)
+       if (strnlen(name, IFNAMSIZ) == IFNAMSIZ)
                return false;
        if (!strcmp(name, ".") || !strcmp(name, ".."))
                return false;