udp: Fix incorrect usage of IPv6 state in IPv4 path

When forwarding IPv4 packets in udp_tap_handler(), we incorrectly use an
IPv6 address test on our IPv4 address (which could cause an out of bounds
access), and possibly set our bind interface to the IPv6 interface based on
it.  Adjust to correctly look at the IPv4 address and IPv4 interface.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-02-28 16:39:28 +11:00 committed by Stefano Brivio
parent deea5a8437
commit 745fa38169

4
udp.c
View file

@ -875,8 +875,8 @@ int udp_tap_handler(struct ctx *c, uint8_t pif,
}; };
const char *bind_if = NULL; const char *bind_if = NULL;
if (!IN6_IS_ADDR_LOOPBACK(&s_in.sin_addr)) if (!IN4_IS_ADDR_LOOPBACK(&s_in.sin_addr))
bind_if = c->ip6.ifname_out; bind_if = c->ip4.ifname_out;
if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.addr_out) && if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.addr_out) &&
!IN4_IS_ADDR_LOOPBACK(&s_in.sin_addr)) !IN4_IS_ADDR_LOOPBACK(&s_in.sin_addr))