mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cheng Yongkang <teel4res@gmail.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	Jason Wang <jasowangio@gmail.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [BUG] net: tun: flow update can repopulate a purged detached queue
Date: Thu, 22 Oct 2026 02:13:58 -0700	[thread overview]
Message-ID: <20261022091358.3649925-1-teel4res@gmail.com> (raw)

Hi all,

tun_get_user() checks !tfile->detached before entering its receive RCU
section, but calls tun_flow_update() after leaving that section.  Queue
detach can complete between those points.  Detach's synchronize_net()
does not cover the hash computation made before the RCU section or the
flow insertion made after RCU unlock.

The late write therefore installs a flow entry with the detached
queue's queue_index after detach has already purged flow entries for
that queue.  A matching TX can then steer to a detached or out-of-range
queue.

Observed on Linux v7.3, commit
08ab31164c55f20c7a2653de3186ae333470e2c1.  A two-stage GDB condition
observed both:

  detach completed its flow purge
  tfile->detached == tun
  tun_flow_update() still ran
  queue_index=2, numqueues=2

The later TX produced:

  tun0 selects TX queue 2, but real number of TX queues is 2

The condition was hit in two independent runs and is distinct from the
purge off-by-one in candidate BR-018/027: even a complete purge can be
followed by this stale insertion.

The detached state and the flow update need to be covered by the same
ordering rule.  One option is to perform the flow lookup/update while
the receive RCU protection still guarantees that detach cannot pass its
synchronize_net(), then avoid using a detached tfile after unlock.

I found no matching upstream fix.

The reproducer, GDB script, and full logs are available on request.

This was found with a multi-agent workflow; the TOCTOU
was observed under QEMU/KVM.

Thanks,
Cheng Yongkang

                 reply	other threads:[~2026-10-22  9:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261022091358.3649925-1-teel4res@gmail.com \
    --to=teel4res@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jasowangio@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemdebruijn.kernel@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

all inboxes | Powered by JetHome®