From: sashiko-bot@kernel.org
To: "Danilo Krummrich" <dakr@kernel.org>
Cc: ojeda@kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v3 19/27] rust: pci: make Bar lifetime-parameterized
Date: Sun, 17 May 2026 00:57:41 +0000 [thread overview]
Message-ID: <20260517005742.38251C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260517000149.3226762-20-dakr@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The `name` pointer passed to `pci_request_region` is stored directly in the kernel's resource tree, causing a Use-After-Free if a dynamically allocated string is passed.
--
commit 288028203fe9a624774ed430783fe427c724785b
Author: Danilo Krummrich <dakr@kernel.org>
rust: pci: make Bar lifetime-parameterized
Convert pci::Bar to be lifetime-parameterized over the device bound.
iomap_region_sized now returns Result<Bar<'bound, SIZE>> directly. Add
Bar::into_devres() to register the bar as a device-managed resource.
> diff --git a/rust/kernel/pci/io.rs b/rust/kernel/pci/io.rs
> index ae78676c927ff..5668394a155bd 100644
> --- a/rust/kernel/pci/io.rs
> +++ b/rust/kernel/pci/io.rs
[ ... ]
> @@ -146,14 +145,14 @@ impl<'a, S: ConfigSpaceKind> IoKnownSize for ConfigSpace<'a, S> {
> ///
> /// `Bar` always holds an `IoRaw` instance that holds a valid pointer to the start of the I/O
> /// memory mapped PCI BAR and its size.
> -pub struct Bar<const SIZE: usize = 0> {
> - pdev: ARef<Device>,
> +pub struct Bar<'bound, const SIZE: usize = 0> {
> + pdev: &'bound Device<device::Bound>,
> io: MmioRaw<SIZE>,
> num: i32,
> }
>
> -impl<const SIZE: usize> Bar<SIZE> {
> - pub(super) fn new(pdev: &Device, num: u32, name: &CStr) -> Result<Self> {
> +impl<'bound, const SIZE: usize> Bar<'bound, SIZE> {
> + pub(super) fn new(pdev: &'bound Device<device::Bound>, num: u32, name: &CStr) -> Result<Self> {
Does this name parameter need a 'static bound?
The kernel's pci_request_region() function (via __request_region_locked())
stores the raw string pointer directly into the struct resource tree
(res->name = name) without copying it.
Because the API does not enforce a 'static lifetime on name, a caller
could pass a dynamically allocated CString that is dropped immediately. If
this happens, the kernel resource tree will hold a dangling pointer,
resulting in a use-after-free when /proc/iomem or /proc/ioports are read.
While the previous signature (name: &'a CStr) also failed to guarantee the
string outlived the resource, should we enforce name: &'static CStr here
to prevent memory corruption?
[ ... ]
> @@ -249,20 +257,16 @@ fn deref(&self) -> &Self::Target {
> impl Device<device::Bound> {
> /// Maps an entire PCI BAR after performing a region-request on it. I/O operation bound checks
> /// can be performed on compile time for offsets (plus the requested type size) < SIZE.
> - pub fn iomap_region_sized<'a, const SIZE: usize>(
> - &'a self,
> + pub fn iomap_region_sized<'bound, const SIZE: usize>(
> + &'bound self,
> bar: u32,
> - name: &'a CStr,
> - ) -> impl PinInit<Devres<Bar<SIZE>>, Error> + 'a {
> - Devres::new(self.as_ref(), Bar::<SIZE>::new(self, bar, name))
> + name: &CStr,
> + ) -> Result<Bar<'bound, SIZE>> {
> + Bar::new(self, bar, name)
> }
>
> /// Maps an entire PCI BAR after performing a region-request on it.
> - pub fn iomap_region<'a>(
> - &'a self,
> - bar: u32,
> - name: &'a CStr,
> - ) -> impl PinInit<Devres<Bar>, Error> + 'a {
> + pub fn iomap_region<'bound>(&'bound self, bar: u32, name: &CStr) -> Result<Bar<'bound>> {
> self.iomap_region_sized::<0>(bar, name)
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260517000149.3226762-1-dakr@kernel.org?part=19
next prev parent reply other threads:[~2026-05-17 0:57 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-17 0:00 [PATCH v3 00/27] rust: device: Higher-Ranked Lifetime Types for device drivers Danilo Krummrich
2026-05-17 0:00 ` [PATCH v3 01/27] rust: alloc: remove `'static` bound on `ForeignOwnable` Danilo Krummrich
2026-05-18 14:42 ` Alexandre Courbot
2026-05-17 0:00 ` [PATCH v3 02/27] rust: driver: move 'static bounds to constructor Danilo Krummrich
2026-05-18 14:42 ` Alexandre Courbot
2026-05-17 0:00 ` [PATCH v3 03/27] rust: driver: decouple driver private data from driver type Danilo Krummrich
2026-05-17 0:19 ` sashiko-bot
2026-05-17 14:32 ` Danilo Krummrich
2026-05-19 12:47 ` Gary Guo
2026-05-18 14:43 ` Alexandre Courbot
2026-05-17 0:00 ` [PATCH v3 04/27] rust: driver core: drop drvdata before devres release Danilo Krummrich
2026-05-17 0:37 ` sashiko-bot
2026-05-18 14:45 ` Alexandre Courbot
2026-05-19 12:47 ` Gary Guo
2026-05-17 0:00 ` [PATCH v3 05/27] rust: pci: implement Sync for Device<Bound> Danilo Krummrich
2026-05-17 0:40 ` sashiko-bot
2026-05-18 14:46 ` Alexandre Courbot
2026-05-19 13:01 ` Gary Guo
2026-05-17 0:00 ` [PATCH v3 06/27] rust: platform: " Danilo Krummrich
2026-05-18 14:46 ` Alexandre Courbot
2026-05-19 13:01 ` Gary Guo
2026-05-17 0:00 ` [PATCH v3 07/27] rust: auxiliary: " Danilo Krummrich
2026-05-17 0:36 ` sashiko-bot
2026-05-18 14:47 ` Alexandre Courbot
2026-05-19 13:02 ` Gary Guo
2026-05-17 0:00 ` [PATCH v3 08/27] rust: usb: " Danilo Krummrich
2026-05-17 0:33 ` sashiko-bot
2026-05-18 14:47 ` Alexandre Courbot
2026-05-19 13:02 ` Gary Guo
2026-05-17 0:00 ` [PATCH v3 09/27] rust: device: " Danilo Krummrich
2026-05-17 0:25 ` sashiko-bot
2026-05-18 14:48 ` Alexandre Courbot
2026-05-19 13:02 ` Gary Guo
2026-05-17 0:00 ` [PATCH v3 10/27] rust: pci: make Driver trait lifetime-parameterized Danilo Krummrich
2026-05-17 0:29 ` sashiko-bot
2026-05-18 14:53 ` Alexandre Courbot
2026-05-18 15:36 ` Gary Guo
2026-05-18 16:10 ` Danilo Krummrich
2026-05-19 4:52 ` Eliot Courtney
2026-05-19 10:39 ` Danilo Krummrich
2026-05-19 11:48 ` Gary Guo
2026-05-19 12:36 ` Danilo Krummrich
2026-05-20 6:14 ` Eliot Courtney
2026-05-17 0:00 ` [PATCH v3 11/27] rust: platform: " Danilo Krummrich
2026-05-18 14:55 ` Alexandre Courbot
2026-05-17 0:01 ` [PATCH v3 12/27] rust: auxiliary: " Danilo Krummrich
2026-05-18 15:39 ` Alexandre Courbot
2026-05-17 0:01 ` [PATCH v3 13/27] rust: usb: " Danilo Krummrich
2026-05-17 0:25 ` sashiko-bot
2026-05-18 15:40 ` Alexandre Courbot
2026-05-17 0:01 ` [PATCH v3 14/27] rust: i2c: " Danilo Krummrich
2026-05-17 0:39 ` sashiko-bot
2026-05-18 15:41 ` Alexandre Courbot
2026-05-17 0:01 ` [PATCH v3 15/27] rust: driver: update module documentation for GAT-based Data type Danilo Krummrich
2026-05-18 15:46 ` Alexandre Courbot
2026-05-17 0:01 ` [PATCH v3 16/27] rust: types: add `ForLt` trait for higher-ranked lifetime support Danilo Krummrich
2026-05-17 0:23 ` sashiko-bot
2026-05-19 6:02 ` Eliot Courtney
2026-05-19 11:23 ` Gary Guo
2026-05-19 11:07 ` Alexandre Courbot
2026-05-19 11:39 ` Gary Guo
2026-05-19 13:03 ` Danilo Krummrich
2026-05-19 13:34 ` Miguel Ojeda
2026-05-17 0:01 ` [PATCH v3 17/27] rust: auxiliary: generalize Registration over ForLt Danilo Krummrich
2026-05-17 0:31 ` sashiko-bot
2026-05-19 7:56 ` Eliot Courtney
2026-05-19 10:39 ` Danilo Krummrich
2026-05-19 11:20 ` Gary Guo
2026-05-19 16:45 ` Gary Guo
2026-05-20 0:33 ` Danilo Krummrich
2026-05-20 9:34 ` Gary Guo
2026-05-17 0:01 ` [PATCH v3 18/27] samples: rust: rust_driver_auxiliary: showcase lifetime-bound registration data Danilo Krummrich
2026-05-19 6:52 ` Eliot Courtney
2026-05-19 15:48 ` Gary Guo
2026-05-17 0:01 ` [PATCH v3 19/27] rust: pci: make Bar lifetime-parameterized Danilo Krummrich
2026-05-17 0:57 ` sashiko-bot [this message]
2026-05-19 6:36 ` Eliot Courtney
2026-05-19 16:24 ` Gary Guo
2026-05-19 17:27 ` Danilo Krummrich
2026-05-17 0:01 ` [PATCH v3 20/27] rust: io: make IoMem and ExclusiveIoMem lifetime-parameterized Danilo Krummrich
2026-05-17 1:31 ` sashiko-bot
2026-05-19 6:39 ` Eliot Courtney
2026-05-17 0:01 ` [PATCH v3 21/27] samples: rust: rust_driver_pci: use HRT lifetime for Bar Danilo Krummrich
2026-05-17 0:57 ` sashiko-bot
2026-05-19 6:41 ` Eliot Courtney
2026-05-17 0:01 ` [PATCH v3 22/27] rust: driver-core: rename 'a lifetime to 'bound Danilo Krummrich
2026-05-17 0:31 ` sashiko-bot
2026-05-19 6:42 ` Eliot Courtney
2026-05-19 16:56 ` Gary Guo
2026-05-19 17:23 ` Danilo Krummrich
2026-05-17 0:01 ` [PATCH REF v3 23/27] gpu: nova-core: " Danilo Krummrich
2026-05-17 0:01 ` [PATCH REF v3 24/27] gpu: nova-core: use lifetime for Bar Danilo Krummrich
2026-05-17 0:58 ` sashiko-bot
2026-05-17 0:01 ` [PATCH REF v3 25/27] gpu: nova-core: unregister sysmem flush page from Drop Danilo Krummrich
2026-05-17 0:50 ` sashiko-bot
2026-05-17 0:01 ` [PATCH REF v3 26/27] gpu: nova-core: replace ARef<Device> with &'bound Device in SysmemFlush Danilo Krummrich
2026-05-17 0:01 ` [PATCH REF v3 27/27] gpu: drm: tyr: use lifetime for IoMem Danilo Krummrich
2026-05-17 0:47 ` sashiko-bot
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=20260517005742.38251C19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dakr@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@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