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: NAPI-frags skb can be freed during a blocked write
Date: Thu, 22 Oct 2026 02:06:55 -0700 [thread overview]
Message-ID: <20261022090655.3643698-1-teel4res@gmail.com> (raw)
Hi all,
In the IFF_NAPI|IFF_NAPI_FRAGS write path, tun_napi_alloc_frags()
publishes tfile->napi.skb and skb_copy_datagram_from_iter() copies user
data before the writer enters the RCU section that teardown waits on.
tun_detach_all() does not take napi_mutex; after disabling NAPI and
calling synchronize_net(), tun_napi_del() can free the same skb through
napi_free_frags().
A userfaultfd-blocked write makes this race deterministic:
writer: napi_get_frags() publishes tfile->napi.skb
writer: sleeps in skb_copy_datagram_from_iter()
deleter: tun_net_uninit -> __netif_napi_del_locked
-> napi_free_frags() frees the skb
writer: resumes copying through the stale local skb pointer
Observed on Linux v7.3, commit
08ab31164c55f20c7a2653de3186ae333470e2c1, on three independent KASAN
boots:
BUG: KASAN: slab-use-after-free
Read of size 8 in skb_copy_datagram_from_iter
tun_get_user
tun_chr_write_iter
Freed by:
__netif_napi_del_locked
tun_net_uninit
unregister_netdevice_many_notify
rtnl_dellink
The already-held local skb pointer also reaches kfree_skb_reason() on
the later drop path, making a second free a direct consequence. The
first KASAN report stops the panic_on_warn kernel before that second
report is observed.
Allocation/use must be serialized with tun_napi_del() and device
unregister, rather than relying only on an RCU section entered after
the expensive user copy.
I found no matching upstream fix.
The userfaultfd reproducer and full console logs are available on
request.
This was found with AI-assisted source analysis and fuzzing; the UAF was
reproduced under KASAN.
Thanks,
Cheng Yongkang
reply other threads:[~2026-10-22 9:07 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=20261022090655.3643698-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®