[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aPGryj-V5PQZRtoI@google.com>
Date: Fri, 17 Oct 2025 02:36:58 +0000
From: Tzung-Bi Shih <tzungbi@...nel.org>
To: Jason Gunthorpe <jgg@...dia.com>
Cc: Benson Leung <bleung@...omium.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Danilo Krummrich <dakr@...nel.org>,
Jonathan Corbet <corbet@....net>, Shuah Khan <shuah@...nel.org>,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
chrome-platform@...ts.linux.dev, linux-kselftest@...r.kernel.org,
Laurent Pinchart <laurent.pinchart@...asonboard.com>,
Bartosz Golaszewski <brgl@...ev.pl>,
Wolfram Sang <wsa+renesas@...g-engineering.com>,
Simona Vetter <simona.vetter@...ll.ch>,
Dan Williams <dan.j.williams@...el.com>
Subject: Re: [PATCH v5 5/7] revocable: Add fops replacement
On Thu, Oct 16, 2025 at 09:31:49AM -0300, Jason Gunthorpe wrote:
> On Thu, Oct 16, 2025 at 05:42:02AM +0000, Tzung-Bi Shih wrote:
> > Introduce fs_revocable_replace() to simplify the use of the revocable
> > API with file_operations.
> >
> > The function, should be called from a driver's ->open(), replaces the
> > fops with a wrapper that automatically handles the `try_access` and
> > `withdraw_access`.
> >
> > When the file is closed, the wrapper's ->release() restores the original
> > fops and cleanups. This centralizes the revocable logic, making drivers
> > cleaner and easier to maintain.
> >
> > Signed-off-by: Tzung-Bi Shih <tzungbi@...nel.org>
> > ---
> > PoC patch.
> >
> > Known issues:
> > - All file operations call revocable_try_access() for guaranteeing the
> > resource even if the resource may be unused in the fops.
>
> Why is this so complicated??
>
> You already added a per-flip struct:
>
> > +struct fs_revocable_replacement {
> > + const struct fs_revocable_operations *frops;
> > + const struct file_operations *orig_fops;
> > + struct file_operations fops;
> > + struct revocable **revs;
> > + size_t num_revs;
> > +};
>
> Why does it need so much junk in it?
>
> struct fs_revocable_replacement {
> struct srcu_struct srcu;
> bool *alive;
> };
>
> That's it. When the caller sets this up it provides a bool * pointer
> from it's own private struct that is kept krefcounted to life cycle of
> the struct file.
>
> Then the ops wrapers are a simple thing - generate them with a macro:
>
> srcu_read_lock(&f_rr->srcu);
> if (*f_rr_>alive)
> ret = f_rr->orig_fops->XX(...)
> else
> ret = -ENODEV;
> srcu_read_unlock(&f_rr->srcu);
> return ret;
>
> No need for all this revokable maze to do somethinig so simple.
Imagining the following example:
/* res1 and res2 are provided by hot-pluggable devices. */
struct filp_priv {
void *res1;
void *res2;
};
/* In .open() fops */
priv = kzalloc(sizeof(struct filp_priv), ...);
priv->res1 = ...;
priv->res2 = ...;
filp->private_data = priv;
/* In .read() fops */
priv = filp->private_data;
priv->res1 // could result UAF if the device has gone
priv->res2 // could result UAF if the device has gone
How does the bool * work for the example?
Powered by blists - more mailing lists