From: Johan Hovold <johan@kernel.org>
To: Bartosz Golaszewski <brgl@kernel.org>
Cc: Andi Shyti <andi.shyti@kernel.org>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2 1/3] i2c: dev: fix blocked adapter deregistration
Date: Tue, 10 Nov 2026 13:34:47 +0100 [thread overview]
Message-ID: <avMPZ5gB_k1KjpEe@hovoldconsulting.com> (raw)
In-Reply-To: <xkcyszlk7ce6rdfsbfihlu4gyi52kgimeftruspl4tdingjc74@llcpfjzkwbis>
On Mon, Nov 09, 2026 at 04:08:46PM +0100, Bartosz Golaszewski wrote:
> On Thu, Aug 27, 2026 at 12:20:41PM +0200, Johan Hovold wrote:
> > The I2C subsystem allows controllers to be used by non-child devices
> > that may remain registered after an adapter goes away.
> >
> > To handle this, adapter deregistration blocks until the last reference
> > to the adapter is released. Albeit unorthodox, this is mostly fine for
> > the vast majority of controllers but can cause some trouble when
> > controllers reside on hotpluggable buses.
> >
> > Specifically, userspace can prevent an adapter from being deregistered
> > indefinitely by holding an i2c-dev character device file open. And with
> > USB attached controllers this prevents further hub events from being
> > processed by the parent hub until the file is closed.
> >
> > Fix the i2c-dev implementation by dropping the additional reference
> > taken at open() and using an rwsem to make sure the adapter is only
> > accessed while registered.
> >
> > Note that before commit 611e12ea0f12 ("i2c: core: manage i2c bus device
> > refcount in i2c_[get|put]_adapter") an adapter going away would instead
> > have resulted in a use-after-free.
> >
> > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> > static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
> > loff_t *offset)
> > {
> > + struct i2c_dev_data *data = file->private_data;
> > + struct i2c_client *client = &data->client;
> > + struct i2c_dev *i2c_dev = data->i2c_dev;
> > char *tmp;
> > int ret;
> >
> > - struct i2c_client *client = file->private_data;
> > + guard(rwsem_read)(&i2c_dev->rwsem);
>
> I think sashiko is correct in its comment and you should limit the
> critical section to until right after i2c_master_recv(). Same elsewhere.
I don't think that's anything we need to care about. If a malicious
actor has physical access to the machine, we have bigger problems than
worrying about them going out of their way to cause a USB hub worker
thread to hang. :)
Johan
> [1] https://sashiko.dev/#/patchset/20260827102043.673273-1-johan%40kernel.org?part=1
next prev parent reply other threads:[~2026-11-10 12:34 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 10:20 [PATCH v2 0/3] " Johan Hovold
2026-08-27 10:20 ` [PATCH v2 1/3] " Johan Hovold
2026-11-09 15:08 ` Bartosz Golaszewski
2026-11-10 12:34 ` Johan Hovold [this message]
2026-08-27 10:20 ` [PATCH v2 2/3] i2c: dev: drop unnecessary sysfs device lookup Johan Hovold
2026-11-09 14:59 ` Bartosz Golaszewski
2026-11-10 11:46 ` Wolfram Sang
2026-08-27 10:20 ` [PATCH v2 3/3] i2c: dev: clean up registration Johan Hovold
2026-11-09 15:01 ` Bartosz Golaszewski
2026-11-10 11:50 ` Wolfram Sang
2026-11-10 12:42 ` Johan Hovold
2026-11-10 12:54 ` Bartosz Golaszewski
2026-11-10 13:07 ` Johan Hovold
2026-11-04 19:42 ` [PATCH v2 0/3] i2c: dev: fix blocked adapter deregistration Wolfram Sang
2026-11-05 8:18 ` Bartosz Golaszewski
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=avMPZ5gB_k1KjpEe@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=andi.shyti@kernel.org \
--cc=brgl@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.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
all inboxes | Powered by JetHome®