Linux I2C development
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Balasubramani Vivekanandan" <balasubramani.vivekanandan@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <rodrigo.vivi@intel.com>,
	"Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>,
	"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
	"Andi Shyti" <andi.shyti@kernel.org>, <linux-i2c@vger.kernel.org>,
	<driver-core@lists.linux.dev>
Subject: Re: [PATCH] drm/xe/i2c: Fix use-after-free on driver unload
Date: Sat, 10 Oct 2026 22:14:44 +0200	[thread overview]
Message-ID: <DM1FMM3KEYU9.1D26IINII93FO@kernel.org> (raw)
In-Reply-To: <20261009164241.923756-2-balasubramani.vivekanandan@intel.com>

(Cc: i2c, driver-core)

On Fri Oct 9, 2026 at 6:42 PM CEST, Balasubramani Vivekanandan wrote:
> The kernel crashes when unloading the xe driver on CRI:
>
>  Oops: general protection fault, probably for non-canonical address 0x6b6b6b6b6b6b6b73
>  RIP: 0010:platform_device_release+0x80/0x90
>  Call Trace:
>   device_release+0x44/0xa0
>   kobject_put+0x9b/0x250
>   put_device+0x13/0x30
>   platform_device_unregister+0x29/0x40
>   xe_i2c_remove+0x80/0xa0 [xe]
>   devm_action_release+0x16/0x30
>   release_nodes+0x3d/0x140
>   devres_release_all+0x96/0xd0
>
> This started after commit 0f485f88656af ("drm/xe/i2c: use
> device_create_managed_software_node()"), which attaches a managed
> software node to a platform device created with platform_device_alloc().
>
> Comment above the device_create_managed_software_node function cautions
> that the software node created by it should not be shared or reused as
> the lifetime of the node is linked to the device.

Yes, it does not distinguish between provider and consumer and hence always
calls swnode_put() in the managed path of software_node_notify_remove().

This seems to be a bit of a footgun, and I think we should address this.

> But the DesignWare i2c driver which creates an adapter device as a child
> of the platform device reuses the software node as its fwnode.
> (device_set_node() in i2c_dw_probe()).
>
> During module unbind, when the adapter device is deleted, it drops the
> reference count for the software node and frees the software node.
> Later when the platform device is removed, it tries to dereference the
> software node pointer and results in use-after-free.
>
> Instead of managed software node use a static struct software_node
> passed through platform_device_info.swnode to
> platform_device_register_full().
> But we have a blocker which doesn't allow to use
> platform_device_register_full() simply.

I think this works out as the I2C adapter and hence its children are destroyed
when the platform device is unregistered.

But also note that technically this approach has some friction in its lifetime
model: The software node pointer stored only lives as long as the Xe module and
becomes invalid after module unload. The structures this pointer is shared with
are reference counted though and could technically be longer lived.

Thanks,
Danilo

       reply	other threads:[~2026-10-10 20:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261009164241.923756-2-balasubramani.vivekanandan@intel.com>
2026-10-10 20:14 ` Danilo Krummrich [this message]
2026-10-12 12:15   ` [PATCH] drm/xe/i2c: Fix use-after-free on driver unload Vivekanandan, Balasubramani

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=DM1FMM3KEYU9.1D26IINII93FO@kernel.org \
    --to=dakr@kernel.org \
    --cc=andi.shyti@kernel.org \
    --cc=balasubramani.vivekanandan@intel.com \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=driver-core@lists.linux.dev \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=rodrigo.vivi@intel.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