All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Balasubramani Vivekanandan" <balasubramani.vivekanandan@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH] drm/xe/i2c: Fix use-after-free on driver unload
Date: Fri, 09 Oct 2026 16:47:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-165849@kernel.org> (raw)
In-Reply-To: <20261009164241.923756-2-balasubramani.vivekanandan@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/xe/i2c: UAF on client devices when i2c_designware is unbound
--

commit acaaddc70630047a3af20f747eb4eed375a715a1
Author: Balasubramani Vivekanandan <balasubramani.vivekanandan@intel.com>

drm/xe/i2c: Fix use-after-free on driver unload

This patch fixes a use-after-free during driver unload by replacing the managed
software node with a static struct software_node. It also modifies
xe_i2c_notifier() to match against the parent device instead of using i2c->dev,
removing a dependency in the two-step platform device creation sequence.

> diff --git a/drivers/gpu/drm/xe/xe_i2c.c b/drivers/gpu/drm/xe/xe_i2c.c
> index f4f3819882897..f0566129b7e70 100644
> --- a/drivers/gpu/drm/xe/xe_i2c.c
> +++ b/drivers/gpu/drm/xe/xe_i2c.c
[ ... ]
> @@ -98,7 +102,7 @@ static int xe_i2c_notifier(struct notifier_block *nb, unsigned long action, void
>  	struct device *dev = data;
>  
>  	if (action == BUS_NOTIFY_ADD_DEVICE &&
> -	    adapter && dev->parent == &i2c->pdev->dev) {
> +	    adapter && dev->parent && dev->parent->parent == i2c->drm_dev) {
>  		i2c->adapter = adapter;
>  		schedule_work(&i2c->work);
>  		return NOTIFY_OK;
>  	}
>  
>  	return NOTIFY_DONE;
>  }

[Severity: High]
Does this missing BUS_NOTIFY_DEL_DEVICE handler leave dangling pointers if the
i2c-designware driver is manually unbound? 

If the adapter is unbound (e.g. via sysfs), the I2C core will unregister and
free all connected I2C client devices. Because this notifier doesn't handle
device removal, i2c->adapter and i2c->client[i] are never cleared and become
dangling pointers.

Later during module teardown, the xe_i2c_remove() devm action executes:

drivers/gpu/drm/xe/xe_i2c.c:xe_i2c_remove() {
	...
	for (i = 0; i < XE_I2C_MAX_CLIENTS; i++) {
		i2c_unregister_device(i2c->client[i]);
		i2c->client[i] = NULL;
	}
	...
}

Will this explicitly call i2c_unregister_device() on already freed client
pointers, causing a use-after-free crash? Additionally, if the unbind occurs
before xe_i2c_client_work() executes, could the workqueue dereference the freed
i2c->adapter pointer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261009164241.923756-2-balasubramani.vivekanandan@intel.com?part=1

  parent reply	other threads:[~2026-10-09 16:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 16:42 [PATCH] drm/xe/i2c: Fix use-after-free on driver unload Balasubramani Vivekanandan
2026-10-09 16:42 ` ✗ CI.checkpatch: warning for " Patchwork
2026-10-09 16:44 ` ✓ CI.KUnit: success " Patchwork
2026-10-09 16:47 ` sashiko-bot [this message]
2026-10-12 12:25   ` [PATCH] " Vivekanandan, Balasubramani
2026-10-09 18:19 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-10-09 21:19 ` ✓ Xe.CI.FULL: " Patchwork
2026-10-10 20:14 ` [PATCH] " Danilo Krummrich
2026-10-12 12:15   ` Vivekanandan, Balasubramani
2026-10-12 11:46 ` Kumar G, Naresh
2026-10-12 13:16   ` 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=sashiko-outbox-165849@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=balasubramani.vivekanandan@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.