Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Shashank Mohan Jain
Wed, 18 Nov 2026 04:29
[PATCH nf] netfilter: ctnetlink: apply port filters to SCTP and GRE entries
Author: Shashank Mohan Jain
Date: Wed, 18 Nov 2026 04:29
Date: Wed, 18 Nov 2026 04:29
55 lines
13137 bytes
13137 bytes
ctnetlink_filter_match_tuple() only compares CTA_PROTO_SRC_PORT and
CTA_PROTO_DST_PORT for TCP and UDP. SCTP and GRE also parse these
attributes into the filter tuple (both use nf_ct_port_nlattr_to_tuple()),
so a filter such as "protonum SCTP, src port X" is accepted, but the
port part is then ignored and every SCTP entry matches.
CTA_FILTER is also honoured by IPCTNL_MSG_CT_DELETE
(ctnetlink_flush_conntrack()), so a filtered flush that asks for one
SCTP port deletes all SCTP conntrack entries in the netns, and a
filtered dump returns all of them. The same applies to GRE keys.
The port and the GRE key share the same offset in
nf_conntrack_man_proto and in the dst union, so the existing
comparison works for both.
Found by reading the code with LLM assistance. Tested on x86_64 under
QEMU: with three SCTP and three GRE entries, a delete filtered on one
source port (or GRE key) removed all three entries of that protocol
before this change and only the matching one with it. Filtered dumps
show the same difference.
Fixes: cb8aa9a3affb ("netfilter: ctnetlink: add kernel side filtering for dump")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Shashank Mohan Jain <jain.sm@gmail.com>
---
Prepared with Claude Code (Anthropic), model Claude Opus 5.5
(claude-opus-5-5).
Based on nf.git main 734bef548a96. Tested with a small raw ctnetlink
program in a busybox initramfs under QEMU (x86_64, TCG). It adds three
SCTP, three GRE and three TCP entries, then sends dumps and
IPCTNL_MSG_CT_DELETE requests with CTA_FILTER set to protonum plus
source port. TCP behaves the same before and after. Also built for
i386; W=1 shows no warnings for nf_conntrack_netlink.c before or after.
net/netfilter/nf_conntrack_netlink.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 1f8d94a05..5e8e0b93b 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -1127,6 +1127,8 @@ 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:
+ case IPPROTO_GRE:
if ((flags & CTA_FILTER_FLAG(CTA_PROTO_SRC_PORT)) &&
filter_tuple->src.u.tcp.port != ct_tuple->src.u.tcp.port)
return 0;
--
2.43.0
Re: [PATCH nf] netfilter: ctnetlink: apply port filters to SCTP and GRE entries
Author: Pablo Neira Ayuso
Date: Wed, 18 Nov 2026 11:47
Date: Wed, 18 Nov 2026 11:47
63 lines
10774 bytes
10774 bytes
Hi,
This is nf-next material.
This is a feature that is missing. BTW, GRE has no ports.
On Wed, Nov 18, 2026 at 09:59:50AM +0530, Shashank Mohan Jain wrote:
> ctnetlink_filter_match_tuple() only compares CTA_PROTO_SRC_PORT and
> CTA_PROTO_DST_PORT for TCP and UDP. SCTP and GRE also parse these
> attributes into the filter tuple (both use nf_ct_port_nlattr_to_tuple()),
> so a filter such as "protonum SCTP, src port X" is accepted, but the
> port part is then ignored and every SCTP entry matches.
>
> CTA_FILTER is also honoured by IPCTNL_MSG_CT_DELETE
> (ctnetlink_flush_conntrack()), so a filtered flush that asks for one
> SCTP port deletes all SCTP conntrack entries in the netns, and a
> filtered dump returns all of them. The same applies to GRE keys.
>
> The port and the GRE key share the same offset in
> nf_conntrack_man_proto and in the dst union, so the existing
> comparison works for both.
>
> Found by reading the code with LLM assistance. Tested on x86_64 under
> QEMU: with three SCTP and three GRE entries, a delete filtered on one
> source port (or GRE key) removed all three entries of that protocol
> before this change and only the matching one with it. Filtered dumps
> show the same difference.
>
> Fixes: cb8aa9a3affb ("netfilter: ctnetlink: add kernel side filtering for dump")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Shashank Mohan Jain <jain.sm@gmail.com>
> ---
> Prepared with Claude Code (Anthropic), model Claude Opus 5.5
> (claude-opus-5-5).
>
> Based on nf.git main 734bef548a96. Tested with a small raw ctnetlink
> program in a busybox initramfs under QEMU (x86_64, TCG). It adds three
> SCTP, three GRE and three TCP entries, then sends dumps and
> IPCTNL_MSG_CT_DELETE requests with CTA_FILTER set to protonum plus
> source port. TCP behaves the same before and after. Also built for
> i386; W=1 shows no warnings for nf_conntrack_netlink.c before or after.
>
> net/netfilter/nf_conntrack_netlink.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
> index 1f8d94a05..5e8e0b93b 100644
> --- a/net/netfilter/nf_conntrack_netlink.c
> +++ b/net/netfilter/nf_conntrack_netlink.c
> @@ -1127,6 +1127,8 @@ 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:
> + case IPPROTO_GRE:
> if ((flags & CTA_FILTER_FLAG(CTA_PROTO_SRC_PORT)) &&
> filter_tuple->src.u.tcp.port != ct_tuple->src.u.tcp.port)
> return 0;
> --
> 2.43.0
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads