netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v4 1/3] net: sched: fix use-after-free in taprio_change()
@ 2024-09-03 14:07 Dmitry Antipov
  2024-09-03 14:07 ` [PATCH net v4 2/3] net: sched: consistently use rcu_replace_pointer() " Dmitry Antipov
  2024-09-03 14:07 ` [PATCH net v4 3/3] net: sched: use RCU read-side critical section in taprio_dump() Dmitry Antipov
  0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Antipov @ 2024-09-03 14:07 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>
---
v4: adjust subject to target net tree
v3: unchanged since v2
v2: unchanged since v1
---
 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.46.0


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

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-03 14:07 [PATCH net v4 1/3] net: sched: fix use-after-free in taprio_change() Dmitry Antipov
2024-09-03 14:07 ` [PATCH net v4 2/3] net: sched: consistently use rcu_replace_pointer() " Dmitry Antipov
2024-09-04 10:19   ` Simon Horman
2024-09-03 14:07 ` [PATCH net v4 3/3] net: sched: use RCU read-side critical section in taprio_dump() Dmitry Antipov
2024-09-04 10:17   ` Simon Horman

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