From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=J183SPT7; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 36EE45A0262 for ; Thu, 12 Sep 2024 08:59:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1726124381; bh=qudDYUn3qPtyIGmwOSd2X4PTWghMMaQ1sCqA1WFLTiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J183SPT7jvgjJ3q1sSW5JtjFiQdE69zT2fNFUYs2vcDX2xbaI65BmLgL8uLf1FWiv /O7odnUMebU2fs5gSdHCp7CjjvWlPXdg37F00zN9pBN5illlwnYRN901FPffuS/hme R2lag4MjuWShDK8yBlivYbR8adY7mujHSa9OK9mf3QIZQZccV6wg6I+UtawOJ6v4B4 4s7Racrvj3sGUJADCC6xE5GOxU2s2D3KPhNVVzqefjoK1rf/luFay8k1ix8sF5xhLp gFv+urBvMi7lTlDEFFCOmPg44D27nN9eG8r23E8nCWpJ22r3z1qfDN2k8H50ff5Vus LPtsn/dt1ov6Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4X47bd6ywpz4x4c; Thu, 12 Sep 2024 16:59:41 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/2] tcp: Avoid overlapping memcpy() in DUP_ACK handling Date: Thu, 12 Sep 2024 16:59:40 +1000 Message-ID: <20240912065940.1738239-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240912065940.1738239-1-david@gibson.dropbear.id.au> References: <20240912065940.1738239-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 6OSTT6KIKIB2KWO6LUQJ7PF4J6Z32Z5R X-Message-ID-Hash: 6OSTT6KIKIB2KWO6LUQJ7PF4J6Z32Z5R 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 handling the DUP_ACK flag, we copy all the buffers making up the ack frame. However, all our frames share the same buffer for the Ethernet header (tcp4_eth_src or tcp6_eth_src), so copying the TCP_IOV_ETH will result in a (perfectly) overlapping memcpy(). This seems to have been harmless so far, but overlapping ranges to memcpy() is undefined behaviour, so we really should avoid it. Signed-off-by: David Gibson --- tcp_buf.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tcp_buf.c b/tcp_buf.c index 2e044b27..1a398461 100644 --- a/tcp_buf.c +++ b/tcp_buf.c @@ -332,9 +332,13 @@ int tcp_buf_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags) else dup_iov = tcp6_l2_flags_iov[tcp6_flags_used++]; - for (i = 0; i < TCP_NUM_IOVS; i++) - memcpy(dup_iov[i].iov_base, iov[i].iov_base, - iov[i].iov_len); + for (i = 0; i < TCP_NUM_IOVS; i++) { + /* All frames share the same ethernet header buffer */ + if (i != TCP_IOV_ETH) { + memcpy(dup_iov[i].iov_base, iov[i].iov_base, + iov[i].iov_len); + } + } dup_iov[TCP_IOV_PAYLOAD].iov_len = iov[TCP_IOV_PAYLOAD].iov_len; } -- 2.46.0