]> git.hungrycats.org Git - linux/commitdiff
packet: packet_getname_spkt: make sure string is always 0-terminated
authorDaniel Borkmann <dborkman@redhat.com>
Wed, 12 Jun 2013 14:02:27 +0000 (16:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 19 May 2014 05:53:43 +0000 (07:53 +0200)
[ Upstream commit 2dc85bf323515e59e15dfa858d1472bb25cad0fe ]

uaddr->sa_data is exactly of size 14, which is hard-coded here and
passed as a size argument to strncpy(). A device name can be of size
IFNAMSIZ (== 16), meaning we might leave the destination string
unterminated. Thus, use strlcpy() and also sizeof() while we're
at it. We need to memset the data area beforehand, since strlcpy
does not padd the remaining buffer with zeroes for user space, so
that we do not possibly leak anything.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
net/packet/af_packet.c

index 728c080eeaca8bf5960c797ccdc0b894657e51c2..f084e01b80895b44675621c312d39546968f1435 100644 (file)
@@ -1525,12 +1525,12 @@ static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr,
                return -EOPNOTSUPP;
 
        uaddr->sa_family = AF_PACKET;
+       memset(uaddr->sa_data, 0, sizeof(uaddr->sa_data));
        dev = dev_get_by_index(sock_net(sk), pkt_sk(sk)->ifindex);
        if (dev) {
-               strncpy(uaddr->sa_data, dev->name, 14);
+               strlcpy(uaddr->sa_data, dev->name, sizeof(uaddr->sa_data));
                dev_put(dev);
-       } else
-               memset(uaddr->sa_data, 0, 14);
+       }
        *uaddr_len = sizeof(*uaddr);
 
        return 0;