Skip to contentSkip to conversation

net: fix possible store tearing in neigh_periodic_work()

PATCH Applied Eric Dumazet 4 participants 4 messages Sep 21, 2023 – Oct 1, 2023

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

PATCH 1/1 net: fix possible store tearing in neigh_periodic_work()

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")
---
 net/core/neighbour.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/neighbour.c +3 -1
index 6b76cd103195374f73786b7bb94fb2f4051a3c73..7212c7e521ef6388f450f3882077e26088bb3644 100644
@@ -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);
Signature · 1 line
2.42.0.459.ge4e396fd5e-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eric Dumazet

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.

Quoted 9 lines

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")
---
 net/core/neighbour.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Eric Dumazet
Quoted 8 lines · Eric Dumazet

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.

Quoted 5 lines

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")
#3 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

Quoted 9 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html