netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netfilter: mark racy access on ext->gen_id
@ 2024-04-23 11:50 linke li
  2024-04-23 12:03 ` Florian Westphal
  2024-04-25  9:36 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 6+ messages in thread
From: linke li @ 2024-04-23 11:50 UTC (permalink / raw)
  Cc: xujianhao01, linke li, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netfilter-devel, coreteam, netdev, linux-kernel

In __nf_ct_ext_find(), ext->gen_id can be changed by 
nf_ct_ext_valid_post(), using WRITE_ONCE. Mark data races on ext->gen_id
as benign using READ_ONCE. 

This patch is aimed at reducing the number of benign races reported by
KCSAN in order to focus future debugging effort on harmful races.

Signed-off-by: linke li <lilinke99@qq.com>
---
 net/netfilter/nf_conntrack_extend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_conntrack_extend.c b/net/netfilter/nf_conntrack_extend.c
index dd62cc12e775..7f1a5e5f6646 100644
--- a/net/netfilter/nf_conntrack_extend.c
+++ b/net/netfilter/nf_conntrack_extend.c
@@ -141,7 +141,7 @@ void *__nf_ct_ext_find(const struct nf_ct_ext *ext, u8 id)
 	if (!__nf_ct_ext_exist(ext, id))
 		return NULL;
 
-	if (this_id == 0 || ext->gen_id == gen_id)
+	if (this_id == 0 || READ_ONCE(ext->gen_id) == gen_id)
 		return (void *)ext + ext->offset[id];
 
 	return NULL;
-- 
2.39.3 (Apple Git-146)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] netfilter: mark racy access on ext->gen_id
  2024-04-23 11:50 [PATCH] netfilter: mark racy access on ext->gen_id linke li
@ 2024-04-23 12:03 ` Florian Westphal
  2024-04-24 22:20   ` Pablo Neira Ayuso
  2024-04-25  9:36 ` Pablo Neira Ayuso
  1 sibling, 1 reply; 6+ messages in thread
From: Florian Westphal @ 2024-04-23 12:03 UTC (permalink / raw)
  To: linke li
  Cc: xujianhao01, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netfilter-devel, coreteam, netdev, linux-kernel

linke li <lilinke99@qq.com> wrote:
> In __nf_ct_ext_find(), ext->gen_id can be changed by 
> nf_ct_ext_valid_post(), using WRITE_ONCE. Mark data races on ext->gen_id
> as benign using READ_ONCE. 
> 
> This patch is aimed at reducing the number of benign races reported by
> KCSAN in order to focus future debugging effort on harmful races.

Acked-by: Florian Westphal <fw@strlen.de>

Should proably go to nf tree.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] netfilter: mark racy access on ext->gen_id
  2024-04-23 12:03 ` Florian Westphal
@ 2024-04-24 22:20   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2024-04-24 22:20 UTC (permalink / raw)
  To: Florian Westphal
  Cc: linke li, xujianhao01, Jozsef Kadlecsik, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netfilter-devel,
	coreteam, netdev, linux-kernel

On Tue, Apr 23, 2024 at 02:03:09PM +0200, Florian Westphal wrote:
> linke li <lilinke99@qq.com> wrote:
> > In __nf_ct_ext_find(), ext->gen_id can be changed by 
> > nf_ct_ext_valid_post(), using WRITE_ONCE. Mark data races on ext->gen_id
> > as benign using READ_ONCE. 
> > 
> > This patch is aimed at reducing the number of benign races reported by
> > KCSAN in order to focus future debugging effort on harmful races.
> 
> Acked-by: Florian Westphal <fw@strlen.de>
> 
> Should proably go to nf tree.

Can I get a Fixes: tag for this one?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] netfilter: mark racy access on ext->gen_id
  2024-04-23 11:50 [PATCH] netfilter: mark racy access on ext->gen_id linke li
  2024-04-23 12:03 ` Florian Westphal
@ 2024-04-25  9:36 ` Pablo Neira Ayuso
  2024-04-25  9:54   ` Eric Dumazet
  1 sibling, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2024-04-25  9:36 UTC (permalink / raw)
  To: linke li
  Cc: xujianhao01, Jozsef Kadlecsik, Florian Westphal, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netfilter-devel,
	coreteam, netdev, linux-kernel

