Devicetree
 help / color / mirror / Atom feed
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 4/9] greybus: connection: Add greybus_data_rcvd_by_intf()
Date: Fri, 04 Dec 2026 10:52:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-249635@kernel.org> (raw)
In-Reply-To: <20261204-gb-uart-transport-v6-4-668b333ae71d@beagleboard.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] greybus: UAF of connection->intf in
  gb_connection_hd_find_by_intf()
- [Low] greybus: inaccurate SVC rationale for new
  greybus_data_rcvd_by_intf() API
--

commit 9a7e831befd1a2fc164cd72fa192fea985fd34bd
Author: Ayush Singh <ayush@beagleboard.org>

greybus: connection: Add greybus_data_rcvd_by_intf()

This commit adds gb_connection_hd_find_by_intf() and exports
greybus_data_rcvd_by_intf() to deliver incoming Greybus data by interface
id and interface CPort id instead of host CPort id.

> diff --git a/drivers/greybus/connection.c b/drivers/greybus/connection.c
> index bd04485decb3d..ce8646299ce8c 100644
> --- a/drivers/greybus/connection.c
> +++ b/drivers/greybus/connection.c
> @@ -69,6 +69,32 @@ gb_connection_hd_find(struct gb_host_device *hd, u16 cport_id)
>  	return connection;
>  }
>  
> +/*
> + * Returns a reference-counted pointer to the connection if found.
> + */
> +static 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) {

[Severity: High]
Can dereferencing connection->intf->interface_id trigger a use-after-free
of struct gb_interface?

Neither _gb_connection_create() nor gb_control_create() takes a reference
on intf->dev, and control->connection is only unlinked from hd->connections
in gb_control_release().

During module removal, gb_control_del() drops control->dev's parent
reference to intf->dev via device_del().  If a bus or PM iterator still
holds control->dev (or CONFIG_DEBUG_KOBJECT_RELEASE delays release),
gb_interface_release() can free intf while control->connection stays listed:

CPU0                                  CPU1
gb_interface_disable()
  gb_control_del()
    device_del(&control->dev)
      put_device(&intf->dev)
  gb_control_put() [held by bus/PM]
gb_interface_release()
  kfree(intf)
                                      greybus_data_rcvd_by_intf()
                                        gb_connection_hd_find_by_intf()
                                          connection->intf->interface_id
                                            <-- use-after-free

Any incoming frame on the shared host device then reads freed memory under
gb_connections_lock with IRQs disabled.  Caching interface_id in struct
gb_connection at creation time (or holding a reference on intf->dev for
the connection's lifetime) would avoid dereferencing a freed gb_interface.

[ ... ]

> @@ -91,6 +117,27 @@ void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
>  }
>  EXPORT_SYMBOL_GPL(greybus_data_rcvd);
>  
> +/*
> + * Callback from a host driver that only knows the remote end of a connection
> + * (interface id and interface CPort id), such as a software SVC.
> + */
> +int greybus_data_rcvd_by_intf(struct gb_host_device *hd, u8 intf_id,
> +			      u16 intf_cport, u8 *data, size_t length)

[Severity: Low]
Is this new exported RX entry point needed for a software SVC, and is the
rationale in the comment and commit message accurate?

For every non-static connection, gb_connection_svc_connection_create()
sends both hd_cport_id and (interface_id, intf_cport_id) to the SVC via
GB_SVC_TYPE_CONN_CREATE, and gb_connection_svc_connection_destroy() pairs
it with GB_SVC_TYPE_CONN_DESTROY.

On TX, gb_message_send() also passes hd_cport_id to message_send().  A
software SVC that tracks its connection table can deliver data through the
existing greybus_data_rcvd() instead of adding a duplicate exported helper.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-gb-uart-transport-v6-0-668b333ae71d@beagleboard.org?part=4

  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
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 [this message]
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-249635@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