Skip to contentSkip to conversation

netfilter: ctnetlink: support port filters for SCTP

PATCH New Shashank Mohan Jain 1 participant 1 message Nov 18

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 netfilter: ctnetlink: support port filters for SCTP

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

---
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/[email protected]/

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(+)
net/netfilter/nf_conntrack_netlink.c +1 -0
index 4b6abe3..798c11d 100644
@@ -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;
Signature · 3 lines
2.54.0 (Apple Git-157)

base-commit: d0107f38162279d9cb0e012210731176265f835d