On Tue, Apr 23, 2024 at 07:50:22PM +0800, linke li wrote:
> In __nf_ct_ext_find(), ext->gen_id can be changed by 
> nf_ct_ext_valid_post(), using WRITE_ONCE. Mark data races on ext->gen_id
> as benign using READ_ONCE. 
> 
> This patch is aimed at reducing the number of benign races reported by
> KCSAN in order to focus future debugging effort on harmful races.

There are a more uses ext->gen_id in the code, my understanding this
patch is just a stub.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] netfilter: mark racy access on ext->gen_id
  2024-04-25  9:36 ` Pablo Neira Ayuso
@ 2024-04-25  9:54   ` Eric Dumazet
  2024-04-25 10:04     ` Florian Westphal
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2024-04-25  9:54 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: linke li, xujianhao01, Jozsef Kadlecsik, Florian Westphal,
	David S. Miller, Jakub Kicinski, Paolo Abeni, netfilter-devel,
	coreteam, netdev, linux-kernel

On Thu, Apr 25, 2024 at 11:36 AM Pablo Neira Ayuso <pablo@netfilter.org> wrote:
>
> On Tue, Apr 23, 2024 at 07:50:22PM +0800, linke li wrote:
> > In __nf_ct_ext_find(), ext->gen_id can be changed by
> > nf_ct_ext_valid_post(), using WRITE_ONCE. Mark data races on ext->gen_id
> > as benign using READ_ONCE.
> >
> > This patch is aimed at reducing the number of benign races reported by
> > KCSAN in order to focus future debugging effort on harmful races.
>
> There are a more uses ext->gen_id in the code, my understanding this
> patch is just a stub.

Anyway, ext->gen_id was already read and stored in @this_id

I would probably avoid reading it a second time.

diff --git a/net/netfilter/nf_conntrack_extend.c
b/net/netfilter/nf_conntrack_extend.c
index dd62cc12e7750734fec9be8a90fd0defcbc815e0..747797b20bc7417a2b7270d84f62d24991a4b982
100644
--- a/net/netfilter/nf_conntrack_extend.c
+++ b/net/netfilter/nf_conntrack_extend.c
@@ -141,7 +141,7 @@ void *__nf_ct_ext_find(const struct nf_ct_ext *ext, u8 id)
        if (!__nf_ct_ext_exist(ext, id))
                return NULL;

-       if (this_id == 0 || ext->gen_id == gen_id)
+       if (this_id == 0 || this_id == gen_id)
                return (void *)ext + ext->offset[id];

        return NULL;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] netfilter: mark racy access on ext->gen_id
  2024-04-25  9:54   ` Eric Dumazet
@ 2024-04-25 10:04     ` Florian Westphal
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2024-04-25 10:04 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Pablo Neira Ayuso, linke li, xujianhao01, Jozsef Kadlecsik,
	Florian Westphal, David S. Miller, Jakub Kicinski, Paolo Abeni,
	netfilter-devel, coreteam, netdev, linux-kernel

Eric Dumazet <edumazet@google.com> wrote:
> > There are a more uses ext->gen_id in the code, my understanding this
> > patch is just a stub.
> 
> Anyway, ext->gen_id was already read and stored in @this_id
> 
> I would probably avoid reading it a second time.
 
> diff --git a/net/netfilter/nf_conntrack_extend.c
> b/net/netfilter/nf_conntrack_extend.c
> index dd62cc12e7750734fec9be8a90fd0defcbc815e0..747797b20bc7417a2b7270d84f62d24991a4b982
> 100644
> --- a/net/netfilter/nf_conntrack_extend.c
> +++ b/net/netfilter/nf_conntrack_extend.c
> @@ -141,7 +141,7 @@ void *__nf_ct_ext_find(const struct nf_ct_ext *ext, u8 id)
>         if (!__nf_ct_ext_exist(ext, id))
>                 return NULL;
> 
> -       if (this_id == 0 || ext->gen_id == gen_id)
> +       if (this_id == 0 || this_id == gen_id)
>                 return (void *)ext + ext->offset[id];
> 
>         return NULL;
> 

Right, that should work, unconfirmed entries are not exposed to other
cpus and confirmed entries get their id set to 0.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-25 10:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23 11:50 [PATCH] netfilter: mark racy access on ext->gen_id linke li
2024-04-23 12:03 ` Florian Westphal
2024-04-24 22:20   ` Pablo Neira Ayuso
2024-04-25  9:36 ` Pablo Neira Ayuso
2024-04-25  9:54   ` Eric Dumazet
2024-04-25 10:04     ` Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).