* [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier
@ 2025-06-12 11:16 Hyunwoo Kim
2025-06-12 11:46 ` Eric Dumazet
2025-06-12 20:23 ` Cong Wang
0 siblings, 2 replies; 7+ messages in thread
From: Hyunwoo Kim @ 2025-06-12 11:16 UTC (permalink / raw)
To: vinicius.gomes, jhs, xiyou.wangcong, jiri, davem, edumazet, kuba,
pabeni, horms, vladimir.oltean
Cc: netdev, imv4bel, v4bel
Since taprio’s taprio_dev_notifier() isn’t protected by an
RCU read-side critical section, a race with advance_sched()
can lead to a use-after-free.
Adding rcu_read_lock() inside taprio_dev_notifier() prevents this.
Fixes: fed87cc6718a ("net/sched: taprio: automatically calculate queueMaxSDU based on TC gate durations")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
---
Changes in v2:
- Add the appropriate tags.
- v1: https://lore.kernel.org/all/aElUZyKy7x66X3SD@v4bel-B760M-AORUS-ELITE-AX/
---
net/sched/sch_taprio.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index 14021b812329..bd2b02d1dc63 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -1320,6 +1320,7 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event,
if (event != NETDEV_UP && event != NETDEV_CHANGE)
return NOTIFY_DONE;
+ rcu_read_lock();
list_for_each_entry(q, &taprio_list, taprio_list) {
if (dev != qdisc_dev(q->root))
continue;
@@ -1328,16 +1329,17 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event,
stab = rtnl_dereference(q->root->stab);
- oper = rtnl_dereference(q->oper_sched);
+ oper = rcu_dereference(q->oper_sched);
if (oper)
taprio_update_queue_max_sdu(q, oper, stab);
- admin = rtnl_dereference(q->admin_sched);
+ admin = rcu_dereference(q->admin_sched);
if (admin)
taprio_update_queue_max_sdu(q, admin, stab);
break;
}
+ rcu_read_unlock();
return NOTIFY_DONE;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier 2025-06-12 11:16 [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier Hyunwoo Kim @ 2025-06-12 11:46 ` Eric Dumazet 2025-06-12 20:23 ` Cong Wang 1 sibling, 0 replies; 7+ messages in thread From: Eric Dumazet @ 2025-06-12 11:46 UTC (permalink / raw) To: Hyunwoo Kim Cc: vinicius.gomes, jhs, xiyou.wangcong, jiri, davem, kuba, pabeni, horms, vladimir.oltean, netdev, v4bel On Thu, Jun 12, 2025 at 4:17 AM Hyunwoo Kim <imv4bel@gmail.com> wrote: > > Since taprio’s taprio_dev_notifier() isn’t protected by an > RCU read-side critical section, a race with advance_sched() > can lead to a use-after-free. > > Adding rcu_read_lock() inside taprio_dev_notifier() prevents this. > > Fixes: fed87cc6718a ("net/sched: taprio: automatically calculate queueMaxSDU based on TC gate durations") > Cc: stable@vger.kernel.org > Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com> Reviewed-by: Eric Dumazet <edumazet@google.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier 2025-06-12 11:16 [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier Hyunwoo Kim 2025-06-12 11:46 ` Eric Dumazet @ 2025-06-12 20:23 ` Cong Wang 2025-06-13 3:36 ` Hyunwoo Kim 2025-06-13 20:33 ` Vladimir Oltean 1 sibling, 2 replies; 7+ messages in thread From: Cong Wang @ 2025-06-12 20:23 UTC (permalink / raw) To: Hyunwoo Kim Cc: vinicius.gomes, jhs, jiri, davem, edumazet, kuba, pabeni, horms, vladimir.oltean, netdev, v4bel On Thu, Jun 12, 2025 at 07:16:55AM -0400, Hyunwoo Kim wrote: > diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c > index 14021b812329..bd2b02d1dc63 100644 > --- a/net/sched/sch_taprio.c > +++ b/net/sched/sch_taprio.c > @@ -1320,6 +1320,7 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > if (event != NETDEV_UP && event != NETDEV_CHANGE) > return NOTIFY_DONE; > > + rcu_read_lock(); > list_for_each_entry(q, &taprio_list, taprio_list) { > if (dev != qdisc_dev(q->root)) > continue; > @@ -1328,16 +1329,17 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, There is a taprio_set_picos_per_byte() call here, it calls __ethtool_get_link_ksettings() which could be blocking. For instance, gve_get_link_ksettings() calls gve_adminq_report_link_speed() which is a blocking function. So I am afraid we can't enforce an atomic context here. Sorry. Cong ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier 2025-06-12 20:23 ` Cong Wang @ 2025-06-13 3:36 ` Hyunwoo Kim 2025-06-13 20:52 ` Vladimir Oltean 2025-06-13 20:33 ` Vladimir Oltean 1 sibling, 1 reply; 7+ messages in thread From: Hyunwoo Kim @ 2025-06-13 3:36 UTC (permalink / raw) To: Cong Wang Cc: vinicius.gomes, jhs, jiri, davem, edumazet, kuba, pabeni, horms, vladimir.oltean, netdev, v4bel, imv4bel On Thu, Jun 12, 2025 at 01:23:38PM -0700, Cong Wang wrote: > On Thu, Jun 12, 2025 at 07:16:55AM -0400, Hyunwoo Kim wrote: > > diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c > > index 14021b812329..bd2b02d1dc63 100644 > > --- a/net/sched/sch_taprio.c > > +++ b/net/sched/sch_taprio.c > > @@ -1320,6 +1320,7 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > if (event != NETDEV_UP && event != NETDEV_CHANGE) > > return NOTIFY_DONE; > > > > + rcu_read_lock(); > > list_for_each_entry(q, &taprio_list, taprio_list) { > > if (dev != qdisc_dev(q->root)) > > continue; > > @@ -1328,16 +1329,17 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > There is a taprio_set_picos_per_byte() call here, it calls > __ethtool_get_link_ksettings() which could be blocking. > > For instance, gve_get_link_ksettings() calls > gve_adminq_report_link_speed() which is a blocking function. > > So I am afraid we can't enforce an atomic context here. In that case, how about moving the lock as follows so that taprio_set_picos_per_byte() isn’t included within it? ``` diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c index 14021b812329..2b14c81a87e5 100644 --- a/net/sched/sch_taprio.c +++ b/net/sched/sch_taprio.c @@ -1328,13 +1328,15 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, stab = rtnl_dereference(q->root->stab); - oper = rtnl_dereference(q->oper_sched); + rcu_read_lock(); + oper = rcu_dereference(q->oper_sched); if (oper) taprio_update_queue_max_sdu(q, oper, stab); - admin = rtnl_dereference(q->admin_sched); + admin = rcu_dereference(q->admin_sched); if (admin) taprio_update_queue_max_sdu(q, admin, stab); + rcu_read_unlock(); break; } ``` This change still prevents the race condition with advance_sched(). > > Sorry. > Cong ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier 2025-06-13 3:36 ` Hyunwoo Kim @ 2025-06-13 20:52 ` Vladimir Oltean 2025-06-14 0:46 ` Hyunwoo Kim 0 siblings, 1 reply; 7+ messages in thread From: Vladimir Oltean @ 2025-06-13 20:52 UTC (permalink / raw) To: Hyunwoo Kim Cc: Cong Wang, vinicius.gomes, jhs, jiri, davem, edumazet, kuba, pabeni, horms, netdev, v4bel On Thu, Jun 12, 2025 at 11:36:12PM -0400, Hyunwoo Kim wrote: > On Thu, Jun 12, 2025 at 01:23:38PM -0700, Cong Wang wrote: > > On Thu, Jun 12, 2025 at 07:16:55AM -0400, Hyunwoo Kim wrote: > > > diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c > > > index 14021b812329..bd2b02d1dc63 100644 > > > --- a/net/sched/sch_taprio.c > > > +++ b/net/sched/sch_taprio.c > > > @@ -1320,6 +1320,7 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > > if (event != NETDEV_UP && event != NETDEV_CHANGE) > > > return NOTIFY_DONE; > > > > > > + rcu_read_lock(); > > > list_for_each_entry(q, &taprio_list, taprio_list) { > > > if (dev != qdisc_dev(q->root)) > > > continue; > > > @@ -1328,16 +1329,17 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > > > There is a taprio_set_picos_per_byte() call here, it calls > > __ethtool_get_link_ksettings() which could be blocking. > > > > For instance, gve_get_link_ksettings() calls > > gve_adminq_report_link_speed() which is a blocking function. > > > > So I am afraid we can't enforce an atomic context here. > > In that case, how about moving the lock as follows so that > taprio_set_picos_per_byte() isn’t included within it? > > ``` > diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c > index 14021b812329..2b14c81a87e5 100644 > --- a/net/sched/sch_taprio.c > +++ b/net/sched/sch_taprio.c > @@ -1328,13 +1328,15 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > stab = rtnl_dereference(q->root->stab); > > - oper = rtnl_dereference(q->oper_sched); > + rcu_read_lock(); > + oper = rcu_dereference(q->oper_sched); > if (oper) > taprio_update_queue_max_sdu(q, oper, stab); > > - admin = rtnl_dereference(q->admin_sched); > + admin = rcu_dereference(q->admin_sched); > if (admin) > taprio_update_queue_max_sdu(q, admin, stab); > + rcu_read_unlock(); > > break; > } > ``` > > This change still prevents the race condition with advance_sched(). This should work. And I'm sorry for the bug introduced here, and elsewhere, by assuming rtnl_dereference() will be fine. I mostly use taprio with offload, where switch_schedules() runs in process context with rtnl_lock() held, not the software emulation that changes the schedules from the advance_sched() hrtimer. Somehow the different locking requirements for the 2 cases eluded me. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier 2025-06-13 20:52 ` Vladimir Oltean @ 2025-06-14 0:46 ` Hyunwoo Kim 0 siblings, 0 replies; 7+ messages in thread From: Hyunwoo Kim @ 2025-06-14 0:46 UTC (permalink / raw) To: Vladimir Oltean Cc: Cong Wang, vinicius.gomes, jhs, jiri, davem, edumazet, kuba, pabeni, horms, netdev, v4bel, imv4bel On Fri, Jun 13, 2025 at 11:52:06PM +0300, Vladimir Oltean wrote: > On Thu, Jun 12, 2025 at 11:36:12PM -0400, Hyunwoo Kim wrote: > > On Thu, Jun 12, 2025 at 01:23:38PM -0700, Cong Wang wrote: > > > On Thu, Jun 12, 2025 at 07:16:55AM -0400, Hyunwoo Kim wrote: > > > > diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c > > > > index 14021b812329..bd2b02d1dc63 100644 > > > > --- a/net/sched/sch_taprio.c > > > > +++ b/net/sched/sch_taprio.c > > > > @@ -1320,6 +1320,7 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > > > if (event != NETDEV_UP && event != NETDEV_CHANGE) > > > > return NOTIFY_DONE; > > > > > > > > + rcu_read_lock(); > > > > list_for_each_entry(q, &taprio_list, taprio_list) { > > > > if (dev != qdisc_dev(q->root)) > > > > continue; > > > > @@ -1328,16 +1329,17 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > > > > > There is a taprio_set_picos_per_byte() call here, it calls > > > __ethtool_get_link_ksettings() which could be blocking. > > > > > > For instance, gve_get_link_ksettings() calls > > > gve_adminq_report_link_speed() which is a blocking function. > > > > > > So I am afraid we can't enforce an atomic context here. > > > > In that case, how about moving the lock as follows so that > > taprio_set_picos_per_byte() isn’t included within it? > > > > ``` > > diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c > > index 14021b812329..2b14c81a87e5 100644 > > --- a/net/sched/sch_taprio.c > > +++ b/net/sched/sch_taprio.c > > @@ -1328,13 +1328,15 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > > > stab = rtnl_dereference(q->root->stab); > > > > - oper = rtnl_dereference(q->oper_sched); > > + rcu_read_lock(); > > + oper = rcu_dereference(q->oper_sched); > > if (oper) > > taprio_update_queue_max_sdu(q, oper, stab); > > > > - admin = rtnl_dereference(q->admin_sched); > > + admin = rcu_dereference(q->admin_sched); > > if (admin) > > taprio_update_queue_max_sdu(q, admin, stab); > > + rcu_read_unlock(); > > > > break; > > } > > ``` > > > > This change still prevents the race condition with advance_sched(). > > This should work. OK, I’ll submit the v3 patch. > > And I'm sorry for the bug introduced here, and elsewhere, by assuming > rtnl_dereference() will be fine. > I mostly use taprio with offload, where switch_schedules() runs in > process context with rtnl_lock() held, not the software emulation that > changes the schedules from the advance_sched() hrtimer. Somehow the > different locking requirements for the 2 cases eluded me. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier 2025-06-12 20:23 ` Cong Wang 2025-06-13 3:36 ` Hyunwoo Kim @ 2025-06-13 20:33 ` Vladimir Oltean 1 sibling, 0 replies; 7+ messages in thread From: Vladimir Oltean @ 2025-06-13 20:33 UTC (permalink / raw) To: Cong Wang Cc: Hyunwoo Kim, vinicius.gomes, jhs, jiri, davem, edumazet, kuba, pabeni, horms, netdev, v4bel On Thu, Jun 12, 2025 at 01:23:38PM -0700, Cong Wang wrote: > On Thu, Jun 12, 2025 at 07:16:55AM -0400, Hyunwoo Kim wrote: > > diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c > > index 14021b812329..bd2b02d1dc63 100644 > > --- a/net/sched/sch_taprio.c > > +++ b/net/sched/sch_taprio.c > > @@ -1320,6 +1320,7 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > if (event != NETDEV_UP && event != NETDEV_CHANGE) > > return NOTIFY_DONE; > > > > + rcu_read_lock(); > > list_for_each_entry(q, &taprio_list, taprio_list) { > > if (dev != qdisc_dev(q->root)) > > continue; > > @@ -1328,16 +1329,17 @@ static int taprio_dev_notifier(struct notifier_block *nb, unsigned long event, > > There is a taprio_set_picos_per_byte() call here, it calls > __ethtool_get_link_ksettings() which could be blocking. > > For instance, gve_get_link_ksettings() calls > gve_adminq_report_link_speed() which is a blocking function. > > So I am afraid we can't enforce an atomic context here. > > Sorry. > Cong Yeah, and phylib's phy_ethtool_ksettings_get() acquires the &phydev->lock mutex, which is sleepable. Agreed that this won't work, good catch. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-06-14 0:46 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-06-12 11:16 [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier Hyunwoo Kim 2025-06-12 11:46 ` Eric Dumazet 2025-06-12 20:23 ` Cong Wang 2025-06-13 3:36 ` Hyunwoo Kim 2025-06-13 20:52 ` Vladimir Oltean 2025-06-14 0:46 ` Hyunwoo Kim 2025-06-13 20:33 ` Vladimir Oltean
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox