From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE7A51DE8AE; Sun, 7 Jun 2026 10:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780826860; cv=none; b=l6//dx4r9BAwJKi5Ie+YPaz16mJIHpeXf4jw6jGiam76MPU0I6CElExQfo9/zbI/2ZhVGpGl/sPoxSc8IW+tLvhSGG8E4+/ph//02Ht/h6VQmj/xIzHQo8H6FMClwP2YkLgUMtTRtaPcEYeMqgICpUi7dBMLXiac4Z60Qp09u+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780826860; c=relaxed/simple; bh=0c5GJ1ipA3MFYPzPQEtVgoSxj+QM73PZLap8n4QfZzI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GVaaC84xrLXRDf3angpcHPz9Wut3w1kNI+qmR4OQ8qTphLWhdyoDCfLjkAV7484TMSLkGH3vUYP4c3MKfmBk8G7kRdPSpSvbxhw6LLBCVylA4F6oNhl5UzXFM9HX4j1thTxlNCAtYly16RPxVJIHwl2AGxvpJoMPO/PyHUupf0o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=d+8srUFn; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="d+8srUFn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F6531F00893; Sun, 7 Jun 2026 10:07:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780826859; bh=iBqa2z+pwRPBsTJYlHLQsjDVBQ/3je56HAV2S4+MvlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=d+8srUFnEqBSUFSwM1C9CewxlF6ZHg+TGEjbXVNjFFJlaLKAoUYdBIPKptX//XSOy gpQE5OKxhHWP1G+Pa3OWcz16bQGDueXqEILF8xUMXwGPwYVSHseJNI1D6JkUrIltIw Jvvk7w/2Jf+jYX+bzstXlnKO4RsemuZ0J1QygRBA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Fernando Fernandez Mancera , Florian Westphal , Sasha Levin Subject: [PATCH 6.18 016/315] netfilter: synproxy: refresh tcphdr after skb_ensure_writable Date: Sun, 7 Jun 2026 11:56:43 +0200 Message-ID: <20260607095728.092233270@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607095727.528828913@linuxfoundation.org> References: <20260607095727.528828913@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit 92170e6afe927ab2792a3f71902845789c8e31b1 ] synproxy_tstamp_adjust() rewrites the TCP timestamp option in place and then patches the TCP checksum via inet_proto_csum_replace4() on the caller-supplied tcphdr pointer. Both ipv4_synproxy_hook() and ipv6_synproxy_hook() obtain that pointer with skb_header_pointer() before calling in, so it may either alias skb->head directly or point at the caller's on-stack _tcph buffer. Between obtaining the pointer and using it, the function calls skb_ensure_writable(skb, optend), which on a cloned or non-linear skb invokes pskb_expand_head() and frees the old skb->head. After that point the cached th is stale: caller (ipv[46]_synproxy_hook) th = skb_header_pointer(skb, ..., &_tcph) synproxy_tstamp_adjust(skb, protoff, th, ...) skb_ensure_writable(skb, optend) pskb_expand_head() /* kfree(old skb->head) */ ... inet_proto_csum_replace4(&th->check, ...) /* writes into freed head, or into the caller's stack copy leaving the on-wire checksum stale */ The option bytes are written through skb->data and are fine; only the checksum update goes through th and so lands in the wrong place. The result is either a write into freed slab memory or a packet leaving with a checksum that does not match its payload. Fix by re-deriving th from skb->data + protoff immediately after skb_ensure_writable() succeeds, so the subsequent checksum update targets the linear, writable header. Fixes: 48b1de4c110a ("netfilter: add SYNPROXY core/target") Assisted-by: kres (claude-opus-4-7) Signed-off-by: Chris Mason Reviewed-by: Fernando Fernandez Mancera Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/netfilter/nf_synproxy_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c index 3fa3f5dfb26444..6a851ac4dd048f 100644 --- a/net/netfilter/nf_synproxy_core.c +++ b/net/netfilter/nf_synproxy_core.c @@ -199,6 +199,8 @@ synproxy_tstamp_adjust(struct sk_buff *skb, unsigned int protoff, if (skb_ensure_writable(skb, optend)) return 0; + th = (struct tcphdr *)(skb->data + protoff); + while (optoff < optend) { unsigned char *op = skb->data + optoff; -- 2.53.0