]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
xhci: Don't add a virt_dev to the devs array before it's fully allocated
authorMathias Nyman <mathias.nyman@linux.intel.com>
Fri, 8 Dec 2017 16:10:05 +0000 (18:10 +0200)
committerSasha Levin <alexander.levin@microsoft.com>
Wed, 17 Jan 2018 17:55:31 +0000 (12:55 -0500)
commit412551c467675878bbf55667e478da7cddcd66a4
tree1c19233c0562e8e5df836744918c6dfcb1415516
parente1d46b53a6442b23bb4de8ed59c34a75cc6d25d4
xhci: Don't add a virt_dev to the devs array before it's fully allocated

[ Upstream commit 5d9b70f7d52eb14bb37861c663bae44de9521c35 ]

Avoid null pointer dereference if some function is walking through the
devs array accessing members of a new virt_dev that is mid allocation.

Add the virt_dev to xhci->devs[i] _after_ the virt_device and all its
members are properly allocated.

issue found by KASAN: null-ptr-deref in xhci_find_slot_id_by_port

"Quick analysis suggests that xhci_alloc_virt_device() is not mutex
protected. If so, there is a time frame where xhci->devs[slot_id] is set
but not fully initialized. Specifically, xhci->devs[i]->udev can be NULL."

Cc: stable <stable@vger.kernel.org>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
drivers/usb/host/xhci-mem.c