From: Joas Antonio dos Santos <joasantonio108@gmail.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>, Florian Westphal <fw@strlen.de>
Cc: Phil Sutter <phil@nwl.cc>,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org
Subject: [PATCH nf] netfilter: nf_conntrack_sip: only honour Via: port in original direction
Date: Wed, 07 Oct 2026 12:25:00 -0300 [thread overview]
Message-ID: <179138670045.80227.4002052840715926590@gmail.com> (raw)
The Cisco phone workaround in process_sip_request() records the port
from the topmost Via: header in ct_sip_info->forced_dport whenever the
Via address matches the sender of the current request and the port
differs from the sender's source port. nf_nat_sip() then rewrites the
UDP destination port of every reply-direction packet to that value.
The check is performed for requests in both directions. For a request
arriving in the reply direction, ct->tuplehash[dir].tuple.src is the
remote peer's own address and port, so the remote side can trivially
satisfy the condition with a Via: line of the form
Via: SIP/2.0/UDP <own-address>:<any-port>
and force forced_dport to a port of its choosing. From then on,
packets it sends on this flow are delivered to the NATed host at that
port instead of the port the NAT mapping was created for, which bypasses
the port restriction normally enforced by the NAT mapping.
The workaround is only meant for phones behind the NAT router, i.e.
requests in the original direction. Restrict it accordingly.
Fixes: 7266507d8999 ("netfilter: nf_ct_sip: support Cisco 7941/7945 IP phones")
Signed-off-by: Joas Antonio dos Santos <joasantonio108@gmail.com>
Assisted-by: Claude:claude-opus-5-5
---
Tested on 602042bf29f6 (arm64, QEMU) with client -> router -> server
network namespaces; the router runs nft masquerade and a "sip" ct helper
on udp/5060. The client sends an OPTIONS request from port 5060; the
server answers with a request carrying "Via: SIP/2.0/UDP <server>:4444"
and then a plain UDP payload on the same flow.
before: client receives both datagrams on port 4444
after: client receives both datagrams on port 5060
net/netfilter/nf_conntrack_sip.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
index 64bc440b1..ef655a0bb 100644
--- a/net/netfilter/nf_conntrack_sip.c
+++ b/net/netfilter/nf_conntrack_sip.c
@@ -1586,8 +1586,14 @@ static int process_sip_request(struct sk_buff *skb, unsigned int protoff,
* router for one of these phones, save the port number from the
* Via: header so that nf_nat_sip can redirect the responses to
* the correct port.
+ *
+ * Only honour the Via: port for requests coming from the phone,
+ * i.e. in the original direction. The remote peer must not be
+ * able to pick the destination port of packets delivered to the
+ * NATed host.
*/
- if (ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen,
+ if (dir == IP_CT_DIR_ORIGINAL &&
+ ct_sip_parse_header_uri(ct, *dptr, NULL, *datalen,
SIP_HDR_VIA_UDP, NULL, &matchoff,
&matchlen, &addr, &port) > 0 &&
port != ct->tuplehash[dir].tuple.src.u.udp.port &&
next reply other threads:[~2026-10-07 15:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 15:25 Joas Antonio dos Santos [this message]
2026-10-07 15:30 ` [PATCH nf] netfilter: nf_conntrack_sip: only honour Via: port in original direction netdev-bot+sinfo
2026-10-07 15:52 ` Joas Antonio
2026-10-07 19:44 ` Pablo Neira Ayuso
2026-10-07 19:58 ` Joas Antonio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179138670045.80227.4002052840715926590@gmail.com \
--to=joasantonio108@gmail.com \
--cc=coreteam@netfilter.org \
--cc=fw@strlen.de \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox