From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id EA0F15A0274 for ; Tue, 15 Aug 2023 05:51:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1692071493; bh=4L/dAoqLuGDMs+Dtgw0Fzhg3R94tSx8DGiGE4REhOYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lklCkbPm3vB7KbIgmFZdM5khNKI4fw1xv9wbrYDZDO0PU3//KpuuNg9xc0p/zHrfp 3kIhx96BpMeNX+ZY/Zi481ap/f+7sa1ikgnPvR4lbo2RhKuvWXXHuN6HgeNJ6WdYP9 KV1dSo48hsxQv3ppUyVHBCWViq+U8b/Kq/YhaBr4= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RPy4P1vc6z4wb8; Tue, 15 Aug 2023 13:51:33 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/3] netlink: Correctly calculate attribute length for address messages Date: Tue, 15 Aug 2023 13:51:28 +1000 Message-ID: <20230815035129.1942905-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230815035129.1942905-1-david@gibson.dropbear.id.au> References: <20230815035129.1942905-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: NXC4IDPFUHVGH5HTHA7H3HTQQZYQL5X6 X-Message-ID-Hash: NXC4IDPFUHVGH5HTHA7H3HTQQZYQL5X6 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netlink.c b/netlink.c index ff44e13..69a5304 100644 --- a/netlink.c +++ b/netlink.c @@ -548,7 +548,7 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af, if (ifa->ifa_index != ifi) 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)) { if (rta->rta_type != IFA_ADDRESS) continue; @@ -677,7 +677,7 @@ int nl_addr_dup(int s_src, unsigned int ifi_src, 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)) { if (rta->rta_type == IFA_LABEL) rta->rta_type = IFA_UNSPEC; -- 2.41.0