Commit 6597b256 authored by Daniel Borkmann's avatar Daniel Borkmann Committed by Willy Tarreau

packet: packet_getname_spkt: make sure string is always 0-terminated

[ Upstream commit 2dc85bf3 ]

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: default avatarDaniel Borkmann <dborkman@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent de892243
...@@ -1525,12 +1525,12 @@ static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr, ...@@ -1525,12 +1525,12 @@ static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr,
return -EOPNOTSUPP; return -EOPNOTSUPP;
uaddr->sa_family = AF_PACKET; 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); dev = dev_get_by_index(sock_net(sk), pkt_sk(sk)->ifindex);
if (dev) { if (dev) {
strncpy(uaddr->sa_data, dev->name, 14); strlcpy(uaddr->sa_data, dev->name, sizeof(uaddr->sa_data));
dev_put(dev); dev_put(dev);
} else }
memset(uaddr->sa_data, 0, 14);
*uaddr_len = sizeof(*uaddr); *uaddr_len = sizeof(*uaddr);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment