Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Maarten Lankhorst <dev@lankhorst.se>, linux-kernel@vger.kernel.org
Cc: intel-xe@lists.freedesktop.org,
	Mukesh Ojha <quic_mojha@quicinc.com>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich	 <dakr@kernel.org>,
	stable@vger.kernel.org, Matthew Brost <matthew.brost@intel.com>
Subject: Re: [PATCH] devcoredump: Fix circular locking dependency with devcd->mutex.
Date: Fri, 24 Oct 2025 10:12:19 +0200	[thread overview]
Message-ID: <e683355a9a9f700d98ae0a057063a975bb11fadc.camel@sipsolutions.net> (raw)
In-Reply-To: <20250723142416.1020423-1-dev@lankhorst.se>

On Wed, 2025-07-23 at 16:24 +0200, Maarten Lankhorst wrote:
> 
> +static void __devcd_del(struct devcd_entry *devcd)
> +{
> +	devcd->deleted = true;
> +	device_del(&devcd->devcd_dev);
> +	put_device(&devcd->devcd_dev);
> +}
> +
>  static void devcd_del(struct work_struct *wk)
>  {
>  	struct devcd_entry *devcd;
> +	bool init_completed;
>  
>  	devcd = container_of(wk, struct devcd_entry, del_wk.work);
>  
> -	device_del(&devcd->devcd_dev);
> -	put_device(&devcd->devcd_dev);
> +	/* devcd->mutex serializes against dev_coredumpm_timeout */
> +	mutex_lock(&devcd->mutex);
> +	init_completed = devcd->init_completed;
> +	mutex_unlock(&devcd->mutex);
> +
> +	if (init_completed)
> +		__devcd_del(devcd);

I'm not sure I understand this completely right now. I think you pull
this out of the mutex because otherwise the unlock could/would be UAF,
right?

But also we have this:

> @@ -151,11 +160,21 @@ static int devcd_free(struct device *dev, void *data)
>  {
>  	struct devcd_entry *devcd = dev_to_devcd(dev);
>  
> +	/*
> +	 * To prevent a race with devcd_data_write(), disable work and
> +	 * complete manually instead.
> +	 *
> +	 * We cannot rely on the return value of
> +	 * disable_delayed_work_sync() here, because it might be in the
> +	 * middle of a cancel_delayed_work + schedule_delayed_work pair.
> +	 *
> +	 * devcd->mutex here guards against multiple parallel invocations
> +	 * of devcd_free().
> +	 */
> +	disable_delayed_work_sync(&devcd->del_wk);
>  	mutex_lock(&devcd->mutex);
> -	if (!devcd->delete_work)
> -		devcd->delete_work = true;
> -
> -	flush_delayed_work(&devcd->del_wk);
> +	if (!devcd->deleted)
> +		__devcd_del(devcd);
>  	mutex_unlock(&devcd->mutex);

^^^^

Which I _think_ is probably OK because devcd_free is only called with an
extra reference held (for each/find device.)

But ... doesn't that then still have unbalanced calls to __devcd_del()
and thus device_del()/put_device()?

CPU 0				CPU 1

dev_coredump_put()		devcd_del()
 -> devcd_free()
   -> locked
     -> !deleted
     -> __devcd_del()
				-> __devcd_del()

no?

johannes

  parent reply	other threads:[~2025-10-24  8:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-23 14:24 [PATCH] devcoredump: Fix circular locking dependency with devcd->mutex Maarten Lankhorst
2025-07-23 17:53 ` ✗ CI.checkpatch: warning for devcoredump: Fix circular locking dependency with devcd->mutex. (rev3) Patchwork
2025-07-23 17:54 ` ✓ CI.KUnit: success " Patchwork
2025-07-23 19:20 ` ✓ Xe.CI.BAT: " Patchwork
2025-07-24  2:54 ` ✗ Xe.CI.Full: failure " Patchwork
2025-10-03 13:29 ` [PATCH] devcoredump: Fix circular locking dependency with devcd->mutex Maarten Lankhorst
2025-10-03 18:00 ` Mukesh Ojha
2025-10-06  9:11   ` Maarten Lankhorst
2025-10-06  9:24     ` Greg Kroah-Hartman
2025-10-24  8:12 ` Johannes Berg [this message]
2025-10-24  8:37   ` Maarten Lankhorst
2025-10-24  8:39     ` Johannes Berg
2025-10-24 10:27       ` Maarten Lankhorst

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=e683355a9a9f700d98ae0a057063a975bb11fadc.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=dakr@kernel.org \
    --cc=dev@lankhorst.se \
    --cc=gregkh@linuxfoundation.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=quic_mojha@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=stable@vger.kernel.org \
    /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