From: sashiko-bot@kernel.org
To: "Ayush Singh" <ayush@beagleboard.org>,
"Jason Kridner" <jkridner@beagleboard.org>,
robertcnelson@gmail.com, "Johan Hovold" <johan@kernel.org>,
"Alex Elder" <elder@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Eric Biggers" <ebiggers@kernel.org>,
"Ard Biesheuvel" <ardb@kernel.org>,
"Ayush Singh" <ayush@beagleboard.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Markus Probst" <markus.probst@posteo.de>
Cc: linux-crypto@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v6 2/9] greybus: operation: arm request timeout before sending
Date: Fri, 04 Dec 2026 10:52:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-249636@kernel.org> (raw)
In-Reply-To: <20261204-gb-uart-transport-v6-2-668b333ae71d@beagleboard.org>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] greybus: operation: UAF and refcount underflow on timeout
during send error
- [High] greybus: operation: early timeout cancels message before host
send submits
- [Low] greybus: operation: missing Fixes trailer for timer-arming race
fix
--
commit ee52b7007b03515d30adcc46c964de89de7b73c3
Author: Ayush Singh <ayush@beagleboard.org>
> greybus: operation: arm request timeout before sending
>
> The host driver can complete a request before add_timer is called. The
> main case for this is softsvc, although, depending on which transport
> is used, there is a possibility that response arrives much faster than
> expected.
>
> By populating timer earilier, we prevent the starting a timer on
> already completed request (which would then leak an active timer on cleanup).
>
> Signed-off-by: Ayush Singh <ayush@beagleboard.org>
[Severity: Low]
This fixes the timer-arming race introduced with generic operation
timeouts. Should this include:
Fixes: dbec27298b0d ("staging: greybus: operation: add generic timeout support")
> diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c
> index a9eada39ec793..cac3b0abf62bc 100644
> --- a/drivers/greybus/operation.c
> +++ b/drivers/greybus/operation.c
> @@ -786,18 +786,23 @@ int gb_operation_request_send(struct gb_operation *operation,
> if (ret)
> goto err_put;
>
> - ret = gb_message_send(operation->request, gfp);
> - if (ret)
> - goto err_put_active;
> -
> + /*
> + * Arm the timeout before sending: the response can arrive, and the
> + * operation complete, before the host driver returns.
> + */
> if (timeout) {
> operation->timer.expires = jiffies + msecs_to_jiffies(timeout);
> add_timer(&operation->timer);
> }
>
> + ret = gb_message_send(operation->request, gfp);
> + if (ret)
> + goto err_put_active;
[Severity: High]
Can an early timeout call gb_message_cancel() before the host driver has
finished submitting the request?
If the sender sleeps or is preempted inside gb_message_send() (for
example, in drivers/greybus/es2.c:message_send() between assigning
message->hcpriv and calling usb_submit_urb()), operation->timer can
expire and queue gb_operation_work() before submission completes:
CPU0 kworker
gb_operation_request_send()
add_timer(&operation->timer)
gb_message_send()
... es2:message_send()
message->hcpriv = urb
usb_fill_bulk_urb(urb, ...)
<timer expires>
gb_operation_timeout()
gb_operation_result_set(-ETIMEDOUT)
queue_work(&operation->work)
gb_operation_work()
gb_message_cancel()
... es2:message_cancel()
usb_kill_urb(urb) <-- data race
usb_submit_urb(urb, ...) <-- submits timed-out URB
In es2.c, usb_kill_urb() either returns as a no-op when message->hcpriv
is still NULL or races with usb_fill_bulk_urb() on struct urb fields,
allowing the timed-out URB to be submitted afterward. If that URB
stalls, gb_operation_cancel() during connection teardown sees
operation->errno is already -ETIMEDOUT, skips gb_message_cancel(), and
blocks forever in wait_event().
> return 0;
>
> err_put_active:
> + timer_delete_sync(&operation->timer);
> gb_operation_put_active(operation);
> gb_operation_put_active(operation);
> err_put:
[Severity: High]
Can err_put_active cause a use-after-free and refcount underflow when
operation->timer expires before gb_message_send() returns an error?
In drivers/greybus/gb-beagleplay.c, hdlc_tx_frames() can sleep up to 1.5
to 2.5 seconds waiting for TX ring space before returning -EAGAIN,
exceeding GB_OPERATION_TIMEOUT_DEFAULT (1000 ms). When the timer fires
during that window, gb_operation_timeout() queues operation->work, and
timer_delete_sync() returns 0 without cancelling the queued work:
CPU0 kworker
gb_operation_request_send()
gb_operation_get() x2
__gb_operation_get_active(2)
add_timer(&operation->timer)
gb_message_send()
... hdlc_tx_frames() sleeps
<timer expires>
gb_operation_timeout()
gb_operation_result_set(-ETIMEDOUT)
queue_work(&operation->work)
returns -EAGAIN
err_put_active:
timer_delete_sync() -> 0
gb_operation_put_active() x2
gb_operation_put() x2
caller drops final ref -> free
gb_operation_work()
operation->callback() <-- use-after-free
gb_operation_put_active() <-- underflow
gb_operation_put()
Three active-count puts and three kref puts then run against only two
acquisitions, freeing operation while operation->work is still queued or
underflowing operation->active to -1. Because operation->callback()
also runs despite the error return, callers like
gb_loopback_async_operation() double free op_async and drop an extra
operation reference.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-gb-uart-transport-v6-0-668b333ae71d@beagleboard.org?part=2
next prev parent reply other threads:[~2026-12-04 10:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:30 [PATCH v6 0/9] Add Greybus Sotfsvc and UART Node drivers Ayush Singh
2026-12-04 10:30 ` [PATCH v6 1/9] greybus: operation: keep request active across message_send Ayush Singh
2026-12-04 10:55 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 2/9] greybus: operation: arm request timeout before sending Ayush Singh
2026-12-04 10:52 ` sashiko-bot [this message]
2026-12-04 10:30 ` [PATCH v6 3/9] greybus: svc: add gb_svc_flush() Ayush Singh
2026-12-04 10:43 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 4/9] greybus: connection: Add greybus_data_rcvd_by_intf() Ayush Singh
2026-12-04 10:52 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 5/9] rust: crc_ccitt: add CRC-CCITT abstraction Ayush Singh
2026-12-04 10:30 ` [PATCH v6 6/9] rust: kernel: Add greybus abstractions Ayush Singh
2026-12-04 11:06 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 7/9] drivers: greybus: Add software SVC implementation Ayush Singh
2026-12-04 11:07 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 8/9] dt-bindings: beagle: Add BeagleConnect Freedom Ayush Singh
2026-12-04 11:03 ` sashiko-bot
2026-12-04 10:30 ` [PATCH v6 9/9] greybus: Add Rust UART node driver Ayush Singh
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-249636@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=ardb@kernel.org \
--cc=ayush@beagleboard.com \
--cc=ayush@beagleboard.org \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=conor+dt@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=ebiggers@kernel.org \
--cc=elder@kernel.org \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=jkridner@beagleboard.org \
--cc=johan@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=liam@infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=lossin@kernel.org \
--cc=markus.probst@posteo.de \
--cc=ojeda@kernel.org \
--cc=robertcnelson@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
--cc=work@onurozkan.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