From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Danilo Krummrich <dakr@kernel.org>
Cc: bleung@chromium.org, dawidn@google.com,
chrome-platform@lists.linux.dev, akpm@linux-foundation.org,
gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] lib: Add ref_proxy module
Date: Fri, 15 Aug 2025 05:36:16 +0000 [thread overview]
Message-ID: <aJ7HUJ0boqYndbtD@google.com> (raw)
In-Reply-To: <DC23GUWD2MYC.1RXVDA2RN7WH3@kernel.org>
On Thu, Aug 14, 2025 at 12:55:55PM +0200, Danilo Krummrich wrote:
> On Thu Aug 14, 2025 at 11:10 AM CEST, Tzung-Bi Shih wrote:
> As mentioned in a sub-thread [1], this is pretty much what we already do in Rust
> with Revocable [2].
>
> The Rust struct Devres [3] is built on Revocable, such that a device resource is
> only accessible for drivers as long as the device is actually bound to the
> driver. Once the device is unbound the resource is "revoked" and drivers are
> prevented from subsequent accesses.
>
> I think it's be good to have a common naming scheme for this, hence I propose to
> name this struct revocable instead.
Sure, will address all review comments and fix in the next version.
> Besides that, I'm not exactly sure I understand why we need two structs for this.
> struct ref_proxy seems unnecessary. I think we should remove it and rename
> struct ref_proxy_provider to struct revocable. Or do I miss anything?
srcu_read_lock() returns an index [4]. The struct ref_proxy is necessary
for tracking the index for leaving the critical section.
[4] https://elixir.bootlin.com/linux/v6.16/source/kernel/rcu/srcutree.c#L750
> > + *
> > + * This holds an initial refcount to the struct.
> > + *
> > + * Return: The pointer of struct ref_proxy_provider. NULL on errors.
> > + */
> > +struct ref_proxy_provider *ref_proxy_provider_alloc(void *ref)
>
> The ref_proxy_provider owns the resource now, so when the ref_proxy_provider
> gets revoked (through the devres callback) the resource must be released, right?
> Where is this done? Who is responsible to do so? Shouldn't this function take a
> release callback that is called once the ref_proxy_provider is revoked?
Thank you, that's a valuable suggestion. While both approaches are valid,
the current implementation is based on a clear separation of ownership.
The design is that struct ref_proxy_provider doesn't own the resource.
Instead, the resource provider (e.g., cros_ec_spi) is responsible for the
full lifecycle:
* It owns and ultimately releases the resource (e.g., [5]).
* It calls ref_proxy_provider_alloc() to expose the resource.
* It calls ref_proxy_provider_free() to revoke access to the resource.
By doing so, the resource provider doesn't need to create a bunch of
void (*release)(void *) callbacks (if multiple resources are exposing).
[5] https://elixir.bootlin.com/linux/v6.16/source/drivers/platform/chrome/cros_ec_spi.c#L752
next prev parent reply other threads:[~2025-08-15 5:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-14 9:10 [PATCH 0/3] platform/chrome: Fix a possible UAF via ref_proxy Tzung-Bi Shih
2025-08-14 9:10 ` [PATCH 1/3] lib: Add ref_proxy module Tzung-Bi Shih
2025-08-14 10:03 ` Greg KH
2025-08-15 5:35 ` Tzung-Bi Shih
2025-08-14 10:05 ` Greg KH
2025-08-14 10:27 ` Danilo Krummrich
2025-08-14 10:55 ` Danilo Krummrich
2025-08-15 5:36 ` Tzung-Bi Shih [this message]
2025-08-14 9:10 ` [PATCH 2/3] platform/chrome: Protect cros_ec_device lifecycle with ref_proxy Tzung-Bi Shih
2025-08-15 13:37 ` kernel test robot
2025-08-14 9:10 ` [PATCH 3/3] platform/chrome: cros_ec_chardev: Consume cros_ec_device via ref_proxy Tzung-Bi Shih
2025-08-15 21:06 ` kernel test robot
2025-08-16 11:46 ` kernel test robot
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=aJ7HUJ0boqYndbtD@google.com \
--to=tzungbi@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=dakr@kernel.org \
--cc=dawidn@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/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