From: Shashank Mohan Jain <jain.sm@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, linux-kernel@vger.kernel.org
Subject: [PATCH nf-next v2] netfilter: ctnetlink: support port filters for SCTP
Date: Wed, 18 Nov 2026 17:58:56 +0530 [thread overview]
Message-ID: <20261118122857.86193-1-jain.sm@gmail.com> (raw)
The kernel side filtering of ctnetlink compares CTA_PROTO_SRC_PORT and
CTA_PROTO_DST_PORT only for TCP and UDP entries. The SCTP l4proto
parses these attributes into the filter tuple
(nf_ct_port_nlattr_to_tuple()), so a filter such as "protonum SCTP,
src port X" is accepted, but the port is not compared and every SCTP
entry matches. A filtered dump then lists all SCTP entries, and a
filtered IPCTNL_MSG_CT_DELETE removes all of them.
Compare the ports for SCTP entries as well. The SCTP port has the same
offset as the TCP port in nf_conntrack_man_proto and in the dst union,
so the existing comparison works unchanged.
Found by reading the code with LLM assistance. Tested on x86_64 under
QEMU: with three SCTP entries, a delete filtered on one source port
removed all three before this change and only the matching one with
it. Filtered dumps show the same difference.
Assisted-by: LLM
Signed-off-by: Shashank Mohan Jain <jain.sm@gmail.com>
---
Changes in v2:
- Target nf-next as a feature, not a fix (Pablo). Drop the Fixes tag
and Cc: stable.
- Drop GRE, which has no ports (Pablo).
v1: https://lore.kernel.org/all/20261118042950.83129-1-jain.sm@gmail.com/
Prepared with Claude Code (Anthropic), model Claude Opus 5.5
(claude-opus-5-5).
The QEMU test above was run on v1, whose SCTP part is this change (a
small raw ctnetlink program in a busybox initramfs, x86_64, TCG; TCP
entries behave the same before and after).
net/netfilter/nf_conntrack_netlink.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 4b6abe3..798c11d 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -1127,6 +1127,7 @@ static int ctnetlink_filter_match_tuple(struct nf_conntrack_tuple *filter_tuple,
switch (ct_tuple->dst.protonum) {
case IPPROTO_TCP:
case IPPROTO_UDP:
+ case IPPROTO_SCTP:
if ((flags & CTA_FILTER_FLAG(CTA_PROTO_SRC_PORT)) &&
filter_tuple->src.u.tcp.port != ct_tuple->src.u.tcp.port)
return 0;
--
2.54.0 (Apple Git-157)
base-commit: d0107f38162279d9cb0e012210731176265f835d
reply other threads:[~2026-11-18 12:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261118122857.86193-1-jain.sm@gmail.com \
--to=jain.sm@gmail.com \
--cc=coreteam@netfilter.org \
--cc=fw@strlen.de \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®