Skip to contentSkip to conversation

net: hsr: fix suspicious usage in hsr_node_get_first()

PATCH Superseded Juhee Kang 2 participants 4 messages Feb 10, 2022 – Feb 11, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Juhee Kang

author
#0 lore raw

PATCH v2 1/1 net: hsr: fix suspicious usage in hsr_node_get_first()

Currently, to dereference hlist_node which is result of hlist_first_rcu(), rcu_dereference() is used. But, suspicious RCU warnings occur because the caller doesn't acquire RCU. So it was solved by adding rcu_read_lock().

The kernel test robot reports:

    [   53.750001][ T3597] =============================
    [   53.754849][ T3597] WARNING: suspicious RCU usage
    [   53.759833][ T3597] 5.17.0-rc2-syzkaller-00903-g45230829827b #0 Not tainted
    [   53.766947][ T3597] -----------------------------
    [   53.771840][ T3597] net/hsr/hsr_framereg.c:34 suspicious rcu_dereference_check() usage!
    [   53.780129][ T3597] other info that might help us debug this:
    [   53.790594][ T3597] rcu_scheduler_active = 2, debug_locks = 1
    [   53.798896][ T3597] 2 locks held by syz-executor.0/3597:
Fixes 4acc45db7115 ("net: hsr: use hlist_head instead of list_head for mac addresses")
Reported-by [email protected]

---
v2:
- rebase current net-next tree

 net/hsr/hsr_framereg.c | 3 +++
 1 file changed, 3 insertions(+)
net/hsr/hsr_framereg.c +3 -0
index b3c6ffa1894d..92abdf855327 100644
@@ -31,7 +31,10 @@ struct hsr_node *hsr_node_get_first(struct hlist_head *head)
 {
 	struct hlist_node *first;
 
+	rcu_read_lock();
 	first = rcu_dereference(hlist_first_rcu(head));
+	rcu_read_unlock();
+
 	if (first)
 		return hlist_entry(first, struct hsr_node, mac_list);
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 5 lines · Juhee Kang

Currently, to dereference hlist_node which is result of hlist_first_rcu(), rcu_dereference() is used. But, suspicious RCU warnings occur because the caller doesn't acquire RCU. So it was solved by adding rcu_read_lock().

The kernel test robot reports:

Quoted 8 lines
     [   53.750001][ T3597] =============================
     [   53.754849][ T3597] WARNING: suspicious RCU usage
     [   53.759833][ T3597] 5.17.0-rc2-syzkaller-00903-g45230829827b #0 Not tainted
     [   53.766947][ T3597] -----------------------------
     [   53.771840][ T3597] net/hsr/hsr_framereg.c:34 suspicious rcu_dereference_check() usage!
     [   53.780129][ T3597] other info that might help us debug this:
     [   53.790594][ T3597] rcu_scheduler_active = 2, debug_locks = 1
     [   53.798896][ T3597] 2 locks held by syz-executor.0/3597:

Please include whole stack.

Quoted 17 lines
Fixes 4acc45db7115 ("net: hsr: use hlist_head instead of list_head for mac addresses")
Reported-by [email protected]

---
v2:
- rebase current net-next tree

  net/hsr/hsr_framereg.c | 3 +++
  1 file changed, 3 insertions(+)
net/hsr/hsr_framereg.c +0 -0
index b3c6ffa1894d..92abdf855327 100644

net/hsr/hsr_framereg.c struct hsr_node *hsr_node_get_first(struct hlist_head *head) · line 40

Quoted 10 lines
net/hsr/hsr_framereg.c +3 -0
@@ -31,7 +31,10 @@ struct hsr_node *hsr_node_get_first(struct hlist_head *head)
  {
  	struct hlist_node *first;
 
+	rcu_read_lock();
  	first = rcu_dereference(hlist_first_rcu(head));
+	rcu_read_unlock();
+
  	if (first)
  		return hlist_entry(first, struct hsr_node, mac_list);
 

This is not fixing anything, just silence the warning.

#2 lore raw
Quoted 41 lines · Eric Dumazet
Quoted 4 lines · Juhee Kang

Currently, to dereference hlist_node which is result of hlist_first_rcu(), rcu_dereference() is used. But, suspicious RCU warnings occur because the caller doesn't acquire RCU. So it was solved by adding rcu_read_lock().

Quoted 9 lines

The kernel test robot reports:
     [   53.750001][ T3597] =============================
     [   53.754849][ T3597] WARNING: suspicious RCU usage
     [   53.759833][ T3597] 5.17.0-rc2-syzkaller-00903-g45230829827b #0 Not tainted [   53.766947][ T3597] -----------------------------
     [   53.771840][ T3597] net/hsr/hsr_framereg.c:34 suspicious rcu_dereference_check() usage! [   53.780129][ T3597] other info that might help us debug this:
     [   53.790594][ T3597] rcu_scheduler_active = 2, debug_locks = 1
     [   53.798896][ T3597] 2 locks held by syz-executor.0/3597:

Please include whole stack.

Quoted 21 lines
Fixes 4acc45db7115 ("net: hsr: use hlist_head instead of list_head for mac addresses")
Reported-by [email protected]

---
v2:
  - rebase current net-next tree

  net/hsr/hsr_framereg.c | 3 +++

  1 file changed, 3 insertions(+)
net/hsr/hsr_framereg.c +0 -0
index b3c6ffa1894d..92abdf855327 100644
@@ -31,7 +31,10 @@ struct hsr_node *hsr_node_get_first(struct 
 hlist_head *head)
   {
       struct hlist_node *first;
   +    rcu_read_lock();
Quoted 8 lines

net/hsr/hsr_framereg.c struct hsr_node *hsr_node_get_first(struct hlist_head *head) · line 39

Quoted 5 lines
net/hsr/hsr_framereg.c +2 -0
       first = rcu_dereference(hlist_first_rcu(head));
+    rcu_read_unlock();
+
       if (first)
           return hlist_entry(first, struct hsr_node, mac_list);

This is not fixing anything, just silence the warning.

I suggest replacing rcu_dereference() by rcu_dereference_rtnl()

author
#3 lore raw
Quoted 60 lines · Eric Dumazet
Quoted 46 lines · Eric Dumazet
Quoted 7 lines · Juhee Kang

Currently, to dereference hlist_node which is result of hlist_first_rcu(),
rcu_dereference() is used. But, suspicious RCU warnings occur because the caller doesn't acquire RCU. So it was solved by adding rcu_read_lock().

The kernel test robot reports:

Quoted 10 lines
     [   53.750001][ T3597] =============================
     [   53.754849][ T3597] WARNING: suspicious RCU usage
     [   53.759833][ T3597] 5.17.0-rc2-syzkaller-00903-g45230829827b
#0 Not tainted
     [   53.766947][ T3597] -----------------------------
     [   53.771840][ T3597] net/hsr/hsr_framereg.c:34 suspicious
rcu_dereference_check() usage!
     [   53.780129][ T3597] other info that might help us debug this:
     [   53.790594][ T3597] rcu_scheduler_active = 2, debug_locks = 1
     [   53.798896][ T3597] 2 locks held by syz-executor.0/3597:

Please include whole stack.

Quoted 22 lines
Fixes 4acc45db7115 ("net: hsr: use hlist_head instead of list_head

for mac addresses")

---
v2:
- rebase current net-next tree

  net/hsr/hsr_framereg.c | 3 +++
  1 file changed, 3 insertions(+)
net/hsr/hsr_framereg.c +0 -0
index b3c6ffa1894d..92abdf855327 100644
@@ -31,7 +31,10 @@ struct hsr_node *hsr_node_get_first(struct
 hlist_head *head)
  {
      struct hlist_node *first;
  +    rcu_read_lock();
Quoted 8 lines

net/hsr/hsr_framereg.c struct hsr_node *hsr_node_get_first(struct hlist_head *head) · line 39

Quoted 5 lines
net/hsr/hsr_framereg.c +2 -0
      first = rcu_dereference(hlist_first_rcu(head));
+    rcu_read_unlock();
+
      if (first)
          return hlist_entry(first, struct hsr_node, mac_list);

This is not fixing anything, just silence the warning.

Quoted 4 lines

I suggest replacing rcu_dereference() by rcu_dereference_rtnl()

Hi Eric,
Thank you for your review!

I will send a v3 patch that applies to your opinion after some tests.

Thank you so much for catching it!

Signature · 2 lines
Best regards,
Juhee Kang