🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Henry Martin Fri, 27 Nov 2026 06:55
[PATCH nf] netfilter: nf_nat_h323: fix UDP mangle offset in set_addr()
#23380
Author: Henry Martin
Date: Fri, 27 Nov 2026 06:55
61 lines
12910 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads