Netdev List
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: pabeni@redhat.com
Cc: netdev@vger.kernel.org, dcaratti@redhat.com, shuali@redhat.com
Subject: Re: [PATCH net] net/sched: fix race between deactivation and dequeue for NOLOCK qdisc
Date: Sun, 15 Sep 2019 19:37:04 +0100 (WEST)	[thread overview]
Message-ID: <20190915.193704.1404390645611004194.davem@davemloft.net> (raw)
In-Reply-To: <80e0c9577218090cada29e4adc9ec116f591cb6f.1568113414.git.pabeni@redhat.com>

From: Paolo Abeni <pabeni@redhat.com>
Date: Thu, 12 Sep 2019 12:02:42 +0200

> The test implemented by some_qdisc_is_busy() is somewhat loosy for
> NOLOCK qdisc, as we may hit the following scenario:
> 
> CPU1						CPU2
> // in net_tx_action()
> clear_bit(__QDISC_STATE_SCHED...);
> 						// in some_qdisc_is_busy()
> 						val = (qdisc_is_running(q) ||
> 						       test_bit(__QDISC_STATE_SCHED,
> 								&q->state));
> 						// here val is 0 but...
> qdisc_run(q)
> // ... CPU1 is going to run the qdisc next
> 
> As a conseguence qdisc_run() in net_tx_action() can race with qdisc_reset()
> in dev_qdisc_reset(). Such race is not possible for !NOLOCK qdisc as
> both the above bit operations are under the root qdisc lock().
> 
> After commit 021a17ed796b ("pfifo_fast: drop unneeded additional lock on dequeue") 
> the race can cause use after free and/or null ptr dereference, but the root 
> cause is likely older.
> 
> This patch addresses the issue explicitly checking for deactivation under
> the seqlock for NOLOCK qdisc, so that the qdisc_run() in the critical
> scenario becomes a no-op.
> 
> Note that the enqueue() op can still execute concurrently with dev_qdisc_reset(),
> but that is safe due to the skb_array() locking, and we can't avoid that
> for NOLOCK qdiscs.
> 
> Fixes: 021a17ed796b ("pfifo_fast: drop unneeded additional lock on dequeue")
> Reported-by: Li Shuang <shuali@redhat.com>
> Reported-and-tested-by: Davide Caratti <dcaratti@redhat.com>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Applied and queued up for -stable, thanks.

      reply	other threads:[~2019-09-15 18:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12 10:02 [PATCH net] net/sched: fix race between deactivation and dequeue for NOLOCK qdisc Paolo Abeni
2019-09-15 18:37 ` David Miller [this message]

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=20190915.193704.1404390645611004194.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=dcaratti@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuali@redhat.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