netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] net: sched: fix use-after-free in taprio_change()
@ 2024-08-07 10:39 Dmitry Antipov
  2024-08-07 10:39 ` [PATCH 2/3] net: sched: consistently use rcu_replace_pointer() " Dmitry Antipov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dmitry Antipov @ 2024-08-07 10:39 UTC (permalink / raw)
  To: Vinicius Costa Gomes
  Cc: Jakub Kicinski, Paolo Abeni, netdev, lvc-project, Dmitry Antipov,
	syzbot+b65e0af58423fc8a73aa

In 'taprio_change()', 'admin' pointer may become dangling due to sched
switch / removal caused by 'advance_sched()', and critical section
protected by 'q->current_entry_lock' is too small to prevent from such
a scenario (which causes use-after-free detected by KASAN). Fix this
by prefer 'rcu_replace_pointer()' over 'rcu_assign_pointer()' to update
'admin' immediately before an attempt to schedule freeing.

Fixes: a3d43c0d56f1 ("taprio: Add support adding an admin schedule")
Reported-by: syzbot+b65e0af58423fc8a73aa@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b65e0af58423fc8a73aa
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 net/sched/sch_taprio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index cc2df9f8c14a..59fad74d5ff9 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -1963,7 +1963,8 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,
 
 		taprio_start_sched(sch, start, new_admin);
 
-		rcu_assign_pointer(q->admin_sched, new_admin);
+		admin = rcu_replace_pointer(q->admin_sched, new_admin,
+					    lockdep_rtnl_is_held());
 		if (admin)
 			call_rcu(&admin->rcu, taprio_free_sched_cb);
 
-- 
2.45.2


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

end of thread, other threads:[~2024-08-08 22:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-07 10:39 [PATCH 1/3] net: sched: fix use-after-free in taprio_change() Dmitry Antipov
2024-08-07 10:39 ` [PATCH 2/3] net: sched: consistently use rcu_replace_pointer() " Dmitry Antipov
2024-08-07 10:39 ` [PATCH 3/3] net: sched: use RCU read-side critical section in taprio_dump() Dmitry Antipov
2024-08-08 22:09   ` Vinicius Costa Gomes
2024-08-08  2:33 ` [PATCH 1/3] net: sched: fix use-after-free in taprio_change() Jakub Kicinski

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).