Skip to contentSkip to conversation

netfilter: ctnetlink: revert to dumping mark regardless of event type

PATCH Superseded Ivan Delalande 3 participants 4 messages Mar 2, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: ctnetlink: revert to dumping mark regardless of event type

I assume that change was unintentional, we have userspace code that needs the mark while listening for events like REPLY, DESTROY, etc.

Fixes 1feeae071507 ("netfilter: ctnetlink: fix compilation warning after data race fixes in ct mark")
---
 net/netfilter/nf_conntrack_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +1 -1
index c11dff91d52d..194822f8f1ee 100644
@@ -831,7 +831,7 @@ ctnetlink_conntrack_event(unsigned int events, const struct nf_ct_event *item)
 	}
 
 #ifdef CONFIG_NF_CONNTRACK_MARK
-	if (events & (1 << IPCT_MARK) &&
+	if ((events & (1 << IPCT_MARK) || READ_ONCE(ct->mark)) &&
 	    ctnetlink_dump_mark(skb, ct) < 0)
 		goto nla_put_failure;
 #endif
Signature · 1 line
Arista Networks
maintainer
#1 lore raw
Quoted 15 lines · Ivan Delalande

I assume that change was unintentional, we have userspace code that needs the mark while listening for events like REPLY, DESTROY, etc.

Fixes 1feeae071507 ("netfilter: ctnetlink: fix compilation warning after data race fixes in ct mark")
---
 net/netfilter/nf_conntrack_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +0 -0
index c11dff91d52d..194822f8f1ee 100644

net/netfilter/nf_conntrack_netlink.c ctnetlink_conntrack_event(unsigned int events, const struct nf_ct_event *item) · line 836

Quoted 7 lines
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -831,7 +831,7 @@ ctnetlink_conntrack_event(unsigned int events, const struct nf_ct_event *item)
 	}
 
 #ifdef CONFIG_NF_CONNTRACK_MARK
-	if (events & (1 << IPCT_MARK) &&
+	if ((events & (1 << IPCT_MARK) || READ_ONCE(ct->mark)) &&
 	    ctnetlink_dump_mark(skb, ct) < 0)
 		goto nla_put_failure;

Probably better to just drop the event bit test?

if (ctnetlink_dump_mark(skb, ct) < 0)

	goto nla_put_failure;
#2 lore raw
Quoted 26 lines · Florian Westphal
Quoted 15 lines · Ivan Delalande

I assume that change was unintentional, we have userspace code that needs the mark while listening for events like REPLY, DESTROY, etc.

Fixes 1feeae071507 ("netfilter: ctnetlink: fix compilation warning after data race fixes in ct mark")
---
 net/netfilter/nf_conntrack_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +0 -0
index c11dff91d52d..194822f8f1ee 100644

net/netfilter/nf_conntrack_netlink.c ctnetlink_conntrack_event(unsigned int events, const struct nf_ct_event *item) · line 836

Quoted 7 lines
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -831,7 +831,7 @@ ctnetlink_conntrack_event(unsigned int events, const struct nf_ct_event *item)
 	}
 
 #ifdef CONFIG_NF_CONNTRACK_MARK
-	if (events & (1 << IPCT_MARK) &&
+	if ((events & (1 << IPCT_MARK) || READ_ONCE(ct->mark)) &&
 	    ctnetlink_dump_mark(skb, ct) < 0)
 		goto nla_put_failure;

Probably better to just drop the event bit test?

Quoted 2 lines

if (ctnetlink_dump_mark(skb, ct) < 0)

	goto nla_put_failure;

Looks good to me, but 1feeae071507 also changes behaviour in another
way: if ct->mark is reset to zero (being non-zero before), the event will not show mark=0 which is probably relevant to userspace. It is a strange corner case though.

Maybe this?

if (ctnetlink_dump_mark(skb, ct, events & (1 << IPCT_MARK)))
goto nla_put_failure;

then:

static int ctnetlink_dump_mark(struct sk_buff *skb, const struct nf_conn *ct, bool dump)

{
        u32 mark = READ_ONCE(ct->mark);

        if (!mark && !dump)
                return 0;

then in __ctnetlink_glue_build() and ctnetlink_dump_info():

        ctnetlink_dump_mark(..., true)

It seems 1feeae071507 also changed conntrack -L, before my update, mark=0 was included in the listing.

Probably a good chance to fix these subtle changes.

maintainer
#3 lore raw
Quoted 27 lines · Pablo Neira Ayuso
Quoted 26 lines · Florian Westphal
Quoted 15 lines · Ivan Delalande

I assume that change was unintentional, we have userspace code that needs the mark while listening for events like REPLY, DESTROY, etc.

Fixes 1feeae071507 ("netfilter: ctnetlink: fix compilation warning after data race fixes in ct mark")
---
 net/netfilter/nf_conntrack_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +0 -0
index c11dff91d52d..194822f8f1ee 100644

net/netfilter/nf_conntrack_netlink.c ctnetlink_conntrack_event(unsigned int events, const struct nf_ct_event *item) · line 836

Quoted 7 lines
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -831,7 +831,7 @@ ctnetlink_conntrack_event(unsigned int events, const struct nf_ct_event *item)
 	}
 
 #ifdef CONFIG_NF_CONNTRACK_MARK
-	if (events & (1 << IPCT_MARK) &&
+	if ((events & (1 << IPCT_MARK) || READ_ONCE(ct->mark)) &&
 	    ctnetlink_dump_mark(skb, ct) < 0)
 		goto nla_put_failure;

Probably better to just drop the event bit test?

Quoted 7 lines
Quoted 2 lines

if (ctnetlink_dump_mark(skb, ct) < 0)

	goto nla_put_failure;

Looks good to me, but 1feeae071507 also changes behaviour in another
way: if ct->mark is reset to zero (being non-zero before), the event will not show mark=0 which is probably relevant to userspace. It is a strange corner case though.

Oh, right.

Quoted 5 lines

Maybe this?

if (ctnetlink_dump_mark(skb, ct, events & (1 << IPCT_MARK)))
goto nla_put_failure;

Quoted 8 lines

then:

static int ctnetlink_dump_mark(struct sk_buff *skb, const struct nf_conn *ct, bool dump)

{
        u32 mark = READ_ONCE(ct->mark);

        if (!mark && !dump)
                return 0;

LGTM, Ivan, can you submit a v2 with Pablos suggested change?

Thanks!