netlink: Correctly calculate attribute length for address messages

In nl_addr_get() and nl_addr_dup() we step the attributes attached to each
RTM_NEWADDR message with a loop initialised with IFA_RTA() and
RTM_PAYLOAD() macros.  RTM_PAYLOAD(), however is for RTM_NEWROUTE messages
(struct rtmsg), not RTM_NEWADDR messages (struct ifaddrmsg).  Consequently
it miscalculates the size and means we can skip some attributes.  Switch
to IFA_PAYLOAD() which we should be using here.

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 2023-08-15 13:51:28 +10:00 committed by Stefano Brivio
parent 4b9f4c2513
commit b4f8ffd5c4

View file

@ -548,7 +548,7 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af,
if (ifa->ifa_index != ifi) if (ifa->ifa_index != ifi)
continue; continue;
for (rta = IFA_RTA(ifa), na = RTM_PAYLOAD(nh); RTA_OK(rta, na); for (rta = IFA_RTA(ifa), na = IFA_PAYLOAD(nh); RTA_OK(rta, na);
rta = RTA_NEXT(rta, na)) { rta = RTA_NEXT(rta, na)) {
if (rta->rta_type != IFA_ADDRESS) if (rta->rta_type != IFA_ADDRESS)
continue; continue;
@ -677,7 +677,7 @@ int nl_addr_dup(int s_src, unsigned int ifi_src,
ifa->ifa_index = ifi_dst; ifa->ifa_index = ifi_dst;
for (rta = IFA_RTA(ifa), na = RTM_PAYLOAD(nh); RTA_OK(rta, na); for (rta = IFA_RTA(ifa), na = IFA_PAYLOAD(nh); RTA_OK(rta, na);
rta = RTA_NEXT(rta, na)) { rta = RTA_NEXT(rta, na)) {
if (rta->rta_type == IFA_LABEL) if (rta->rta_type == IFA_LABEL)
rta->rta_type = IFA_UNSPEC; rta->rta_type = IFA_UNSPEC;