composite_setup() answers the Microsoft OS 1.0 Extended Properties vendor request (bRequest = os_desc b_vendor_code, wIndex 5) by walking desc->ext_prop and copying each ext_prop->name/data into the ep0 buffer (fill_ext_prop()). It runs from the UDC's interrupt/softirq path with only gi->spinlock held (configfs_composite_setup()). The configfs side changes the same objects without that lock: ext_prop_data_store() frees ext_prop->data and installs a new buffer and data_len, ext_prop_type_store() changes type/data_len, ext_prop_make()/ext_prop_drop() add and remove the property from desc->ext_prop. The only lock they take, desc->opts_mutex, is NULL for every user (f_ncm, f_rndis). So a host that polls the descriptor while the gadget side rewrites a property reads freed memory. Reproduced with an ncm function with one property (type 3), the host polling the vendor request while configfs rewrites the property value: [ 34.913719][ C2] ================================================================== [ 34.913733][ C2] BUG: KASAN: slab-use-after-free in composite_setup+0x79d3/0x9130 [ 34.913758][ C2] Read of size 1800 at addr ffff888049cb5000 by task swapper/2/0 [ 34.913773][ C2] [ 34.913781][ C2] CPU: 2 UID: 0 PID: 0 Comm: swapper/2 Not tainted 7.4.0-rc3-g666539eecdf4 #1 PREEMPT(full) [ 34.913802][ C2] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 [ 34.913813][ C2] Call Trace: [ 34.913819][ C2] [ 34.913825][ C2] dump_stack_lvl+0x116/0x1b0 [ 34.913845][ C2] print_report+0xf1/0x5c0 [ 34.913869][ C2] ? __virt_addr_valid+0x238/0x430 [ 34.913894][ C2] ? composite_setup+0x79d3/0x9130 [ 34.913910][ C2] kasan_report+0xca/0x100 [ 34.913927][ C2] ? composite_setup+0x79d3/0x9130 [ 34.913944][ C2] kasan_check_range+0x39/0x1c0 [ 34.913964][ C2] __asan_memcpy+0x24/0x60 [ 34.913986][ C2] composite_setup+0x79d3/0x9130 [ 34.914007][ C2] ? __pfx_composite_setup+0x10/0x10 [ 34.914023][ C2] ? __pfx_do_raw_spin_lock+0x10/0x10 [ 34.914042][ C2] ? do_raw_spin_lock+0x12b/0x270 [ 34.914062][ C2] ? configfs_composite_setup+0x10f/0x150 [ 34.914083][ C2] configfs_composite_setup+0x10f/0x150 [ 34.914106][ C2] dummy_timer+0x12ce/0x35c0 [ 34.914126][ C2] ? find_held_lock+0x2b/0x80 [ 34.914148][ C2] ? do_raw_spin_unlock+0x147/0x1f0 [ 34.914169][ C2] ? find_held_lock+0x2b/0x80 [ 34.914189][ C2] ? __pfx_dummy_timer+0x10/0x10 [ 34.914207][ C2] ? _raw_spin_unlock_irqrestore+0x5a/0x70 [ 34.914233][ C2] __hrtimer_run_queues+0x17f/0xa00 [ 34.914259][ C2] ? __pfx_dummy_timer+0x10/0x10 [ 34.914279][ C2] hrtimer_run_softirq+0x1c9/0x360 [ 34.914306][ C2] handle_softirqs+0x20e/0x9e0 [ 34.914331][ C2] __irq_exit_rcu+0x184/0x240 [ 34.914352][ C2] irq_exit_rcu+0x9/0x30 [ 34.914373][ C2] sysvec_apic_timer_interrupt+0xa8/0xc0 [ 34.914398][ C2] [ 34.914403][ C2] [ 34.914409][ C2] asm_sysvec_apic_timer_interrupt+0x1a/0x20 [ 34.914428][ C2] RIP: 0010:pv_native_safe_halt+0x1e/0x30 [ 34.914454][ C2] Code: 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa 0f 1f 44 00 00 eb 0c 0f 1f 44 00 00 0f 00 2d 29 f8 15 00 0f 1f 44 00 00 fb f4 cc cc cc cc 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 90 90 90 90 [ 34.914471][ C2] RSP: 0018:ffffc9000048fdf8 EFLAGS: 00000202 [ 34.914486][ C2] RAX: 000000000002d99b RBX: ffff88801d15ddc0 RCX: ffffffff8bd63249 [ 34.914498][ C2] RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000 [ 34.914508][ C2] RBP: ffffed1003a2bbb8 R08: 0000000000000001 R09: ffffed10056a6825 [ 34.914519][ C2] R10: ffff88802b53412b R11: 0000000000000001 R12: dffffc0000000000 [ 34.914530][ C2] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 34.914543][ C2] ? ct_kernel_exit+0x1d9/0x240 [ 34.914560][ C2] default_idle+0xe/0x20 [ 34.914576][ C2] default_idle_call+0x6c/0xb0 [ 34.914593][ C2] do_idle+0x3c1/0x5c0 [ 34.914610][ C2] ? __pfx_do_idle+0x10/0x10 [ 34.914627][ C2] ? _raw_spin_unlock_irq_enable+0x120/0x160 [ 34.914654][ C2] ? lockdep_hardirqs_on+0x7d/0x110 [ 34.914681][ C2] cpu_startup_entry+0x4f/0x60 [ 34.914699][ C2] start_secondary+0x21d/0x2d0 [ 34.914723][ C2] ? __pfx_start_secondary+0x10/0x10 [ 34.914748][ C2] common_startup_64+0x13e/0x158 [ 34.914769][ C2] [ 34.914774][ C2] [ 34.914777][ C2] Allocated by task 9595: [ 34.914785][ C2] kasan_save_stack+0x24/0x50 [ 34.914809][ C2] kasan_save_track+0x14/0x30 [ 34.914832][ C2] __kasan_kmalloc+0xaa/0xb0 [ 34.914861][ C2] __kmalloc_node_track_caller_noprof+0x35c/0x840 [ 34.914884][ C2] kmemdup_noprof+0x2b/0x60 [ 34.914904][ C2] ext_prop_data_store+0xb4/0x300 [ 34.914920][ C2] configfs_write_iter+0x307/0x500 [ 34.914936][ C2] vfs_write+0xc11/0x1140 [ 34.914950][ C2] ksys_write+0x121/0x240 [ 34.914964][ C2] do_syscall_64+0x132/0x7c0 [ 34.914987][ C2] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 34.915002][ C2] [ 34.915006][ C2] Freed by task 9595: [ 34.915013][ C2] kasan_save_stack+0x24/0x50 [ 34.915036][ C2] kasan_save_track+0x14/0x30 [ 34.915059][ C2] kasan_save_free_info+0x3b/0x60 [ 34.915077][ C2] __kasan_slab_free+0x61/0x80 [ 34.915091][ C2] kfree+0x2ca/0x6e0 [ 34.915106][ C2] ext_prop_data_store+0x132/0x300 [ 34.915123][ C2] configfs_write_iter+0x307/0x500 [ 34.915137][ C2] vfs_write+0xc11/0x1140 [ 34.915150][ C2] ksys_write+0x121/0x240 [ 34.915164][ C2] do_syscall_64+0x132/0x7c0 [ 34.915187][ C2] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 34.915202][ C2] [ 34.915205][ C2] The buggy address belongs to the object at ffff888049cb5000 [ 34.915205][ C2] which belongs to the cache kmalloc-2k of size 2048 [ 34.915218][ C2] The buggy address is located 0 bytes inside of [ 34.915218][ C2] freed 2048-byte region [ffff888049cb5000, ffff888049cb5800) [ 34.915235][ C2] [ 34.915238][ C2] The buggy address belongs to the physical page: [ 34.915245][ C2] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0xffff888049cb2000 pfn:0x49cb0 [ 34.915261][ C2] head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 [ 34.915273][ C2] flags: 0x4fff00000000240(workingset|head|node=1|zone=1|lastcpupid=0x7ff) [ 34.915290][ C2] page_type: f5(slab) [ 34.915304][ C2] raw: 04fff00000000240 ffff88801d042f00 ffff888040400948 ffffea0001237e10 [ 34.915319][ C2] raw: ffff888049cb2000 0000000000080006 00000000f5000000 0000000000000000 [ 34.915334][ C2] head: 04fff00000000240 ffff88801d042f00 ffff888040400948 ffffea0001237e10 [ 34.915349][ C2] head: ffff888049cb2000 0000000000080006 00000000f5000000 0000000000000000 [ 34.915365][ C2] head: 04fff00000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff [ 34.915380][ C2] head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008 [ 34.915389][ C2] page dumped because: kasan: bad access detected [ 34.915396][ C2] page_owner tracks the page as allocated [ 34.915401][ C2] page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 9446, tgid 9446 (dhcpcd-run-hook), ts 30865730439 [ 34.915428][ C2] post_alloc_hook+0xff/0x130 [ 34.915444][ C2] get_page_from_freelist+0xdf0/0x2a10 [ 34.915462][ C2] __alloc_frozen_pages_noprof+0x28b/0x2dd0 [ 34.915481][ C2] new_slab+0xb9/0x6b0 [ 34.915498][ C2] refill_objects+0x10e/0x3d0 [ 34.915516][ C2] __pcs_replace_empty_main+0x35a/0x680 [ 34.915534][ C2] __kmalloc_noprof+0x68b/0x810 [ 34.915554][ C2] tomoyo_init_log+0x1329/0x1f00 [ 34.915571][ C2] tomoyo_supervisor+0x35b/0x1410 [ 34.915590][ C2] tomoyo_env_perm+0x185/0x200 [ 34.915610][ C2] tomoyo_find_next_domain+0x12d0/0x20c0 [ 34.915632][ C2] tomoyo_bprm_check_security+0x139/0x1d0 [ 34.915653][ C2] security_bprm_check+0x1d0/0x200 [ 34.915673][ C2] bprm_execve+0x824/0x1930 [ 34.915686][ C2] do_execveat_common.isra.0+0x480/0x5d0 [ 34.915701][ C2] __x64_sys_execve+0x93/0xd0 [ 34.915715][ C2] page last free pid 829 tgid 829 ts 29542408867 stack trace: [ 34.915725][ C2] __free_frozen_pages+0x75e/0x1190 [ 34.915740][ C2] qlist_free_all+0x4c/0xf0 [ 34.915761][ C2] kasan_quarantine_reduce+0x195/0x1e0 [ 34.915784][ C2] __kasan_slab_alloc+0x67/0x90 [ 34.915797][ C2] __kmalloc_cache_noprof+0x259/0x6e0 [ 34.915815][ C2] drm_atomic_commit_alloc+0xb9/0x120 [ 34.915831][ C2] drm_atomic_helper_dirtyfb+0xc3/0x790 [ 34.915847][ C2] drm_fbdev_shmem_helper_fb_dirty+0x1cc/0x360 [ 34.915878][ C2] drm_fb_helper_damage_work+0x4b1/0xa80 [ 34.915894][ C2] process_one_work+0xa97/0x1db0 [ 34.915913][ C2] worker_thread+0x693/0xeb0 [ 34.915931][ C2] kthread+0x390/0x4a0 [ 34.915947][ C2] ret_from_fork+0xb0c/0xdb0 [ 34.915969][ C2] ret_from_fork_asm+0x1a/0x30 [ 34.915989][ C2] [ 34.915992][ C2] Memory state around the buggy address: [ 34.916000][ C2] ffff888049cb4f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 34.916012][ C2] ffff888049cb4f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 34.916023][ C2] >ffff888049cb5000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 34.916032][ C2] ^ [ 34.916040][ C2] ffff888049cb5080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 34.916051][ C2] ffff888049cb5100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 34.916060][ C2] ================================================================== Removing and re-creating the property instead (rmdir + mkdir) makes the walk follow a list_del()ed entry: [ 32.896487][ C2] Oops: general protection fault, probably for non-canonical address 0xfbd59c0000000024: 0000 [#1] SMP KASAN NOPTI [ 32.898662][ C2] KASAN: maybe wild-memory-access in range [0xdead000000000120-0xdead000000000127] [ 32.900299][ C2] CPU: 2 UID: 0 PID: 0 Comm: swapper/2 Not tainted 7.4.0-rc3-g666539eecdf4 #1 PREEMPT(full) [ 32.902086][ C2] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014 [ 32.903725][ C2] RIP: 0010:composite_setup+0x749c/0x9130 [ 32.904752][ C2] Code: 08 44 8b a5 10 ff ff ff e8 b1 12 02 fa 48 3b 9d e0 fe ff ff 0f 84 81 06 00 00 e8 9f 12 02 fa 4c 8d 6b 20 4c 89 e8 48 c1 e8 03 <42> 0f b6 04 38 84 c0 74 08 3c 03 0f 8e 87 06 00 00 48 8d 7b 14 8b [ 32.908171][ C2] RSP: 0018:ffffc90000558ad0 EFLAGS: 00010016 [ 32.909264][ C2] RAX: 1bd5a00000000024 RBX: dead000000000100 RCX: 0000000000000102 [ 32.910664][ C2] RDX: ffff88801d145dc0 RSI: ffffffff87c168b1 RDI: ffff88804917e024 [ 32.912064][ C2] RBP: ffffc90000558c20 R08: 4141414141414141 R09: 4141414141414141 [ 32.913164][ C2] R10: 4141414141414141 R11: 4141414141414141 R12: 000000000000072c [ 32.914271][ C2] R13: dead000000000120 R14: ffff88804917e72c R15: dffffc0000000000 [ 32.915372][ C2] FS: 0000000000000000(0000) GS:ffff888095b93000(0000) knlGS:0000000000000000 [ 32.916603][ C2] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 32.917518][ C2] CR2: 00005599bf340828 CR3: 0000000048dca000 CR4: 0000000000350ef0 [ 32.918618][ C2] Call Trace: [ 32.919079][ C2] [ 32.919492][ C2] ? __pfx_composite_setup+0x10/0x10 [ 32.920238][ C2] ? __pfx_do_raw_spin_lock+0x10/0x10 [ 32.920990][ C2] ? do_raw_spin_lock+0x12b/0x270 [ 32.921703][ C2] ? configfs_composite_setup+0x10f/0x150 [ 32.922510][ C2] configfs_composite_setup+0x10f/0x150 [ 32.923295][ C2] dummy_timer+0x12ce/0x35c0 [ 32.923945][ C2] ? find_held_lock+0x2b/0x80 [ 32.924615][ C2] ? do_raw_spin_unlock+0x147/0x1f0 [ 32.925355][ C2] ? find_held_lock+0x2b/0x80 [ 32.926016][ C2] ? __pfx_dummy_timer+0x10/0x10 [ 32.926544][ C2] ? _raw_spin_unlock_irqrestore+0x5a/0x70 [ 32.927084][ C2] __hrtimer_run_queues+0x17f/0xa00 [ 32.927574][ C2] ? __pfx_dummy_timer+0x10/0x10 [ 32.928032][ C2] hrtimer_run_softirq+0x1c9/0x360 [ 32.928524][ C2] handle_softirqs+0x20e/0x9e0 [ 32.928972][ C2] __irq_exit_rcu+0x184/0x240 [ 32.929416][ C2] irq_exit_rcu+0x9/0x30 [ 32.929814][ C2] sysvec_apic_timer_interrupt+0xa8/0xc0 [ 32.930345][ C2] [ 32.930617][ C2] [ 32.930889][ C2] asm_sysvec_apic_timer_interrupt+0x1a/0x20 [ 32.931459][ C2] RIP: 0010:pv_native_safe_halt+0x1e/0x30 [ 32.931992][ C2] Code: 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa 0f 1f 44 00 00 eb 0c 0f 1f 44 00 00 0f 00 2d 29 f8 15 00 0f 1f 44 00 00 fb f4 cc cc cc cc 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 90 90 90 90 [ 32.933772][ C2] RSP: 0018:ffffc9000048fdf8 EFLAGS: 00000202 [ 32.934348][ C2] RAX: 0000000000037b43 RBX: ffff88801d145dc0 RCX: ffffffff8bd63249 [ 32.935080][ C2] RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000 [ 32.935932][ C2] RBP: ffffed1003a28bb8 R08: 0000000000000001 R09: ffffed10056a6825 [ 32.936773][ C2] R10: ffff88802b53412b R11: 0000000000000001 R12: dffffc0000000000 [ 32.937611][ C2] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 32.938444][ C2] ? ct_kernel_exit+0x1d9/0x240 [ 32.938959][ C2] default_idle+0xe/0x20 [ 32.939413][ C2] default_idle_call+0x6c/0xb0 [ 32.939918][ C2] do_idle+0x3c1/0x5c0 [ 32.940358][ C2] ? __pfx_do_idle+0x10/0x10 [ 32.940846][ C2] ? _raw_spin_unlock_irq_enable+0x120/0x160 [ 32.941485][ C2] ? lockdep_hardirqs_on+0x7d/0x110 [ 32.942040][ C2] cpu_startup_entry+0x4f/0x60 [ 32.942552][ C2] start_secondary+0x21d/0x2d0 [ 32.943063][ C2] ? __pfx_start_secondary+0x10/0x10 [ 32.943630][ C2] common_startup_64+0x13e/0x158 [ 32.944156][ C2] [ 32.944481][ C2] Modules linked in: [ 32.944894][ C2] ---[ end trace 0000000000000000 ]--- Protect the ext_prop attributes and the make/drop paths with gi->spinlock, which configfs_composite_setup() holds around composite_setup(). Fixes: 7419485f197c ("usb: gadget: configfs: OS Extended Properties descriptors support") Cc: stable@vger.kernel.org Assisted-by: ZCode:GLM-5.4 Signed-off-by: Jaegyun Lee --- drivers/usb/gadget/configfs.c | 41 ++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 46a2f1c6308c1..b164f1ec58c86 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -1283,6 +1283,15 @@ static inline struct usb_os_desc_ext_prop return container_of(item, struct usb_os_desc_ext_prop, item); } +static spinlock_t *os_desc_setup_lock(struct usb_os_desc *desc) +{ + struct config_item *funcs = + desc->group.cg_item.ci_parent->ci_parent->ci_parent; + + return &container_of(to_config_group(funcs), struct gadget_info, + functions_group)->spinlock; +} + static ssize_t ext_prop_type_show(struct config_item *item, char *page) { return sprintf(page, "%d\n", to_usb_os_desc_ext_prop(item)->type); @@ -1293,6 +1302,8 @@ static ssize_t ext_prop_type_store(struct config_item *item, { struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); + spinlock_t *lock = os_desc_setup_lock(desc); + unsigned long flags; u8 type; int ret; @@ -1305,6 +1316,7 @@ static ssize_t ext_prop_type_store(struct config_item *item, if (desc->opts_mutex) mutex_lock(desc->opts_mutex); + spin_lock_irqsave(lock, flags); if ((ext_prop->type == USB_EXT_PROP_BINARY || ext_prop->type == USB_EXT_PROP_LE32 || @@ -1322,6 +1334,7 @@ static ssize_t ext_prop_type_store(struct config_item *item, ext_prop->data_len >>= 1; ext_prop->type = type; + spin_unlock_irqrestore(lock, flags); if (desc->opts_mutex) mutex_unlock(desc->opts_mutex); return len; @@ -1330,13 +1343,19 @@ static ssize_t ext_prop_type_store(struct config_item *item, static ssize_t ext_prop_data_show(struct config_item *item, char *page) { struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); - int len = ext_prop->data_len; + struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); + spinlock_t *lock = os_desc_setup_lock(desc); + unsigned long flags; + int len; + spin_lock_irqsave(lock, flags); + len = ext_prop->data_len; if (ext_prop->type == USB_EXT_PROP_UNICODE || ext_prop->type == USB_EXT_PROP_UNICODE_ENV || ext_prop->type == USB_EXT_PROP_UNICODE_LINK) len >>= 1; memcpy(page, ext_prop->data, len); + spin_unlock_irqrestore(lock, flags); return len; } @@ -1346,7 +1365,9 @@ static ssize_t ext_prop_data_store(struct config_item *item, { struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); - char *new_data; + spinlock_t *lock = os_desc_setup_lock(desc); + unsigned long flags; + char *new_data, *old_data; size_t ret_len = len; if (page[len - 1] == '\n' || page[len - 1] == '\0') @@ -1357,7 +1378,8 @@ static ssize_t ext_prop_data_store(struct config_item *item, if (desc->opts_mutex) mutex_lock(desc->opts_mutex); - kfree(ext_prop->data); + spin_lock_irqsave(lock, flags); + old_data = ext_prop->data; ext_prop->data = new_data; desc->ext_prop_len -= ext_prop->data_len; ext_prop->data_len = len; @@ -1370,8 +1392,10 @@ static ssize_t ext_prop_data_store(struct config_item *item, ext_prop->data_len += 2; desc->ext_prop_len += ext_prop->data_len; } + spin_unlock_irqrestore(lock, flags); if (desc->opts_mutex) mutex_unlock(desc->opts_mutex); + kfree(old_data); return ret_len; } @@ -1402,6 +1426,7 @@ static struct config_item *ext_prop_make( struct usb_os_desc_ext_prop *ext_prop; struct config_item_type *ext_prop_type; struct usb_os_desc *desc; + unsigned long flags; char *vlabuf; vla_group(data_chunk); @@ -1427,13 +1452,14 @@ static struct config_item *ext_prop_make( kfree(vlabuf); return ERR_PTR(-ENOMEM); } - desc->ext_prop_len += 14; ext_prop->name_len = 2 * strlen(ext_prop->name) + 2; if (desc->opts_mutex) mutex_lock(desc->opts_mutex); - desc->ext_prop_len += ext_prop->name_len; + spin_lock_irqsave(os_desc_setup_lock(desc), flags); + desc->ext_prop_len += 14 + ext_prop->name_len; list_add_tail(&ext_prop->entry, &desc->ext_prop); ++desc->ext_prop_count; + spin_unlock_irqrestore(os_desc_setup_lock(desc), flags); if (desc->opts_mutex) mutex_unlock(desc->opts_mutex); @@ -1444,14 +1470,17 @@ static void ext_prop_drop(struct config_group *group, struct config_item *item) { struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); struct usb_os_desc *desc = to_usb_os_desc(&group->cg_item); + unsigned long flags; if (desc->opts_mutex) mutex_lock(desc->opts_mutex); + spin_lock_irqsave(os_desc_setup_lock(desc), flags); list_del(&ext_prop->entry); --desc->ext_prop_count; + desc->ext_prop_len -= (ext_prop->name_len + ext_prop->data_len + 14); + spin_unlock_irqrestore(os_desc_setup_lock(desc), flags); kfree(ext_prop->name); kfree(ext_prop->data); - desc->ext_prop_len -= (ext_prop->name_len + ext_prop->data_len + 14); if (desc->opts_mutex) mutex_unlock(desc->opts_mutex); config_item_put(item);