mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: 徐晗翔 <xuhx@hust.edu.cn>
Cc: tj@kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: kernfs: kernfs_drain()'s fast-path decision reads the active count without acquire ordering -- on weakly-ordered architectures the forced ->release()/unmap can be skipped
Date: Wed, 11 Nov 2026 08:41:36 -0500	[thread overview]
Message-ID: <2026111106-blurb-mantra-4b92@gregkh> (raw)
In-Reply-To: <61919bed.2429b.1a1c983aa11.Coremail.xuhx@hust.edu.cn>

On Wed, Nov 11, 2026 at 03:30:11PM +0800, 徐晗翔 wrote:
> kernfs_drain() (fs/kernfs/dir.c:508-551) decides whether it must
> drain open files with the fast-path test "atomic_read(&kn->active)
> == KN_DEACTIVATED_BIAS && !kernfs_should_drain_open_files(kn)" --
> both a plain atomic_read (relaxed) and an unlocked read of
> kn->attr.open / on->nr_mmapped / on->nr_to_release.  The writer side
> (the last active holder) releases correctly -- its writes to
> attr.open/counter happen under the hash lock, followed by the fully
> ordered atomic_dec_return() that wakes the drain waiter
> (dir.c:491-495) -- but on the READER side there is no acquire edge
> on any fast path: the early-return branch (:522-524), the
> wait_event's non-sleeping first check (:537-538), and the slow-loop
> checks where the waker has not yet touched the queue lock.  The
> phase-1 BIAS add is itself a relaxed atomic_add (:1563), and the
> kernfs_rwsem write lock the remover holds has no intersection with
> the putter.  On a weakly-ordered architecture (arm64, powerpc,
> riscv; x86-TSO is immune because plain load-load does not reorder),
> the remover can therefore observe "active drained" WITHOUT observing
> the racing opener's attr.open/nr_to_release/nr_mmapped updates, skip
> kernfs_drain_open_files() entirely, and leave the mandatory
> ->release() and unmap_mapping_range() to be deferred to the last fd
> close.  Consequences under current semantics: no memory corruption
> (of->kn/inode stay pinned through the dentry chain; the close path
> performs the release and decrements then, and the accounting WARN
> never fires) -- the observable effects are a delayed
> cgroup_file_release()/put_cgroup_ns() (a cgroup-namespace reference
> pinned for the lifetime of a leaked-open fd) and a skipped
> unmap_mapping_range() (mmap'ed vmas survive until their next fault
> takes the kernfs fault path and SIGBUSes, safely).  I verified the
> RACE itself dynamically on a stock Linux 7.3 KCSAN kernel: a
> cgroup2-slot hammer (attached) produced 17 captures of exactly the
> target race pair -- kernfs_fop_release (the nr_to_release--
> writer, inlined in the close path) vs kernfs_should_drain_open_files
> (read), with the reader stack at kernfs_drain+0xba, which I mapped
> back to dir.c:522-524 (the early-return decision) via objdump (the
> cmp $0x80000001 / KN_DEACTIVATED_BIAS immediate).  The consequence
> itself needs a weakly-ordered machine plus a microsecond window, so
> I did not and could not trigger it on x86 -- the report is therefore
> a memory-ordering fix with (a) the race pair proven to occur as a
> matter of course on x86, (b) an LKMM litmus showing the outcome is
> Allowed on linux-kernel.cat and Never on x86-TSO (available; please
> run it), and (c) a one-line fix that closes all three fast paths.

<snip>

This is a wall of LLM text that isn't useful to anyone, sorry.

Please just submit normal patches, as our documentation asks for.

thanks,

