public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: Hyunwoo Kim <imv4bel@gmail.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>,
	vinicius.gomes@intel.com, jhs@mojatatu.com, jiri@resnulli.us,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
	v4bel@theori.io
Subject: Re: [PATCH v2] net/sched: fix use-after-free in taprio_dev_notifier
Date: Fri, 13 Jun 2025 23:52:06 +0300	[thread overview]
Message-ID: <20250613205206.fssf4bi4wjgyy53x@skbuf> (raw)
In-Reply-To: <aEucrIuj7yxTX58y@v4bel-B760M-AORUS-ELITE-AX>

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.

  reply	other threads:[~2025-06-13 20:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-06-14  0:46       ` Hyunwoo Kim
2025-06-13 20:33   ` Vladimir Oltean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250613205206.fssf4bi4wjgyy53x@skbuf \
    --to=vladimir.oltean@nxp.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=imv4bel@gmail.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=v4bel@theori.io \
    --cc=vinicius.gomes@intel.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox