Commit ab5a489f authored by Niklas Neronin's avatar Niklas Neronin Committed by Wang Wensheng
Browse files

usb: config: fix iteration issue in 'usb_get_bos_descriptor()'

stable inclusion
from stable-v5.10.203
commit 9ef94ec8e52eaf7b9abc5b5f8f5b911751112223
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9R4KP
CVE: CVE-2023-52781

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9ef94ec8e52eaf7b9abc5b5f8f5b911751112223



--------------------------------

[ Upstream commit 974bba5c118f4c2baf00de0356e3e4f7928b4cbc ]

The BOS descriptor defines a root descriptor and is the base descriptor for
accessing a family of related descriptors.

Function 'usb_get_bos_descriptor()' encounters an iteration issue when
skipping the 'USB_DT_DEVICE_CAPABILITY' descriptor type. This results in
the same descriptor being read repeatedly.

To address this issue, a 'goto' statement is introduced to ensure that the
pointer and the amount read is updated correctly. This ensures that the
function iterates to the next descriptor instead of reading the same
descriptor repeatedly.

Cc: stable@vger.kernel.org
Fixes: 3dd550a2 ("USB: usbcore: Fix slab-out-of-bounds bug during device reset")
Signed-off-by: default avatarNiklas Neronin <niklas.neronin@linux.intel.com>
Acked-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
Reviewed-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20231115121325.471454-1-niklas.neronin@linux.intel.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent f90278e8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1047,7 +1047,7 @@ int usb_get_bos_descriptor(struct usb_device *dev)

		if (cap->bDescriptorType != USB_DT_DEVICE_CAPABILITY) {
			dev_notice(ddev, "descriptor type invalid, skip\n");
			continue;
			goto skip_to_next_descriptor;
		}

		switch (cap_type) {
@@ -1080,6 +1080,7 @@ int usb_get_bos_descriptor(struct usb_device *dev)
			break;
		}

skip_to_next_descriptor:
		total_len -= length;
		buffer += length;
	}