greg k-h

      reply	other threads:[~2026-11-11 13:41 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 12:35 usb: devio: usbdev_release() has no barrier against an in-flight async_completed() callback (use-after-free window on struct usb_dev_state)gregkh@linuxfoundation.org 徐晗翔
2026-10-27 14:12 ` Greg KH
2026-11-03 11:21   ` mm/slub: has_pcs_used() reads remote per-CPU sheaf state from flush_all_cpus_locked() without synchronization (data race; KCSAN blind spot: slub.o is uninstrumented) 徐晗翔
2026-11-04  9:41     ` Qing Wang
2026-11-04 10:07       ` Qing Wang
2026-11-03 11:30   ` futex/hrtimer: hrtimer_sleeper::task is read unsynchronized in 16 places on v7.3 -- the accessor series that fixes this is not in 7.3; please make sure it reaches the affected trees (backport nudge + stock-kernel KCSAN evidence) 徐晗翔
2026-11-03 11:48   ` cgroup: fork vs cgroup.procs write race in favordynmods mode -- v7.3 is affected; please make sure bf6fbf46b5ff reaches the stable trees (repro incl. uninstrumented natural hit) 徐晗翔
2026-11-03 14:51     ` Sasha Levin
2026-11-03 11:57   ` net: rtnetlink: rtnl_link_unregister() vs in-flight RTM_GETLINK dump readers -- v7.3 lacks the synchronize_rcu() fix (Fixes: 6b57ff21a310 family); A/B reproduction on stock 7.3 徐晗翔
2026-11-03 15:49     ` Eric Dumazet
2026-11-04 15:03     ` Sasha Levin
2026-11-03 12:07   ` wifi: wilc1000: SDIO/SPI remove destroys the srcu_struct before wiphy_unregister() -- late cfg80211 callbacks write through dangling srcu state (unfixed upstream; controlled + natural Oops) 徐晗翔
2026-11-03 12:10   ` gpio: gpiolib: final put of the gpio_device happens inside the SRCU read critical section on the setup-failure path -- deterministic use-after-free read at guard release (unfixed upstream) 徐晗翔
2026-11-05  8:52     ` Linus Walleij
2026-11-04 12:54   ` soc: qcom: pmic_glink_altmode: fix use-after-free on unbind (no cancel_work_sync for port work and enable_work) 徐晗翔
2026-11-04 13:04     ` Greg KH
2026-11-04 12:57   ` usb: typec: anx7411: unregister partner/altmodes before stopping the IRQ work -- use-after-free, double unregister, orphan partner on remove 徐晗翔
2026-11-04 13:28     ` Greg KH
2026-11-04 12:58   ` usb: typec: ucsi: deadlock on cros_ec unbind -- connector lock held across cancel_delayed_work_sync vs the mode-selection work's unbounded trylock polling 徐晗翔
2026-11-04 13:00   ` usb: typec: stusb160x/rt1719/hd3ss3220: IRQ thread vs remove -- double unregister / use-after-free on the partner and port 徐晗翔
2026-11-04 13:01   ` usb: typec: ucsi: displayport: data race on dp->header/ vdo_data/vdo_size -- work reads them unlocked while writers hold con->lock (VDM mismatch) 徐晗翔
2026-11-04 13:02   ` usb: typec: class: three lifetime/locking gaps around the mux/switch handles and mode_selection (drvdata UAF after provider unbind; no concurrent protocol for set/put; unlocked state_update vs delete) 徐晗翔
2026-11-10 12:56   ` driver core: uevent: netns teardown frees uevent_sock while a tagged uevent is still being broadcast (UAF) 徐晗翔
2026-11-10 13:00   ` 徐晗翔
2026-11-10 18:48     ` Greg KH
2026-11-10 13:05   ` ACPI: CPPC: per-CPU cpc_desc is freed on processor unbind without clearing the published pointer, causing UAF in cpufreq accessors 徐晗翔
2026-11-10 13:07   ` ACPI: CPPC: shared PCC subspace data can be freed while another CPU probes, reads, or tears it down 徐晗翔
2026-11-10 14:47     ` Christian Loehle
2026-11-10 13:11   ` ACPI: ACPICA: Reset can delete an event semaphore while another thread is blocked in Wait 徐晗翔
2026-11-10 13:14   ` power: supply: bq25890: pump-express work can call power_supply_changed after the psy is unregistered 徐晗翔
2026-11-10 13:17   ` power: supply: core: get/set property callbacks can run after unregister and read freed driver data 徐晗翔
2026-11-10 13:18   ` power: supply: core: system-battery enumeration can return an unregistered battery 徐晗翔
2026-11-10 13:21   ` power: supply: core: changed work can run after unregister and use freed LED triggers 徐晗翔
2026-11-10 13:23   ` power: supply: bq24190: IRQ handler can call power_supply_changed after the psy is unregistered 徐晗翔
2026-11-10 13:34   ` 徐晗翔
2026-11-11  7:17   ` genirq: NMI dispatch reads struct irqaction with no quiescence -- use-after-free across free_nmi()'s kfree (x86 verification on the arch-independent core path) 徐晗翔
2026-11-11  7:26   ` genirq: NMI API lacks the request_mutex / dev_id matching / idempotency semantics that free_irq() has -- double free_nmi releases chip PM and module references twice (verified) 徐晗翔
2026-11-11  7:30   ` kernfs: kernfs_drain()'s fast-path decision reads the active count without acquire ordering -- on weakly-ordered architectures the forced ->release()/unmap can be skipped 徐晗翔
2026-11-11 13:41     ` Greg KH [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=2026111106-blurb-mantra-4b92@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=driver-core@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=xuhx@hust.edu.cn \
    /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®