The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] firmware_loader: do not queue completed sysfs fallback requests
@ 2026-07-16  8:16 Mukesh Ojha
  2026-08-03 18:12 ` Mukesh Ojha
  2026-08-06 21:38 ` Danilo Krummrich
  0 siblings, 2 replies; 5+ messages in thread
From: Mukesh Ojha @ 2026-07-16  8:16 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Danilo Krummrich,
	Greg Kroah-Hartman, Rafael J. Wysocki, Anirudh Rayabharam,
	Shuah Khan
  Cc: driver-core, linux-kernel, Mukesh Ojha

fw_load_sysfs_fallback() calls device_add() before adding the fw_priv to
pending_fw_head. device_add() publishes the fallback loading interface, so
a userspace helper which discovers the device by scanning sysfs can write 0
to the loading attribute and complete the request before it is queued as
pending.

In that interleaving firmware_loading_store() calls fw_state_done() while
pending_list still points to itself, so it cannot remove an entry from
pending_fw_head. The subsequent unconditional list_add() then queues an
already-completed fw_priv. Once the request is released, pending_fw_head
can retain a pointer to freed memory and the next fallback request can
fault while validating the list.

Only in-flight fallback requests need suspend or reboot abort handling. If
the request is already DONE after device_add(), return success from the
fallback path without sending another uevent, waiting again, or queueing it
as pending. This preserves the invariant that pending_fw_head contains only
active fallback requests.

Fixes: 75d95e2e39b2 ("firmware_loader: fix use-after-free in firmware_fallback_sysfs")
Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
---
 drivers/base/firmware_loader/fallback.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
index 3ef0b312ae71..ffe1b3784788 100644
--- a/drivers/base/firmware_loader/fallback.c
+++ b/drivers/base/firmware_loader/fallback.c
@@ -95,6 +95,15 @@ static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, long timeout)
 		retval = -EINTR;
 		goto out;
 	}
+	/*
+	 * device_add() exposes the loading interface before pending_list is
+	 * linked into pending_fw_head, so fw_state_done() may run first.
+	 */
+	if (fw_state_is_done(fw_priv)) {
+		mutex_unlock(&fw_lock);
+		goto out;
+	}
+
 	list_add(&fw_priv->pending_list, &pending_fw_head);
 	mutex_unlock(&fw_lock);
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] firmware_loader: do not queue completed sysfs fallback requests
  2026-07-16  8:16 [PATCH] firmware_loader: do not queue completed sysfs fallback requests Mukesh Ojha
@ 2026-08-03 18:12 ` Mukesh Ojha
  2026-08-03 18:40   ` Danilo Krummrich
  2026-08-06 21:38 ` Danilo Krummrich
  1 sibling, 1 reply; 5+ messages in thread
From: Mukesh Ojha @ 2026-08-03 18:12 UTC (permalink / raw)
  To: Luis Chamberlain, Russ Weight, Danilo Krummrich,
	Greg Kroah-Hartman, Rafael J. Wysocki, Anirudh Rayabharam,
	Shuah Khan
  Cc: driver-core, linux-kernel

On Thu, Jul 16, 2026 at 01:46:01PM +0530, Mukesh Ojha wrote:
> fw_load_sysfs_fallback() calls device_add() before adding the fw_priv to
> pending_fw_head. device_add() publishes the fallback loading interface, so
> a userspace helper which discovers the device by scanning sysfs can write 0
> to the loading attribute and complete the request before it is queued as
> pending.
> 
> In that interleaving firmware_loading_store() calls fw_state_done() while
> pending_list still points to itself, so it cannot remove an entry from
> pending_fw_head. The subsequent unconditional list_add() then queues an
> already-completed fw_priv. Once the request is released, pending_fw_head
> can retain a pointer to freed memory and the next fallback request can
> fault while validating the list.
> 
> Only in-flight fallback requests need suspend or reboot abort handling. If
> the request is already DONE after device_add(), return success from the
> fallback path without sending another uevent, waiting again, or queueing it
> as pending. This preserves the invariant that pending_fw_head contains only
> active fallback requests.
> 
> Fixes: 75d95e2e39b2 ("firmware_loader: fix use-after-free in firmware_fallback_sysfs")
> Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>

Can we consider this fix for this mentioned issue ?

> ---
>  drivers/base/firmware_loader/fallback.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
> index 3ef0b312ae71..ffe1b3784788 100644
> --- a/drivers/base/firmware_loader/fallback.c
> +++ b/drivers/base/firmware_loader/fallback.c
> @@ -95,6 +95,15 @@ static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, long timeout)
>  		retval = -EINTR;
>  		goto out;
>  	}
> +	/*
> +	 * device_add() exposes the loading interface before pending_list is
> +	 * linked into pending_fw_head, so fw_state_done() may run first.
> +	 */
> +	if (fw_state_is_done(fw_priv)) {
> +		mutex_unlock(&fw_lock);
> +		goto out;
> +	}
> +
>  	list_add(&fw_priv->pending_list, &pending_fw_head);
>  	mutex_unlock(&fw_lock);
>  
> -- 
> 2.53.0
> 

-- 
-Mukesh Ojha

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] firmware_loader: do not queue completed sysfs fallback requests
  2026-08-03 18:12 ` Mukesh Ojha
