Skip to content

Commit e38143c

Browse files
Florian Westphalgregkh
authored andcommitted
netfilter: nf_nat_sip: reload possible stale data pointer
commit 77e43bc upstream. 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: 7266507 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 430521a commit e38143c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

net/netfilter/nf_nat_sip.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,24 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff,
283283

284284
/* Mangle destination port for Cisco phones, then fix up checksums */
285285
if (dir == IP_CT_DIR_REPLY && ct_sip_info->forced_dport) {
286+
int doff = *dptr - (const char *)skb->data;
286287
struct udphdr *uh;
287288

289+
if (doff <= 0) {
290+
DEBUG_NET_WARN_ON_ONCE(1);
291+
return NF_DROP;
292+
}
293+
294+
/* ct_sip_info->forced_dport only expected with UDP */
295+
if (nf_ct_protonum(ct) != IPPROTO_UDP)
296+
return NF_DROP;
297+
288298
if (skb_ensure_writable(skb, skb->len)) {
289299
nf_ct_helper_log(skb, ct, "cannot mangle packet");
290300
return NF_DROP;
291301
}
292302

303+
*dptr = skb->data + doff;
293304
uh = (void *)skb->data + protoff;
294305
uh->dest = ct_sip_info->forced_dport;
295306

0 commit comments

Comments
 (0)