]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
netfilter: nf_nat_sip: reload possible stale data pointer
authorFlorian Westphal <fw@strlen.de>
Wed, 1 Jul 2026 05:44:17 +0000 (07:44 +0200)
committerFlorian Westphal <fw@strlen.de>
Fri, 3 Jul 2026 12:45:20 +0000 (14:45 +0200)
commit77e43bcb7ec177e293a5c3f1b91a2c5aebfb6c68
treed8beb873dbe382c2642972bcbe502820e60d5d5e
parentd335dcc6f521571d57117b8deeebc940836e5450
netfilter: nf_nat_sip: reload possible stale data pointer

quoting sashiko:
 ------------------------------------------------------------------------
 [..] noticed a potential memory bug and header corruption involving the
 SIP NAT helper.

 In net/netfilter/nf_nat_sip.c:nf_nat_sip():
if (skb_ensure_writable(skb, skb->len)) {
nf_ct_helper_log(skb, ct, "cannot mangle packet");
return NF_DROP;
}
uh = (void *)skb->data + protoff;
uh->dest = ct_sip_info->forced_dport;
if (!nf_nat_mangle_udp_packet(skb, ct, ctinfo, protoff,
      0, 0, NULL, 0)) {

 If a cloned or fragmented SKB is reallocated by skb_ensure_writable(), the
 old data buffer is freed. However, nf_nat_sip() fails to update *dptr to
 point to the new buffer.

 It also appears to use nf_nat_mangle_udp_packet() on what could be a TCP
 packet, which would overwrite the sequence number with a checksum update.
 ------------------------------------------------------------------------

nf_conntrack_sip linerizes skbs, hence no fragmented skb can be seen.
But clones are possible, so rebuild dptr.

Disable nf_nat_mangle_udp_packet() branch for TCP streams.
It doesn't look like this can ever happen, else we should have received
bug reports about this, so just check the conntrack is UDP and drop
otherwise.

The calling conntrack_sip set ->forced_dport for SIP_HDR_VIA_UDP messages,
so I don't think this is ever expected to be true for a TCP stream.

Fixes: 7266507d8999 ("netfilter: nf_ct_sip: support Cisco 7941/7945 IP phones")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-sonnet-4-6
Signed-off-by: Florian Westphal <fw@strlen.de>
net/netfilter/nf_nat_sip.c