From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 4297F5A0289 for ; Thu, 22 Feb 2024 00:21:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1708557678; bh=4uc6hHnumV9lqe9ZY7bd8N5gW48aSYVNCSAC3N6ECJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VZuEBwBO2ULtO5TUUyj+jpnPtRJyudpZe6LsU5zXmMIfcKd3zADuQ0PY+5dpGmNyN /e6DfQkClXrAcOnFnq3tHZzMI5tSYqOOHxCbJojTXC0UsuX56y7j2r4H/53Z00IkW3 qOUEavdEYAyeMF8SSME/R4Ljbia/wZDvRzqlhvpbjWkePLsPAf+vXj9vRasqVCy6J/ 6ZEXbMmYub0oCuKEG/wg649n2pXTu3EoSJ3WSt4OGfVSEbEIJfTje1nG+RNDpXKVPm 5wf5XQ/XQgILcdLywCpQZEv/wmYhZIGDQVjcqp/6TnPl/Se1zTflK5Y1rA8qJeNmBm MhU7l+KvkxJxw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TgC2Q2YtWz4wyk; Thu, 22 Feb 2024 10:21:18 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 6/7] udp: Fix incorrect usage of IPv6 state in IPv4 path Date: Thu, 22 Feb 2024 10:21:14 +1100 Message-ID: <20240221232115.1376333-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221232115.1376333-1-david@gibson.dropbear.id.au> References: <20240221232115.1376333-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: QE3V2SXO66W7YHM6HS5VSX3W7RUMDG7A X-Message-ID-Hash: QE3V2SXO66W7YHM6HS5VSX3W7RUMDG7A 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: 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 --- udp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/udp.c b/udp.c index 87f440f5..0204f1d2 100644 --- a/udp.c +++ b/udp.c @@ -874,8 +874,8 @@ int udp_tap_handler(struct ctx *c, uint8_t pif, }; const char *bind_if = NULL; - if (!IN6_IS_ADDR_LOOPBACK(&s_in.sin_addr)) - bind_if = c->ip6.ifname_out; + if (!IN4_IS_ADDR_LOOPBACK(&s_in.sin_addr)) + bind_if = c->ip4.ifname_out; if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.addr_out) && !IN4_IS_ADDR_LOOPBACK(&s_in.sin_addr)) -- 2.43.2