From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org
Subject: Re: [PATCH v16 2/3] samples: rust: add Rust serial device bus sample device driver
Date: Sat, 18 Jul 2026 15:54:37 +0000 [thread overview]
Message-ID: <20260718155437.9BE091F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260718-rust_serdev-v16-2-5809384d2e1b@posteo.de>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Race condition causing Use-After-Free and NULL pointer dereference in `receive_buf_callback` during device unbind or probe failure.
- [Medium] Missing `write_wakeup` hook in serdev abstraction causes driver stalls on transmit buffer full.
--
--- Patch [2]: [PATCH v16 2/3] samples: rust: add Rust serial device bus sample device driver ---
commit 55560927fe62016a13f3a51d6f3e3f813e10db57
Author: Markus Probst <markus.probst@posteo.de>
samples: rust: add Rust serial device bus sample device driver
Add a sample Rust serial device bus device driver illustrating the usage
of the serial device bus abstractions.
> diff --git a/samples/rust/rust_driver_serdev.rs b/samples/rust/rust_driver_serdev.rs
> new file mode 100644
> index 0000000000000..a12b1412db30c
> --- /dev/null
> +++ b/samples/rust/rust_driver_serdev.rs
[ ... ]
> + fn receive<'bound>(
> + sdev: &'bound serdev::Device<Bound>,
> + _this: Pin<&Self>,
> + data: &[u8],
> + ) -> usize {
> + sdev.write(data).unwrap_or_default() as usize
[Severity: Medium]
Will this driver stall on a full transmit buffer?
If the transmit buffer fills up, sdev.write() returns a short count, which the
driver propagates back to the TTY core.
The TTY core responds by pausing further receive operations until space becomes
available.
Since the Rust serdev abstraction hardcodes write_wakeup to
bindings::serdev_device_write_wakeup (which only wakes up synchronous writes via
write_all):
rust/kernel/serdev.rs:Adapter::OPS {
...
write_wakeup: Some(bindings::serdev_device_write_wakeup),
...
}
the driver cannot hook write_wakeup to be notified when transmit space becomes
available.
As a result, the driver never resumes the TTY receive path, causing a permanent
stall until a new byte physically arrives to re-trigger the receive workqueue.
> + }
> +}
> +
> +impl Drop for SampleDriver {
> + fn drop(&mut self) {
> + dev_dbg!(
> + self.sdev.as_ref(),
> + "Remove Rust Serial device bus device driver sample.\n"
> + );
> + }
> +}
[Severity: High]
Does the serdev abstraction have a use-after-free or NULL pointer dereference
race condition during device unbind or probe failure?
During device unbind, the driver core invokes post_unbind_callback, which calls
drvdata_obtain to take ownership of the driver data, setting drvdata to NULL:
rust/kernel/device.rs:drvdata_obtain() {
...
unsafe { bindings::dev_set_drvdata(self.as_raw(), core::ptr::null_mut()) };
...
}
It then drops PrivateData, which closes the device:
rust/kernel/serdev.rs:PinnedDrop for PrivateData {
...
unsafe { bindings::serdev_device_close(self.sdev.as_raw()) };
...
}
Because the device is closed only at the end of the drop routine, the TTY port
remains active while drvdata is NULL and while PrivateData is being freed.
If data arrives on the UART during this window, the TTY layer concurrently
invokes receive_buf_callback, which borrows drvdata:
rust/kernel/serdev.rs:receive_buf_callback() {
...
let private_data = unsafe { sdev.as_ref().drvdata_borrow::<PrivateData<'_, T>>() };
...
}
rust/kernel/device.rs:drvdata_borrow() {
...
unsafe { Pin::<KBox<T>>::borrow(ptr.cast()) }
...
}
This will either dereference the NULL drvdata pointer, or if it already read
the pointer before drvdata_obtain, it will access PrivateData after it has been
freed when attempting to lock active.
The same race exists in the probe error path where ScopeGuard drops PrivateData
before the device is closed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260718-rust_serdev-v16-0-5809384d2e1b@posteo.de?part=2
next prev parent reply other threads:[~2026-07-18 15:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 15:33 [PATCH v16 0/3] rust: add basic serial device bus abstractions Markus Probst
2026-07-18 15:33 ` [PATCH v16 1/3] " Markus Probst
2026-07-18 15:48 ` sashiko-bot
2026-07-18 15:33 ` [PATCH v16 2/3] samples: rust: add Rust serial device bus sample device driver Markus Probst
2026-07-18 15:54 ` sashiko-bot [this message]
2026-07-18 15:33 ` [PATCH v16 3/3] MAINTAINERS: serdev: Add self for serdev Markus Probst
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=20260718155437.9BE091F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=markus.probst@posteo.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.