Unverified Commit 1c55f6bf authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!15203 usb: cdc-acm: Check control transfer buffer size before access

parents 5e283eba 8f2b29fa
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -371,7 +371,7 @@ static void acm_process_notification(struct acm *acm, unsigned char *buf)
static void acm_ctrl_irq(struct urb *urb)
{
	struct acm *acm = urb->context;
	struct usb_cdc_notification *dr = urb->transfer_buffer;
	struct usb_cdc_notification *dr;
	unsigned int current_size = urb->actual_length;
	unsigned int expected_size, copy_size, alloc_size;
	int retval;
@@ -398,9 +398,20 @@ static void acm_ctrl_irq(struct urb *urb)

	usb_mark_last_busy(acm->dev);

	if (acm->nb_index)
	if (acm->nb_index == 0) {
		/*
		 * The first chunk of a message must contain at least the
		 * notification header with the length field, otherwise we
		 * can't get an expected_size.
		 */
		if (current_size < sizeof(struct usb_cdc_notification)) {
			dev_dbg(&acm->control->dev, "urb too short\n");
			goto exit;
		}
		dr = urb->transfer_buffer;
	} else {
		dr = (struct usb_cdc_notification *)acm->notification_buffer;

	}
	/* size = notification-header + (optional) data */
	expected_size = sizeof(struct usb_cdc_notification) +
					le16_to_cpu(dr->wLength);