@ 2026-08-03 18:40   ` Danilo Krummrich
  2026-08-04 13:29     ` Mukesh Ojha
  0 siblings, 1 reply; 5+ messages in thread
From: Danilo Krummrich @ 2026-08-03 18:40 UTC (permalink / raw)
  To: Mukesh Ojha
  Cc: Luis Chamberlain, Russ Weight, Greg Kroah-Hartman,
	Rafael J. Wysocki, Anirudh Rayabharam, Shuah Khan, driver-core,
	linux-kernel

On Mon Aug 3, 2026 at 8:12 PM CEST, Mukesh Ojha wrote:
> On Thu, Jul 16, 2026 at 01:46:01PM +0530, Mukesh Ojha wrote:
>> fw_load_sysfs_fallback() calls device_add() before adding the fw_priv to
>> pending_fw_head. device_add() publishes the fallback loading interface, so
>> a userspace helper which discovers the device by scanning sysfs can write 0
>> to the loading attribute and complete the request before it is queued as
>> pending.
>> 
>> In that interleaving firmware_loading_store() calls fw_state_done() while
>> pending_list still points to itself, so it cannot remove an entry from
>> pending_fw_head. The subsequent unconditional list_add() then queues an
>> already-completed fw_priv. Once the request is released, pending_fw_head
>> can retain a pointer to freed memory and the next fallback request can
>> fault while validating the list.
>> 
>> Only in-flight fallback requests need suspend or reboot abort handling. If
>> the request is already DONE after device_add(), return success from the
>> fallback path without sending another uevent, waiting again, or queueing it
>> as pending. This preserves the invariant that pending_fw_head contains only
>> active fallback requests.
>> 
>> Fixes: 75d95e2e39b2 ("firmware_loader: fix use-after-free in firmware_fallback_sysfs")
>> Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
>
> Can we consider this fix for this mentioned issue ?

Sure, how did you come across this issue?

>> ---
>>  drivers/base/firmware_loader/fallback.c | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>> 
>> diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
>> index 3ef0b312ae71..ffe1b3784788 100644
>> --- a/drivers/base/firmware_loader/fallback.c
>> +++ b/drivers/base/firmware_loader/fallback.c
>> @@ -95,6 +95,15 @@ static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, long timeout)
>>  		retval = -EINTR;
>>  		goto out;
>>  	}
>> +	/*
>> +	 * device_add() exposes the loading interface before pending_list is
>> +	 * linked into pending_fw_head, so fw_state_done() may run first.
>> +	 */
>> +	if (fw_state_is_done(fw_priv)) {
>> +		mutex_unlock(&fw_lock);
>> +		goto out;
>> +	}
>> +
>>  	list_add(&fw_priv->pending_list, &pending_fw_head);
>>  	mutex_unlock(&fw_lock);
>>  
>> -- 
>> 2.53.0
>> 
>
> -- 
> -Mukesh Ojha


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] firmware_loader: do not queue completed sysfs fallback requests
  2026-08-03 18:40   ` Danilo Krummrich
@ 2026-08-04 13:29     ` Mukesh Ojha
  0 siblings, 0 replies; 5+ messages in thread
