From: <dan.j.williams@intel.com>
To: Tzung-Bi Shih <tzungbi@kernel.org>,
Benson Leung <bleung@chromium.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>,
"Dawid Niedzwiecki" <dawidn@google.com>,
<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<chrome-platform@lists.linux.dev>,
<linux-kselftest@vger.kernel.org>, <tzungbi@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Wolfram Sang <wsa+renesas@sang-engineering.com>
Subject: Re: [PATCH v4 5/7] revocable: Add fops replacement
Date: Wed, 24 Sep 2025 13:54:14 -0700 [thread overview]
Message-ID: <68d45a76a36ad_1c79100a6@dwillia2-mobl4.notmuch> (raw)
In-Reply-To: <20250923075302.591026-6-tzungbi@kernel.org>
Tzung-Bi Shih wrote:
> Introduce revocable_replace_fops() 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@kernel.org>
[..]
> +/**
> + * revocable_replace_fops() - Replace the file operations to be revocable-aware.
> + *
> + * Should be used only from ->open() instances.
> + */
> +int revocable_replace_fops(struct file *filp, struct revocable_provider *rp,
> + const struct revocable_operations *rops)
> +{
> + struct fops_replacement *fr;
> +
> + fr = kzalloc(sizeof(*fr), GFP_KERNEL);
> + if (!fr)
> + return -ENOMEM;
> +
> + fr->filp = filp;
> + fr->rops = rops;
> + fr->orig_fops = filp->f_op;
> + fr->rev = revocable_alloc(rp);
> + if (!fr->rev)
> + return -ENOMEM;
> + memcpy(&fr->fops, filp->f_op, sizeof(struct file_operations));
> + scoped_guard(mutex, &fops_replacement_mutex)
> + list_add(&fr->list, &fops_replacement_list);
This list grows for every active instance? Unless I am misreading, that
looks like a scaling burden that the simple approach below does not
have.
> + fr->fops.release = revocable_fr_release;
> +
> + if (filp->f_op->read)
> + fr->fops.read = revocable_fr_read;
> + if (filp->f_op->poll)
> + fr->fops.poll = revocable_fr_poll;
> + if (filp->f_op->unlocked_ioctl)
> + fr->fops.unlocked_ioctl = revocable_fr_unlocked_ioctl;
> +
> + filp->f_op = &fr->fops;
> + return 0;
> +}
This facility is protecting the wrong resource, and I argue hides bugs
in drivers that think they need this. That matches the conclusion I came
to with my "managed_fops" attempt.
The resource that is being revoked is the device's attachment to its
driver. Whether that is dev_get_drvdata() or some other device-to-data
lookup, that is the resource that gets removed, not the fops themselves.
The only resource race with fops is whether the code text section
remains available while the fops are registered, but that lifetime scope
is not at a per-device instance scope.
revocable() could be useful for more complicated scenarios, but for
making sure that ->unlocked_ioctl(), ->poll(), and ->read() start
reliably failing, just do:
guard(rwsem_read)(&subsystem_device_registration_lock);
data = subsystem_lookup_device_relative_data(...)
if (data)
return subsystem_{ioctl,poll,read}(data, ...);
return -ENXIO;
...and revoke future subsystem_{ioctl,poll,read}() invocations by making
subsystem_lookup_device_relative_data() start failing under
guard(rwsem_write)(&subsystem_device_registration_lock).
next prev parent reply other threads:[~2025-09-24 20:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 7:52 [PATCH v4 0/7] platform/chrome: Fix a possible UAF via revocable Tzung-Bi Shih
2025-09-23 7:52 ` [PATCH v4 1/7] revocable: Revocable resource management Tzung-Bi Shih
2025-09-23 7:52 ` [PATCH v4 2/7] revocable: Add Kunit test cases Tzung-Bi Shih
2025-09-23 7:52 ` [PATCH v4 3/7] selftests: revocable: Add kselftest cases Tzung-Bi Shih
2025-09-23 7:52 ` [PATCH v4 4/7] platform/chrome: Protect cros_ec_device lifecycle with revocable Tzung-Bi Shih
2025-09-23 7:53 ` [PATCH v4 5/7] revocable: Add fops replacement Tzung-Bi Shih
2025-09-24 20:54 ` dan.j.williams [this message]
2025-10-01 14:23 ` Tzung-Bi Shih
2025-09-23 7:53 ` [PATCH v4 6/7] char: misc: Leverage revocable " Tzung-Bi Shih
2025-09-23 7:53 ` [PATCH v4 7/7] platform/chrome: cros_ec_chardev: Secure cros_ec_device via revocable Tzung-Bi Shih
2025-09-23 8:29 ` Tzung-Bi Shih
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=68d45a76a36ad_1c79100a6@dwillia2-mobl4.notmuch \
--to=dan.j.williams@intel.com \
--cc=bleung@chromium.org \
--cc=brgl@bgdev.pl \
--cc=chrome-platform@lists.linux.dev \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=dawidn@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=shuah@kernel.org \
--cc=tzungbi@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/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