diff options
author | brooks <brooks@FreeBSD.org> | 2018-04-09 15:21:40 +0000 |
---|---|---|
committer | brooks <brooks@FreeBSD.org> | 2018-04-09 15:21:40 +0000 |
commit | 46e8f7b6a3b8ad0727ce0cff41c08c2aaeb59393 (patch) | |
tree | 586b1d29b66e721f2401a1b63b7ca782c27f5143 /sys/net/if.c | |
parent | eae13f400d071c03fff4ebf1e223fad718b49516 (diff) | |
download | FreeBSD-src-46e8f7b6a3b8ad0727ce0cff41c08c2aaeb59393.zip FreeBSD-src-46e8f7b6a3b8ad0727ce0cff41c08c2aaeb59393.tar.gz |
MFC r332151:
ifconf(): correct handling of sockaddrs smaller than struct sockaddr.
Portable programs that use SIOCGIFCONF (e.g. traceroute) assume
that each pseudo ifreq is of length MAX(sizeof(struct ifreq),
sizeof(ifr_name) + ifr_addr.sa_len). For short sockaddrs we copied
too much from the source sockaddr resulting in a heap leak.
I believe only one such sockaddr exists (struct sockaddr_sco which
is 8 bytes) and it is unclear if such sockaddrs end up on interfaces
in practice. If it did, the result would be an 8 byte heap leak on
current architectures.
admbugs: 869
Reviewed by: kib
Obtained from: CheriBSD
Security: kernel heap leak
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D14981
Diffstat (limited to 'sys/net/if.c')
-rw-r--r-- | sys/net/if.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index ae2136d..0aa0f87 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -3153,7 +3153,13 @@ again: max_len += sizeof(ifr); } else if (sa->sa_len <= sizeof(*sa)) { - ifr.ifr_addr = *sa; + if (sa->sa_len < sizeof(*sa)) { + memset(&ifr.ifr_ifru.ifru_addr, 0, + sizeof(ifr.ifr_ifru.ifru_addr)); + memcpy(&ifr.ifr_ifru.ifru_addr, sa, + sa->sa_len); + } else + ifr.ifr_ifru.ifru_addr = *sa; sbuf_bcat(sb, &ifr, sizeof(ifr)); max_len += sizeof(ifr); } else { |