]> www.infradead.org Git - users/willy/linux.git/commitdiff
USB: properly lock dynamic id list when showing an id
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Nov 2024 06:49:23 +0000 (07:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 14 Nov 2024 16:05:25 +0000 (17:05 +0100)
When walking the list of dynamic ids for a driver, no lock was being
held, which meant that an id could be removed or added while the list
was being iterated.  Fix this up by properly grabing the lock while we
walk the list.

Reported-by: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-usb@vger.kernel.org
Link: https://lore.kernel.org/r/2024111324-tubby-facecloth-d4a0@gregkh
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/driver.c

index bc3c00580238d7a682d592e5e0d6391644599d9f..9ea955a3d115112f9d51772c029ddab8bda4858f 100644 (file)
@@ -116,6 +116,7 @@ ssize_t usb_show_dynids(struct usb_dynids *dynids, char *buf)
        struct usb_dynid *dynid;
        size_t count = 0;
 
+       guard(mutex)(&usb_dynids_lock);
        list_for_each_entry(dynid, &dynids->list, node)
                if (dynid->id.bInterfaceClass != 0)
                        count += scnprintf(&buf[count], PAGE_SIZE - count, "%04x %04x %02x\n",