[PATCH net] net: fix possible store tearing in neigh_periodic_work()

Subsystems: networking [general], the rest

STALE1114d

4 messages, 4 authors, 2023-10-01 · open the first message on its own page

[PATCH net] net: fix possible store tearing in neigh_periodic_work()

From: Eric Dumazet <hidden>
Date: 2023-09-21 18:35:18

While looking at a related syzbot report involving neigh_periodic_work(),
I found that I forgot to add an annotation when deleting an
RCU protected item from a list.

Readers use rcu_deference(*np), we need to use either
rcu_assign_pointer() or WRITE_ONCE() on writer side
to prevent store tearing.

I use rcu_assign_pointer() to have lockdep support,
this was the choice made in neigh_flush_dev().

Fixes: 767e97e1e0db ("neigh: RCU conversion of struct neighbour")
Signed-off-by: Eric Dumazet <redacted>
---
 net/core/neighbour.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 6b76cd103195374f73786b7bb94fb2f4051a3c73..7212c7e521ef6388f450f3882077e26088bb3644 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -988,7 +988,9 @@ static void neigh_periodic_work(struct work_struct *work)
 			    (state == NUD_FAILED ||
 			     !time_in_range_open(jiffies, n->used,
 						 n->used + NEIGH_VAR(n->parms, GC_STALETIME)))) {
-				*np = n->next;
+				rcu_assign_pointer(*np,
+					rcu_dereference_protected(n->next,
+						lockdep_is_held(&tbl->lock)));
 				neigh_mark_dead(n);
 				write_unlock(&n->lock);
 				neigh_cleanup_and_release(n);
-- 
2.42.0.459.ge4e396fd5e-goog

Re: [PATCH net] net: fix possible store tearing in neigh_periodic_work()

From: David Ahern <dsahern@kernel.org>
Date: 2023-09-21 19:33:02

On 9/21/23 2:46 AM, Eric Dumazet wrote:
While looking at a related syzbot report involving neigh_periodic_work(),
I found that I forgot to add an annotation when deleting an
RCU protected item from a list.

Readers use rcu_deference(*np), we need to use either
rcu_assign_pointer() or WRITE_ONCE() on writer side
to prevent store tearing.

I use rcu_assign_pointer() to have lockdep support,
this was the choice made in neigh_flush_dev().

Fixes: 767e97e1e0db ("neigh: RCU conversion of struct neighbour")
Signed-off-by: Eric Dumazet <redacted>
---
 net/core/neighbour.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Reviewed-by: David Ahern <dsahern@kernel.org>

Re: [PATCH net] net: fix possible store tearing in neigh_periodic_work()

From: Simon Horman <horms@kernel.org>
Date: 2023-09-22 09:49:46

On Thu, Sep 21, 2023 at 08:46:26AM +0000, Eric Dumazet wrote:
While looking at a related syzbot report involving neigh_periodic_work(),
I found that I forgot to add an annotation when deleting an
RCU protected item from a list.

Readers use rcu_deference(*np), we need to use either
rcu_assign_pointer() or WRITE_ONCE() on writer side
to prevent store tearing.

I use rcu_assign_pointer() to have lockdep support,
this was the choice made in neigh_flush_dev().

Fixes: 767e97e1e0db ("neigh: RCU conversion of struct neighbour")
Signed-off-by: Eric Dumazet <redacted>
Reviewed-by: Simon Horman <horms@kernel.org>

Re: [PATCH net] net: fix possible store tearing in neigh_periodic_work()

From: patchwork-bot+netdevbpf@kernel.org
Date: 2023-10-01 15:30:23

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller [off-list ref]:

On Thu, 21 Sep 2023 08:46:26 +0000 you wrote:
While looking at a related syzbot report involving neigh_periodic_work(),
I found that I forgot to add an annotation when deleting an
RCU protected item from a list.

Readers use rcu_deference(*np), we need to use either
rcu_assign_pointer() or WRITE_ONCE() on writer side
to prevent store tearing.

[...]
Here is the summary with links:
  - [net] net: fix possible store tearing in neigh_periodic_work()
    https://git.kernel.org/netdev/net/c/25563b581ba3

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help