Netdev List
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: nf_nat_h323: fix UDP mangle offset in set_addr()
@ 2026-11-27  6:55 Henry Martin
  0 siblings, 0 replies; only message in thread
From: Henry Martin @ 2026-11-27  6:55 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Florian Westphal, Phil Sutter,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Patrick McHardy
  Cc: netfilter-devel, coreteam, netdev, Henry Martin, stable

set_addr() unconditionally adds dataoff to the embedded-address offset
before mangling the packet.  That is correct for TCP, where
nf_nat_mangle_tcp_packet() counts match_offset from the TCP header and
dataoff carries the TPKT header length.  For UDP,
nf_nat_mangle_udp_packet() already counts from the UDP payload, which
is where the decoded H.245 data starts, so the extra dataoff shifts the
write past the address.  When the decoded address sits at the end of
the payload, the shifted match_end runs past the skb tail and the
memmove() length in mangle_contents() underflows, turning into a huge
copy that runs off the mapped pages:

e.g. on mainline v7.4-rc4 (KASAN build):

 BUG: unable to handle page fault for address: ffff888140000000
 CPU: 1 UID: 1000 PID: 82 Comm: poc Tainted: G O 7.4.0-rc4 #2
 RIP: 0010:memmove+0x91/0x1c0
 RDX: fffffffffffffffe RSI: ffff88813ffffffe RDI: ffff88813ffffffe
 Call Trace:
  nf_nat_mangle_udp_packet+0x13f/0x420
  set_addr+0x18a/0x830
  nat_rtp_rtcp+0x50e/0x910
  h245_help+0x1eb/0x240
  nf_confirm+0x481/0x8c0
  raw_sendmsg+0x203d/0x2630

Only add dataoff on the TCP path.

This issue was discovered by Tencent CodeBuddy Security.

Cc: stable@vger.kernel.org
Fixes: f587de0e2feb ("[NETFILTER]: nf_conntrack/nf_nat: add H.323 helper port")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 net/ipv4/netfilter/nf_nat_h323.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/netfilter/nf_nat_h323.c b/net/ipv4/netfilter/nf_nat_h323.c
index 6bcd6734769b5..764bfc89027f6 100644
--- a/net/ipv4/netfilter/nf_nat_h323.c
+++ b/net/ipv4/netfilter/nf_nat_h323.c
@@ -35,9 +35,16 @@ static int set_addr(struct sk_buff *skb, unsigned int protoff,
 
 	buf.ip = ip;
 	buf.port = port;
-	addroff += dataoff;
 
 	if (ip_hdr(skb)->protocol == IPPROTO_TCP) {
+		/* nf_nat_mangle_tcp_packet() counts match_offset from the
+		 * TCP header, so move the offset past the TPKT header.
+		 * nf_nat_mangle_udp_packet() already counts from the UDP
+		 * payload, where the decoded data starts; adding dataoff
+		 * there writes past the address and can underflow the
+		 * memmove() length in mangle_contents().
+		 */
+		addroff += dataoff;
 		if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
 					      protoff, addroff, sizeof(buf),
 					      (char *) &buf, sizeof(buf))) {
-- 
2.39.5


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-27  6:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  6:55 [PATCH nf] netfilter: nf_nat_h323: fix UDP mangle offset in set_addr() Henry Martin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox