Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Dec 2020 11:51:18 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r368658 - head/sys/dev/usb
Message-ID:  <202012151151.0BFBpIUP073790@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Tue Dec 15 11:51:17 2020
New Revision: 368658
URL: https://svnweb.freebsd.org/changeset/base/368658

Log:
  Improve handling of alternate settings in the USB stack.
  
  Limit the number of alternate settings to 256.
  Else the alternate index variable may wrap around.
  
  PR:		251856
  MFC after:	1 week
  Submitted by:	Ma, Horse <Shichun.Ma@dell.com>
  Sponsored by:	Mellanox Technologies // NVIDIA Networking

Modified:
  head/sys/dev/usb/usb_parse.c

Modified: head/sys/dev/usb/usb_parse.c
==============================================================================
--- head/sys/dev/usb/usb_parse.c	Tue Dec 15 09:43:18 2020	(r368657)
+++ head/sys/dev/usb/usb_parse.c	Tue Dec 15 11:51:17 2020	(r368658)
@@ -2,7 +2,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
+ * Copyright (c) 2008-2020 Hans Petter Selasky. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -141,8 +141,20 @@ usb_idesc_foreach(struct usb_config_descriptor *cd,
 			break;
 		if ((id->bDescriptorType == UDESC_INTERFACE) &&
 		    (id->bLength >= sizeof(*id))) {
-			if (ps->iface_no_last == id->bInterfaceNumber)
+			if (ps->iface_no_last == id->bInterfaceNumber) {
+				/*
+				 * Don't allow more than 256 alternate
+				 * settings to avoid overflowing the
+				 * alternate index which is a 8-bit
+				 * variable.
+				 */
+				if (ps->iface_index_alt == 255) {
+					DPRINTF("Interface(%u) has more than 256 alternate settings\n",
+					    id->bInterfaceNumber);
+					continue;
+				}
 				new_iface = 0;
+			}
 			ps->iface_no_last = id->bInterfaceNumber;
 			break;
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012151151.0BFBpIUP073790>