From patchwork Thu Apr 4 10:06:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Korsgaard X-Patchwork-Id: 13617513 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FF2D6BB29 for ; Thu, 4 Apr 2024 10:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712225217; cv=none; b=Tx/G+mFh7Gm/krsN+MQh5MqgE7BckzSiFkdMCf1Ir1Qy+hUYrLrbgv5mxB+XQNOZ3iz8bNKPJAaFhRcxEpPc1QhsjYlwgnf7OiNFBxAfRv3OxkmvbcMC6Snut3Qnn55+r8LqQraZgtuX8rKA2DnW2nAq2TKHNC1qyJF1272ixSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712225217; c=relaxed/simple; bh=dxTfu9hY9hmmdGJg36UAOeQDiA7PGLhsA/UX+IWNX70=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Qp0rgTq3CRRyuo16ITID2ZQ67U8jui9KWwr2deUmVgYSvXWsdfAq3HqiRIeBWlo+Lv+syW1w86akiRcA4lAvlnE6ZjWx7XEn76ar5I65RaVW5MzWDdCUaKQJtEXx6zVr2vtjDB+drlD6atC4j0h38VYj0GIxqJ0WApFVsEWH5q0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=korsgaard.com; spf=pass smtp.mailfrom=48ers.dk; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=korsgaard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=48ers.dk Received: by mail.gandi.net (Postfix) with ESMTPSA id 8FEF01BF203; Thu, 4 Apr 2024 10:06:50 +0000 (UTC) Received: from peko by dell.be.48ers.dk with local (Exim 4.96) (envelope-from ) id 1rsJzd-00DUSf-2Q; Thu, 04 Apr 2024 12:06:49 +0200 From: Peter Korsgaard To: linux-usb@vger.kernel.org, Greg Kroah-Hartman , Andrzej Pietrasiewicz Cc: Peter Korsgaard Subject: [PATCH] usb: gadget: composite: fix OS descriptors w_value logic Date: Thu, 4 Apr 2024 12:06:35 +0200 Message-Id: <20240404100635.3215340-1-peter@korsgaard.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: peter@korsgaard.com The OS descriptors logic had the high/low byte of w_value inverted, causing the extended properties to not be accessible for interface != 0. From the Microsoft documentation: https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-os-1-0-descriptors-specification OS_Desc_CompatID.doc (w_index = 0x4): - wValue: High Byte = InterfaceNumber. InterfaceNumber is set to the number of the interface or function that is associated with the descriptor, typically 0x00. Because a device can have only one extended compat ID descriptor, it should ignore InterfaceNumber, regardless of the value, and simply return the descriptor. Low Byte = 0. PageNumber is used to retrieve descriptors that are larger than 64 KB. The header section is 16 bytes, so PageNumber is set to 0 for this request. We currently do not support >64KB compat ID descriptors, so verify that the low byte is 0. OS_Desc_Ext_Prop.doc (w_index = 0x5): - wValue: High byte = InterfaceNumber. The high byte of wValue is set to the number of the interface or function that is associated with the descriptor. Low byte = PageNumber. The low byte of wValue is used to retrieve descriptors that are larger than 64 KB. The header section is 10 bytes, so PageNumber is set to 0 for this request. We also don't support >64KB extended properties, so verify that the low byte is 0 and use the high byte for the interface number. Fixes: 37a3a533429e ("usb: gadget: OS Feature Descriptors support") Signed-off-by: Peter Korsgaard --- drivers/usb/gadget/composite.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 0ace45b66a31..0e151b54aae8 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -2112,7 +2112,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) buf[5] = 0x01; switch (ctrl->bRequestType & USB_RECIP_MASK) { case USB_RECIP_DEVICE: - if (w_index != 0x4 || (w_value >> 8)) + if (w_index != 0x4 || (w_value & 0xff)) break; buf[6] = w_index; /* Number of ext compat interfaces */ @@ -2128,9 +2128,9 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) } break; case USB_RECIP_INTERFACE: - if (w_index != 0x5 || (w_value >> 8)) + if (w_index != 0x5 || (w_value & 0xff)) break; - interface = w_value & 0xFF; + interface = w_value >> 8; if (interface >= MAX_CONFIG_INTERFACES || !os_desc_cfg->interface[interface]) break;