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 2AF575A0274 for ; Wed, 28 Feb 2024 06:39:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709098773; bh=ZIGf5XT9ocEWf7VPQhNBCxvkAAGGYpzMtaNm4dWxXCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GrzW4ck9y3YLkcXdu6HMiacc7ZZZWb1RJH6SNIGIwjCSp/TOKorAX+DX2hNgwp6QL nDBE3gk8A+y+WqeO4VZkPlA24ym/2wK7BXenPRk5Zu86OV14He21YAyT1uDCNIQL2u ha/7iGXX/OpFndUYe2osyU5k8FDxgp8en+7cxBtvmzfkRBZFB2dEAwjJjIBLmSR5To 3iHQ7RqnjlGIbaVxuGWxasg1yUFIX+lRSWPaeYD2VXgFeR7QxbKe7HIj9yTZbVdc4S tP3M7loQ+GjK1Kbf/+BM8MHcz4CnBOD7YNsbu/cL84fon5pbna7hxLTJVQZ4c8mHwh yjn1Et90mwxDA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Tl3853PSDz4wxt; Wed, 28 Feb 2024 16:39:33 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top, Laurent Vivier Subject: [PATCH v2 4/5] udp: Fix incorrect usage of IPv6 state in IPv4 path Date: Wed, 28 Feb 2024 16:39:28 +1100 Message-ID: <20240228053929.1570254-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228053929.1570254-1-david@gibson.dropbear.id.au> References: <20240228053929.1570254-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: BGVB5MXAJEOVY53OXKZYWEE75WOCEJY5 X-Message-ID-Hash: BGVB5MXAJEOVY53OXKZYWEE75WOCEJY5 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 561ba604..d55a6827 100644 --- a/udp.c +++ b/udp.c @@ -875,8 +875,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