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 69E804071C7; Sun, 7 Jun 2026 10:05:50 +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=1780826751; cv=none; b=sMqed8U2eybYMe1tQoBkBR63DmhHgXcUDRU9xhyyLIooHBxSY5sREzdO/O7hsvzZy93JAlv/xFQTHGUpJgpvdsC7qUZBJIBzhA7rNDPtrGjIkNlVzRSJWUnDROrgU2rytmd0EDcMG422Oc1qpyO9X54kJj3PtRiNFzStYMWKV2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780826751; c=relaxed/simple; bh=BVIWnP7hYX2kPzQ4itWb/Z/SAOKzYUXB4KF32EAi0UI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MGpIaGrpCOBpxqQ+xvPCOZeuNnde2/U+vn+xvwMDf8Rms0kDDMFtHqyYL2vSnrnMmLtEkeVC4OJWe2nNKSpdXnhyyF/9W13R+F6y+fyrHwR2/FjiuxIbFFKHdXaMI1/utTqUPrf1wBH+pC473fW5EnBQlr63pcedhVgXsNIBDRQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PLH/Pjpx; 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="PLH/Pjpx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A40A1F00893; Sun, 7 Jun 2026 10:05:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780826750; bh=mVlan1Oxf9fXBr8AOaj2uJLKKIRNiMdcfgY2MlS1Pdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PLH/PjpxC1wvMNqFMENecwBDVWAcoHjtutEkEtBovpohOhR0G0N9OsikqGrceRNji Ivg8LLdzdCfDBhqwh5Fp9TGr3wjc5Kb1+3oQEGf93+hkbxz438mb77/wxH0gT3yhRT 5QZNN/hNceybAI7XLGi5MGfgXyZMmVG1kQdXB8js= 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 7.0 017/332] netfilter: synproxy: refresh tcphdr after skb_ensure_writable Date: Sun, 7 Jun 2026 11:56:26 +0200 Message-ID: <20260607095728.683473916@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607095728.031258202@linuxfoundation.org> References: <20260607095728.031258202@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 7.0-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 57f57e2fc80a8f..036c8586f49b75 100644 --- a/net/netfilter/nf_synproxy_core.c +++ b/net/netfilter/nf_synproxy_core.c @@ -200,6 +200,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