From: Mukesh Ojha @ 2026-08-04 13:29 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: Luis Chamberlain, Russ Weight, Greg Kroah-Hartman,
	Rafael J. Wysocki, Anirudh Rayabharam, Shuah Khan, driver-core,
	linux-kernel

On Mon, Aug 03, 2026 at 08:40:06PM +0200, Danilo Krummrich wrote:
> On Mon Aug 3, 2026 at 8:12 PM CEST, Mukesh Ojha wrote:
> > On Thu, Jul 16, 2026 at 01:46:01PM +0530, Mukesh Ojha wrote:
> >> fw_load_sysfs_fallback() calls device_add() before adding the fw_priv to
> >> pending_fw_head. device_add() publishes the fallback loading interface, so
> >> a userspace helper which discovers the device by scanning sysfs can write 0
> >> to the loading attribute and complete the request before it is queued as
> >> pending.
> >> 
> >> In that interleaving firmware_loading_store() calls fw_state_done() while
> >> pending_list still points to itself, so it cannot remove an entry from
> >> pending_fw_head. The subsequent unconditional list_add() then queues an
> >> already-completed fw_priv. Once the request is released, pending_fw_head
> >> can retain a pointer to freed memory and the next fallback request can
> >> fault while validating the list.
> >> 
> >> Only in-flight fallback requests need suspend or reboot abort handling. If
> >> the request is already DONE after device_add(), return success from the
> >> fallback path without sending another uevent, waiting again, or queueing it
> >> as pending. This preserves the invariant that pending_fw_head contains only
> >> active fallback requests.
> >> 
> >> Fixes: 75d95e2e39b2 ("firmware_loader: fix use-after-free in firmware_fallback_sysfs")
> >> Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
> >
> > Can we consider this fix for this mentioned issue ?
> 
> Sure, how did you come across this issue?

with Kasan with some fuzzing.

-Mukesh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] firmware_loader: do not queue completed sysfs fallback requests
  2026-07-16  8:16 [PATCH] firmware_loader: do not queue completed sysfs fallback requests Mukesh Ojha
  2026-08-03 18:12 ` Mukesh Ojha
@ 2026-08-06 21:38 ` Danilo Krummrich
  1 sibling, 0 replies; 5+ messages in thread
From: Danilo Krummrich @ 2026-08-06 21:38 UTC (permalink / raw)
  To: Mukesh Ojha
  Cc: Luis Chamberlain, Russ Weight, Danilo Krummrich,
	Greg Kroah-Hartman, Rafael J . Wysocki, Anirudh Rayabharam,
	Shuah Khan, driver-core, linux-kernel

On Thu, 16 Jul 2026 13:46:01 +0530, Mukesh Ojha wrote:
> [PATCH] firmware_loader: do not queue completed sysfs fallback requests

Applied, thanks!

  Branch: driver-core-testing
  Tree:   git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

[1/1] firmware_loader: do not queue completed sysfs fallback requests
      commit: b48373c90195

The patch will appear in the next linux-next integration (typically within 24
hours on weekdays).

The patch is in the driver-core-testing branch and will be promoted to
driver-core-next after validation.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-06 21:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16  8:16 [PATCH] firmware_loader: do not queue completed sysfs fallback requests Mukesh Ojha
2026-08-03 18:12 ` Mukesh Ojha
2026-08-03 18:40   ` Danilo Krummrich
2026-08-04 13:29     ` Mukesh Ojha
2026-08-06 21:38 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox