From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381563; b=iNpqPHU6K66FZB7iIxkkSJkUY0V3V959xiAYL7cCEjYnn/24GkkYjNoRfWKuaYFygPgU YnKgpw9xRA3uAn6duFQ6YIv1dbVve4htGXCG5C4QWRQGP3XFMKXzev6npEoyYvwbYCtLG MHdWot30tL5VLSgu8qbpj6S/peRpYKWxK6pf6K96PhlG2A0wMjRbB9iixvlZckx4jeeUU Ua8W5V2VOhDKT6wRFiUuXjMVC3QfpGl9eu8HPbpiDLi0wHqs2sf5AuWL0+MpVWwHFCkcB I44o5zA/s52oIa361F4Bbx8gFQzYn3VgIaXcABHZA+6xcQAR1AA1t0kN/abh3Q4gK6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381563; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=zz/+ObXg/898LzfQq8D/UkgKYC0nykp3AhD5xcy6swo=; b=uVv7ZF21ykoXs2RGnJVHXKUvqDIK7IWY+rr923mNHx/1Lpw6IACMvtaYToytRWgRCrwM clgxKVrI4ZbMO+9zjSpVIyC0zL0vMmwRoJBQmgOWyB4mhlpLITTugUuTYZzZy8Bk85h9T /QUaESaI5KWLhGtXvlKqBnfUjf2DvI64dBLC3tJyXGcvtkxwpYIgDe3jpMPLC7iwIFEL+ s1Xv/xdkpJ7QRXUTaairWAmZOWjucp0O55FcimxpuuuXJ5a8FCjEC0JTZOVQmafZYpwC2 1lUtjUoMYV16nZUPl/BfrZr/kQ/vM+cEVzDsjerRO9RxGXGFvJ4O23a7e3TP7WExWzw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ARVQr9Nz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0394606A330; Fri, 4 Dec 2026 10:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ARVQr9Nz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D1B51F00897; Fri, 4 Dec 2026 10:52:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796381563; bh=zz/+ObXg/898LzfQq8D/UkgKYC0nykp3AhD5xcy6swo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ARVQr9Nz81FrG/K/mB5L3lrrLqfOGreLB/DLHriypJdw6Y7+epCpFxJk1BDcq5wNz o/s3gu555tF8JZ2hDJ+IEUhI9hpW9N7MG2al/hcJsqj6B7CMJXMA4tF/1zwaMKLqI0 sovYAjU98DnkGM7l8AJCCmTixpnNMswkt1Y2qo3iOYBQMrt2U8YLbZhXaiijSuuM25 ca7nntVNR0/q8ZqIFCoGyku0wzxNszkCLwlR2lTY3g/IacHI2+uF04LNCh7WcYXZP2 Fa/tlHBKPMpMMMH1mCR3zYiHugmnkf13+pvp2MnEyi6VbytCRVHLqwZJBJSaz86k1/ KK6kGdjO33hPw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 2/9] greybus: operation: arm request timeout before sending Reply-To: sashiko-reviews@lists.linux.dev To: "Ayush Singh" , "Jason Kridner" , robertcnelson@gmail.com, "Johan Hovold" , "Alex Elder" , "Greg Kroah-Hartman" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?b?Qmo=?= =?utf-8?b?w7ZybiBSb3kgQmFyb24=?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Daniel Almeida" , "Tamir Duberstein" , "Alexandre Courbot" , =?utf-8?b?T251ciDDlnprYW4=?= , "Eric Biggers" , "Ard Biesheuvel" , "Ayush Singh" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , "Lorenzo Stoakes" , "Vlastimil Babka" , "Liam R. Howlett" , "Uladzislau Rezki" , "Markus Probst" Cc: linux-crypto@vger.kernel.org, devicetree@vger.kernel.org In-Reply-To: <20261204-gb-uart-transport-v6-2-668b333ae71d@beagleboard.org> References: <20261204-gb-uart-transport-v6-0-668b333ae71d@beagleboard.org> <20261204-gb-uart-transport-v6-2-668b333ae71d@beagleboard.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 10:52:41 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > 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 clean= up). > > Signed-off-by: Ayush Singh [Severity: Low] This fixes the timer-arming race introduced with generic operation timeouts. Should this include: Fixes: dbec27298b0d ("staging: greybus: operation: add generic timeout su= pport") > 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; > =20 > - ret =3D 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 =3D jiffies + msecs_to_jiffies(timeout); > add_timer(&operation->timer); > } > =20 > + ret =3D 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 =3D urb usb_fill_bulk_urb(urb, ...) 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; > =20 > 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 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-fr= ee 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-gb-uart-tr= ansport-v6-0-668b333ae71d@beagleboard.org?part=3D2