]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: atm: ueagle-atm: wait for pre-firmware load in .disconnect()
authorMauricio Faria de Oliveira <mfo@igalia.com>
Tue, 26 May 2026 17:09:44 +0000 (14:09 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jun 2026 15:03:39 +0000 (16:03 +0100)
ueagle-atm uses the asynchronous request_firmware_nowait() in .probe(),
but does not wait for its completion, not even in .disconnect(); so, if the
device is unplugged meanwhile, its teardown runs concurrently with that.

Even though this inconsistency is worth addressing on its own, it has also
triggered several bug reports in syzbot over the years (some auto-closed)
where the firmware sysfs fallback mechanism (CONFIG_FW_LOADER_USER_HELPER)
creates a firmware subdirectory in the device directory during its removal,
which might hit unexpected conditions in kernfs, apparently, depending at
which point the add and remove operations raced. (See links.)

The pattern is:

usb ?-?: Direct firmware load for ueagle-atm/eagle?.fw failed with error -2
usb ?-?: Falling back to sysfs fallback for: ueagle-atm/eagle?.fw
<ERROR>
Call trace:
 ...
 kernfs_create_dir_ns
 sysfs_create_dir_ns
 create_dir
 kobject_add_internal
 kobject_add_varg
 kobject_add
 class_dir_create_and_add
 get_device_parent
 device_add
 fw_load_sysfs_fallback
 fw_load_from_user_helper
 firmware_fallback_sysfs
 _request_firmware
 request_firmware_work_func
 ...

(Some variations are observed, after fw_load_sysfs_fallback(), e.g., [1].)

While the kernfs side is being looked at, the ueagle-atm side can be fixed
by waiting for the pre-firmware load in the .disconnect() handler.

This change has a similar approach to previous work by Andrey Tsygunka [2]
(wait_for_completion() in .disconnect()), but it is relatively different in
design/implementation; using the Originally-by tag for credit assignment.

This has been tested with:
- synthetic reproducer to check the error path;
- USB gadget (virtual device) to check the firmware upload path;
- QEMU device emulator to check the device ID re-enumeration path;
(The latter two were written by Claude; no other code/text in this commit.)

Links (year first reported):
 2025 https://syzbot.org/bug?extid=ce1e5a1b4e086b43e56d
 2025 https://syzbot.org/bug?extid=9af8471255ac36e34fd4
 2024 https://syzbot.org/bug?extid=306212936b13e520679d
 2023 https://syzkaller.appspot.com/bug?extid=457452d30bcdda75ead2
 2022 https://syzbot.org/bug?extid=782984d6f1701b526edb
 2021 https://syzbot.org/bug?id=f3f221579f4ef7e9691281f3c6f56c05f83e8490
 2021 https://syzbot.org/bug?id=84d86f0d71394829df6fc53daf6642c045983881
 2021 https://syzbot.org/bug?id=3302dc1c0e2b9c94f2e8edb404eabc9267bc6f90

[1] https://syzkaller.appspot.com/bug?extid=457452d30bcdda75ead2
[2] https://lore.kernel.org/lkml/20250410093146.3776801-2-aitsygunka@yandex.ru/

Cc: stable <stable@kernel.org>
Reported-by: syzbot+ce1e5a1b4e086b43e56d@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=ce1e5a1b4e086b43e56d
Reported-by: syzbot+306212936b13e520679d@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=306212936b13e520679d
Reported-by: syzbot+457452d30bcdda75ead2@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=457452d30bcdda75ead2
Originally-by: Andrey Tsygunka <aitsygunka@yandex.ru>
Fixes: b72458a80c75 ("[PATCH] USB: Eagle and ADI 930 usb adsl modem driver")
Assisted-by: Claude:claude-opus-4.7 # usb gadget & qemu device for testing
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
Acked-by: Stanislaw Gruszka <stf_xl@wp.pl>
Link: https://patch.msgid.link/20260526-ueagle-atm_req-fw-sync-v3-1-93c01961daaf@igalia.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/atm/ueagle-atm.c

index d610cdcef7d0921444e8be9808f986b2411d1d73..4e71ed679a76121694a5d17119717de29ea9f295 100644 (file)
@@ -594,7 +594,9 @@ static int uea_send_modem_cmd(struct usb_device *usb,
 static void uea_upload_pre_firmware(const struct firmware *fw_entry,
                                                                void *context)
 {
-       struct usb_device *usb = context;
+       struct usb_interface *intf = context;
+       struct usb_device *usb = interface_to_usbdev(intf);
+       struct completion *fw_done = usb_get_intfdata(intf);
        const u8 *pfw;
        u8 value;
        u32 crc = 0;
@@ -663,15 +665,17 @@ err_fw_corrupted:
        uea_err(usb, "firmware is corrupted\n");
 err:
        release_firmware(fw_entry);
+       complete(fw_done);
 }
 
 /*
  * uea_load_firmware - Load usb firmware for pre-firmware devices.
  */
-static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
+static int uea_load_firmware(struct usb_interface *intf, unsigned int ver)
 {
        int ret;
        char *fw_name = EAGLE_FIRMWARE;
+       struct usb_device *usb = interface_to_usbdev(intf);
 
        uea_info(usb, "pre-firmware device, uploading firmware\n");
 
@@ -694,7 +698,7 @@ static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
        }
 
        ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
-                                       GFP_KERNEL, usb,
+                                       GFP_KERNEL, intf,
                                        uea_upload_pre_firmware);
        if (ret)
                uea_err(usb, "firmware %s is not available\n", fw_name);
@@ -2555,8 +2559,23 @@ static int uea_probe(struct usb_interface *intf, const struct usb_device_id *id)
 
        usb_reset_device(usb);
 
-       if (UEA_IS_PREFIRM(id))
-               return uea_load_firmware(usb, UEA_CHIP_VERSION(id));
+       if (UEA_IS_PREFIRM(id)) {
+               struct completion *fw_done;
+
+               /* Wait for the firmware load to be done, in .disconnect() */
+               fw_done = kzalloc_obj(*fw_done);
+               if (!fw_done)
+                       return -ENOMEM;
+
+               init_completion(fw_done);
+               usb_set_intfdata(intf, fw_done);
+
+               ret = uea_load_firmware(intf, UEA_CHIP_VERSION(id));
+               if (ret)
+                       kfree(fw_done);
+
+               return ret;
+       }
 
        ret = usbatm_usb_probe(intf, id, &uea_usbatm_driver);
        if (ret == 0) {
@@ -2586,6 +2605,13 @@ static void uea_disconnect(struct usb_interface *intf)
                usbatm_usb_disconnect(intf);
                mutex_unlock(&uea_mutex);
                uea_info(usb, "ADSL device removed\n");
+       } else if (usb->config->desc.bNumInterfaces == 1) {
+               struct completion *fw_done = usb_get_intfdata(intf);
+
+               uea_dbg(usb, "pre-firmware device, waiting firmware upload\n");
+               wait_for_completion(fw_done);
+               uea_dbg(usb, "pre-firmware device, finished waiting\n");
+               kfree(fw_done);
        }
 }