From: Chen Pei <cp0613@linux.alibaba.com>
To: dave.jiang@intel.com, alison.schofield@intel.com,
bhelgaas@google.com, rafael@kernel.org, lenb@kernel.org,
guoren@kernel.org, sashiko-reviews@lists.linux.dev
Cc: linux-pci@vger.kernel.org, linux-cxl@vger.kernel.org,
linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ACPI: PCI: Clear driver_data on all error paths in acpi_pci_root_add()
Date: Wed, 15 Jul 2026 21:33:10 +0800 [thread overview]
Message-ID: <20260715133020.3282712-1-cp0613@linux.alibaba.com> (raw)
In-Reply-To: <20260707122549.C01DC1F00A3A@smtp.kernel.org>
Thanks for the review.
> Pre-existing issues:
> - [High] The acpi_pci_root_remove() function frees the acpi_pci_root
> object but fails to clear device->driver_data, leaving a dangling
> pointer.
Agreed. acpi_pci_root_remove() calls kfree(root) without resetting
device->driver_data, which leaves exactly the same dangling pointer
this patch removes from the add() error paths. I'll fix it in v2 by
also clearing device->driver_data in acpi_pci_root_remove(), so the
add and remove paths leave driver_data consistent.
> - [High] Lockless access to `device->driver_data` causes a TOCTOU
> Use-After-Free race during hot-add failure and hot-remove.
I don't think this is reachable, so I'll leave the locking model
unchanged:
- driver_data is published early (device->driver_data = root), but the
PCI hierarchy below this root bridge is not created until
pci_acpi_scan_root() and pci_bus_add_devices(), both of which run
only on the success path, after the dmar_device_add() error goto.
During the error window there are no child PCI devices yet, so an AER
or CXL consumer under this bridge has no way to obtain the handle and
call acpi_pci_find_root() against a half-initialized root.
- The early publish of driver_data is pre-existing; this patch does not
change it, it only makes the error-path cleanup consistent.
- ACPI .add and .remove are serialized by acpi_scan_lock, so add cannot
race remove.
If there is a concrete caller that can reach acpi_pci_find_root() for
this handle during the add-failure window, I'm happy to revisit. Adding
RCU or locking to the find_root() fast path otherwise seems unwarranted
for this fix.
I'll send a v2 with the acpi_pci_root_remove() fix.
Thanks,
Pei
prev parent reply other threads:[~2026-07-15 13:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 12:12 Chen Pei
[not found] ` <20260707122549.C01DC1F00A3A@smtp.kernel.org>
2026-07-15 13:33 ` Chen Pei [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=20260715133020.3282712-1-cp0613@linux.alibaba.com \
--to=cp0613@linux.alibaba.com \
--cc=alison.schofield@intel.com \
--cc=bhelgaas@google.com \
--cc=dave.jiang@intel.com \
--cc=guoren@kernel.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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
Powered by JetHome