Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ayush Singh" <ayush@beagleboard.org>
Cc: robh@kernel.org, devicetree@vger.kernel.org, ojeda@kernel.org,
	conor+dt@kernel.org
Subject: Re: [PATCH v2 2/7] greybus: connection: Add gb_connection_hd_find_by_intf()
Date: Thu, 27 Aug 2026 08:13:14 +0000	[thread overview]
Message-ID: <20260827081314.6DE201F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260827-gb-uart-transport-v2-2-a03bb1f5fbd1@beagleboard.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Returning a refcounted gb_connection for external use enables Use-After-Free vulnerabilities because connection teardown ignores the refcount.

Pre-existing issues:
- [High] Race condition between `gb_operation_request_send()` and `gb_connection_destroy()` leads to a message being sent to a released or reassigned `hd_cport_id`.
--

commit 4b0f9446338941774da275dbe57306c7d950598d
Author: Ayush Singh <ayush@beagleboard.org>

    greybus: connection: Add gb_connection_hd_find_by_intf()

This commit introduces gb_connection_hd_find_by_intf() to look up a
connection on a host device using its remote interface ID and CPort ID. It
returns a reference-counted connection pointer to the caller.

> diff --git a/drivers/greybus/connection.c b/drivers/greybus/connection.c
> index f8fda22bc4667..dc9eb49a69bcf 100644
> --- a/drivers/greybus/connection.c
> +++ b/drivers/greybus/connection.c
> @@ -71,6 +71,29 @@ gb_connection_hd_find(struct gb_host_device *hd, u16 cport_id)
>  	return connection;
>  }
>  
> +struct gb_connection *gb_connection_hd_find_by_intf(struct gb_host_device *hd,
> +						    u8 intf_id, u16 intf_cport)
> +{
> +	struct gb_connection *connection;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&gb_connections_lock, flags);
> +	list_for_each_entry(connection, &hd->connections, hd_links) {
> +		if (connection->intf &&
> +		    connection->intf->interface_id == intf_id &&
> +		    connection->intf_cport_id == intf_cport) {
> +			gb_connection_get(connection);

[Severity: High]
Does returning a refcounted gb_connection for external use enable
use-after-free vulnerabilities?

If an external driver like gb_softsvc uses this new API to obtain the
connection, a hot-unplug event could trigger gb_connection_destroy(). Since
connection teardown ignores this kref, it will unconditionally destroy the
workqueue and release the CPort.

Can the external driver subsequently access the torn-down connection,
resulting in a use-after-free of connection->intf and resource confusion
of connection->wq and hd_cport_id?

> +			goto found;
> +		}
> +	}
> +	connection = NULL;
> +found:
> +	spin_unlock_irqrestore(&gb_connections_lock, flags);
> +
> +	return connection;
> +}
> +EXPORT_SYMBOL_GPL(gb_connection_hd_find_by_intf);

[ ... ]

Looking at gb_operation_request_send() in drivers/greybus/operation.c:

> 	/*
> 	 * Get an extra reference on the operation. It'll be dropped when the
> 	 * operation completes.
> 	 */
> 	gb_operation_get(operation);
> 	ret = gb_operation_get_active(operation);
> 	if (ret)
> 		goto err_put;
> 
> 	ret = gb_message_send(operation->request, gfp);

[Severity: High]
This is a pre-existing issue, but can a race condition occur between
gb_operation_request_send() and gb_connection_destroy() leading to a message
being sent to a released or reassigned hd_cport_id?

If gb_operation_request_send() gets the active reference, unlocks the
connection, and is preempted before calling gb_message_send():

    gb_operation_get_active(operation);
    // preempted here

Concurrent gb_connection_destroy() could cancel the operation, wait for the
completion work to drop the active ref, and then destroy the connection
resources (setting hd_cport_id to CPORT_ID_BAD and releasing it).

When the preempted thread resumes, could it use the released or recycled
hd_cport_id when calling gb_message_send(), potentially causing the host
driver to send data to the wrong endpoint or panic?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260827-gb-uart-transport-v2-0-a03bb1f5fbd1@beagleboard.org?part=2

  reply	other threads:[~2026-08-27  8:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27  7:54 [PATCH v2 0/7] Add Greybus Sotfsvc and UART Node drivers Ayush Singh
2026-08-27  7:54 ` [PATCH v2 1/7] greybus: connection: Export gb_connection_get() and gb_connection_put() Ayush Singh
2026-08-27  7:54 ` [PATCH v2 2/7] greybus: connection: Add gb_connection_hd_find_by_intf() Ayush Singh
2026-08-27  8:13   ` sashiko-bot [this message]
2026-08-27  7:54 ` [PATCH v2 3/7] rust: crc_ccitt: add CRC-CCITT abstraction Ayush Singh
2026-08-27  7:54 ` [PATCH v2 4/7] rust: kernel: Add greybus abstractions Ayush Singh
2026-08-27  8:12   ` sashiko-bot
2026-08-27  7:54 ` [PATCH v2 5/7] drivers: greybus: Add software SVC implementation Ayush Singh
2026-08-27  8:09   ` sashiko-bot
2026-08-27  7:54 ` [PATCH v2 6/7] dt-bindings: beagle: Add BeagleConnect Freedom Ayush Singh
2026-08-27  8:02   ` sashiko-bot
2026-08-27 16:06   ` Conor Dooley
2026-08-27  7:54 ` [PATCH v2 7/7] greybus: Add Rust UART node driver Ayush Singh
2026-08-27  8:13   ` 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=20260827081314.6DE201F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ayush@beagleboard.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=robh@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