From: sashiko-bot@kernel.org
To: "Philipp Stanner" <phasta@kernel.org>
Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org,
ojeda@kernel.org, gary@garyguo.net
Subject: Re: [RFC PATCH v6 3/5] rust: DmaFence: Don't drop on signal
Date: Fri, 16 Oct 2026 09:04:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-174048@kernel.org> (raw)
In-Reply-To: <20261016085724.1031766-5-phasta@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] dma_fence: counter underflow in DriverFence::signal leads to panic or UAF
--
commit 2af2d8c956b06120d0b00ac40ad908be8f229a7d
Author: Philipp Stanner <phasta@kernel.org>
rust: DmaFence: Don't drop on signal
This commit changes the DriverFence::signal method to take a shared reference
instead of consuming the object. This allows multiple or concurrent calls to
signal() on the same fence object, avoiding unnecessary drops in atomic
contexts.
> diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_fence.rs
> index 0028124e6aa64..b67121c7abd41 100644
> --- a/rust/kernel/dma_buf/dma_fence.rs
> +++ b/rust/kernel/dma_buf/dma_fence.rs
> @@ -806,23 +806,23 @@ pub fn as_fence(&self) -> &Fence {
> }
>
> /// Signal the fence. This will invoke all registered callbacks.
> - pub fn signal(self, res: Result) {
> + pub fn signal(&self, res: Result) {
> let fence = self.as_fence().lock();
>
> // SAFETY: `fence` is valid because `self` is valid. The lock must be
[ ... ]
> // SAFETY: `fence` is valid because `self` is valid. The lock must
> // be held, which we acquired above.
> unsafe { bindings::dma_fence_signal_locked(fence.as_raw()) };
> }
>
> // SAFETY: `self.data` is valid because `self` is valid.
> let fctx = unsafe { self.data.as_ref().fctx };
> let _ = fctx.nr_of_unsignaled_fences.fetch_sub(1, Relaxed);
[Severity: High]
Since signal() now takes a shared reference and can be called multiple times,
will this unconditional decrement of nr_of_unsignaled_fences cause an
underflow?
When called repeatedly for the same fence, this decrement executes outside
the if !signaled block and will occur on every call.
This could cause the counter to artificially reach 0 and bypass the panic
check in FenceContext::drop(), potentially allowing the context to be freed
while unsignaled fences still exist.
Could this result in a use-after-free when those fences are later queried by
the C backend?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261016085724.1031766-2-phasta@kernel.org?part=3
next prev parent reply other threads:[~2026-10-16 9:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 8:57 [RFC PATCH v6 0/5] rust: Add drm::JobQueue Philipp Stanner
2026-10-16 8:57 ` [RFC PATCH v6 1/5] rust: DmaFence: remove static lifetime Philipp Stanner
2026-10-16 9:06 ` sashiko-bot
2026-10-16 8:57 ` [RFC PATCH v6 2/5] rust: DmaFence: Implement Deref for FenceContext Philipp Stanner
2026-10-16 9:01 ` sashiko-bot
2026-10-16 8:57 ` [RFC PATCH v6 3/5] rust: DmaFence: Don't drop on signal Philipp Stanner
2026-10-16 9:04 ` sashiko-bot [this message]
2026-10-16 9:49 ` Alice Ryhl
2026-10-16 8:57 ` [RFC PATCH v6 4/5] rust: DmaFence: Replace call_rcu() with synchronize_rcu() Philipp Stanner
2026-10-16 9:11 ` sashiko-bot
2026-10-16 8:57 ` [RFC PATCH v6 5/5] rust: drm: Add JobQueue Philipp Stanner
2026-10-16 9:12 ` 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=sashiko-outbox-174048@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=media-ci@linuxtv.org \
--cc=ojeda@kernel.org \
--cc=phasta@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.