public inbox for linux-doc@vger.kernel.org
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: dan.j.williams@intel.com
Cc: Benson Leung <bleung@chromium.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	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,
	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, 1 Oct 2025 22:23:09 +0800	[thread overview]
Message-ID: <aN05TFvhPPj5voUD@tzungbi-laptop> (raw)
In-Reply-To: <68d45a76a36ad_1c79100a6@dwillia2-mobl4.notmuch>

On Wed, Sep 24, 2025 at 01:54:14PM -0700, dan.j.williams@intel.com wrote:
> Tzung-Bi Shih wrote:
> > +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.

Correct, unless we want to embed the context (e.g. struct fops_replacement)
into struct file.  FWIW: the issue also listed as a known issue after "---".

> > +	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_replace_fops() doesn't protect any resources.  It replaces the
fops to revocable wrappers and recovers the fops when the file is releasing.

  reply	other threads:[~2025-10-01 14:23 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
2025-10-01 14:23     ` Tzung-Bi Shih [this message]
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=aN05TFvhPPj5voUD@tzungbi-laptop \
    --to=tzungbi@kernel.org \
    --cc=bleung@chromium.org \
    --cc=brgl@bgdev.pl \
    --cc=chrome-platform@lists.linux.dev \
    --cc=corbet@lwn.net \
    --cc=dakr@kernel.org \
    --cc=dan.j.williams@intel.com \
    --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=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