From nobody Sun Feb 8 18:39:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613649298; cv=none; d=zohomail.com; s=zohoarc; b=cOVeCumtWkw+kU5JX9/dX7HNxsD8GnvH/pf+GSaqkt1Pmj5LuAO+tb+yeKzd/jEDQuZNO5ZvNQOG/LIjRKhdNC+7p2hiKjR0LpjbZfybeaaqd2eqljMDxc8G88jaXA610nguFi6nWZtz4bQHXKO7FE1/2arvv+LI0mVKSeBvzVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613649298; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ljs0jl2NWwnjIia2zMHwRqHl3PssesXBzlB04pg2NuQ=; b=acuRfvxPSsq0ug8kze9GbrK71kTZ1ZMnzGFOAZspMIrQDPw1hPsV8z1SfNBHfL/usvDbz4ZiHsPGi1IY9W0Pfx2c+TNLty+hb68pMhsQhz9PJ/z3gBPywkGpEGl+xghRpwMylgJcHw2bfTyQiRvRAUKQBHl0FwM7lAh3zQcNtOA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613649298547514.6551986060523; Thu, 18 Feb 2021 03:54:58 -0800 (PST) Received: from localhost ([::1]:37814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lChtZ-0000oW-7r for importer@patchew.org; Thu, 18 Feb 2021 06:54:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lChqz-0007Kp-72 for qemu-devel@nongnu.org; Thu, 18 Feb 2021 06:52:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lChqt-0004nK-EN for qemu-devel@nongnu.org; Thu, 18 Feb 2021 06:52:16 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-47-mxWa1GZzPkWF1ZJRFstBqA-1; Thu, 18 Feb 2021 06:52:07 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E3B618829DC; Thu, 18 Feb 2021 11:52:06 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-114-184.ams2.redhat.com [10.36.114.184]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 511A25C1C4; Thu, 18 Feb 2021 11:52:03 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id B5B311800382; Thu, 18 Feb 2021 12:52:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613649129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ljs0jl2NWwnjIia2zMHwRqHl3PssesXBzlB04pg2NuQ=; b=OZ3WeD8mZWga7D73ztfaQf8F+BJ7gkTJ8V/K+R/SPR8DnzdpuPk+U4IWGzGjZnP6BQ6WxV VlMAXdflBcqo+/y/A5JQLomXSC3OTVN5NSsOjw4LPOnr0Pnzd5eXUxw6b+vyPW856D4eCo 1+SnYyfLtrbZkHTxJk68Oyuuw3MR3aU= X-MC-Unique: mxWa1GZzPkWF1ZJRFstBqA-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 1/2] usb-host: use correct altsetting in usb_host_ep_update Date: Thu, 18 Feb 2021 12:52:00 +0100 Message-Id: <20210218115201.2765071-2-kraxel@redhat.com> In-Reply-To: <20210218115201.2765071-1-kraxel@redhat.com> References: <20210218115201.2765071-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , Gerd Hoffmann , Nick Rosbrook Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Nick Rosbrook In order to keep track of the alternate setting that should be used for a given interface, the USBDevice struct keeps an array of alternate setting values, which is indexed by the interface number. In usb_host_set_interface, when this array is updated, usb_host_ep_update is called as a result. However, when usb_host_ep_update accesses the active libusb_config_descriptor, it indexes udev->altsetting with the loop variable, rather than the interface number. With the simple trace backend enable, this behavior can be seen: [...] usb_xhci_xfer_start 0.440 pid=3D1215 xfer=3D0x5596a4b85930 slotid=3D0x1 e= pid=3D0x1 streamid=3D0x0 usb_packet_state_change 1.703 pid=3D1215 bus=3D0x1 port=3Db'1' ep=3D0x0 p= =3D0x5596a4b85938 o=3Db'undef' n=3Db'setup' usb_host_req_control 2.269 pid=3D1215 bus=3D0x1 addr=3D0x5 p=3D0x5596a4b8= 5938 req=3D0x10b value=3D0x1 index=3D0xd usb_host_set_interface 0.449 pid=3D1215 bus=3D0x1 addr=3D0x5 interface=3D= 0xd alt=3D0x1 usb_host_parse_config 2542.648 pid=3D1215 bus=3D0x1 addr=3D0x5 value=3D0x= 2 active=3D0x1 usb_host_parse_interface 1.804 pid=3D1215 bus=3D0x1 addr=3D0x5 num=3D0xc = alt=3D0x0 active=3D0x1 usb_host_parse_endpoint 2.012 pid=3D1215 bus=3D0x1 addr=3D0x5 ep=3D0x2 di= r=3Db'in' type=3Db'int' active=3D0x1 usb_host_parse_interface 1.598 pid=3D1215 bus=3D0x1 addr=3D0x5 num=3D0xd = alt=3D0x0 active=3D0x1 usb_host_req_emulated 3.593 pid=3D1215 bus=3D0x1 addr=3D0x5 p=3D0x5596a4b= 85938 status=3D0x0 usb_packet_state_change 2.550 pid=3D1215 bus=3D0x1 port=3Db'1' ep=3D0x0 p= =3D0x5596a4b85938 o=3Db'setup' n=3Db'complete' usb_xhci_xfer_success 4.298 pid=3D1215 xfer=3D0x5596a4b85930 bytes=3D0x0 [...] In particular, it is seen that although usb_host_set_interface sets the alternate setting of interface 0xd to 0x1, usb_host_ep_update uses 0x0 as the alternate setting due to using the incorrect index to udev->altsetting. Fix this problem by getting the interface number from the active libusb_config_descriptor, and then using that as the index to udev->altsetting. Signed-off-by: Nick Rosbrook Message-Id: <20210201213021.500277-1-rosbrookn@ainfosec.com> Signed-off-by: Gerd Hoffmann --- hw/usb/host-libusb.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index 7dde3d12069e..354713a77dc9 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -836,7 +836,7 @@ static void usb_host_ep_update(USBHostDevice *s) struct libusb_ss_endpoint_companion_descriptor *endp_ss_comp; #endif uint8_t devep, type; - int pid, ep; + int pid, ep, alt; int rc, i, e; =20 usb_ep_reset(udev); @@ -848,8 +848,20 @@ static void usb_host_ep_update(USBHostDevice *s) conf->bConfigurationValue, true); =20 for (i =3D 0; i < conf->bNumInterfaces; i++) { - assert(udev->altsetting[i] < conf->interface[i].num_altsetting); - intf =3D &conf->interface[i].altsetting[udev->altsetting[i]]; + /* + * The udev->altsetting array indexes alternate settings + * by the interface number. Get the 0th alternate setting + * first so that we can grab the interface number, and + * then correct the alternate setting value if necessary. + */ + intf =3D &conf->interface[i].altsetting[0]; + alt =3D udev->altsetting[intf->bInterfaceNumber]; + + if (alt !=3D 0) { + assert(alt < conf->interface[i].num_altsetting); + intf =3D &conf->interface[i].altsetting[alt]; + } + trace_usb_host_parse_interface(s->bus_num, s->addr, intf->bInterfaceNumber, intf->bAlternateSetting, true); --=20 2.29.2 From nobody Sun Feb 8 18:39:15 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613649298; cv=none; d=zohomail.com; s=zohoarc; b=SNoSkWKnLelq3tdZtrUMGwjFx0MREcHwRuvmLdxdujgkGxpzVWFkPNEYFzVS7CXe+Qvk8O5ozx8FLfp7bybIr+4mqYUnzpnItyuhx/JXjyfbyxWKgChyYdPODp/f1s2Dr+cCS4AXCwMXt86u8TUUnEHIQM9CT57VnPmICTTUgXI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613649298; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YhQhnDzoROLQ360Dw8zGWGwb9pzcbAwZh8U1ogxY2qk=; b=FcdMTmypL18OYZi/6Vur5iH7KexXTNGXFDXSqCzPfbTGPyRVwE2vpVPBIXNijubbgZniP7rWEPU8dh7DrksAfNto00iA54FyouyHCTy5C4NlrMI2zvG4XEosIUqQIdAuIn4MOh83cqdxyLmz+rIJkKeL+Eu7KutzHoEhAZfq6ZM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613649298548784.6392269630919; Thu, 18 Feb 2021 03:54:58 -0800 (PST) Received: from localhost ([::1]:37778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lChtZ-0000na-DY for importer@patchew.org; Thu, 18 Feb 2021 06:54:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lChr0-0007Lb-57 for qemu-devel@nongnu.org; Thu, 18 Feb 2021 06:52:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lChqu-0004nW-1f for qemu-devel@nongnu.org; Thu, 18 Feb 2021 06:52:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-471-o0CSy2SeMkGoSAFL1kwmKg-1; Thu, 18 Feb 2021 06:52:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2ED03107AD29 for ; Thu, 18 Feb 2021 11:52:08 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-114-184.ams2.redhat.com [10.36.114.184]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45D6360C61; Thu, 18 Feb 2021 11:52:03 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C04E31800383; Thu, 18 Feb 2021 12:52:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613649130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YhQhnDzoROLQ360Dw8zGWGwb9pzcbAwZh8U1ogxY2qk=; b=QDbwlrMVfYq3EM1pxwnGQ8J4OUAjVwxLA3fR6f81poFIQGv5hhab7l+iR5QDj/Q068fRB0 mJRTBhUrDBikO75uPB8BegQmiaTz4e4r2qeD+4q+qNQ68KF8KWNeQSdi+oHoP8cIvpCweJ 00FIPILzGbs79CjXSMWVzVZS6F/0S/4= X-MC-Unique: o0CSy2SeMkGoSAFL1kwmKg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 2/2] usb/pcap: set flag_setup Date: Thu, 18 Feb 2021 12:52:01 +0100 Message-Id: <20210218115201.2765071-3-kraxel@redhat.com> In-Reply-To: <20210218115201.2765071-1-kraxel@redhat.com> References: <20210218115201.2765071-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Without that wireshark complains about invalid control setup data for non-control transfers. Signed-off-by: Gerd Hoffmann Message-Id: <20210216144939.841873-1-kraxel@redhat.com> Signed-off-by: Gerd Hoffmann --- hw/usb/pcap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/usb/pcap.c b/hw/usb/pcap.c index 4350989d3a71..dbff00be252e 100644 --- a/hw/usb/pcap.c +++ b/hw/usb/pcap.c @@ -127,6 +127,7 @@ static void do_usb_pcap_ctrl(FILE *fp, USBPacket *p, bo= ol setup) .xfer_type =3D usbmon_xfer_type[USB_ENDPOINT_XFER_CONTROL], .epnum =3D in ? 0x80 : 0, .devnum =3D dev->addr, + .flag_setup =3D setup ? 0 : '-', .flag_data =3D '=3D', .length =3D dev->setup_len, }; @@ -169,6 +170,7 @@ static void do_usb_pcap_data(FILE *fp, USBPacket *p, bo= ol setup) .xfer_type =3D usbmon_xfer_type[p->ep->type], .epnum =3D usbmon_epnum(p), .devnum =3D p->ep->dev->addr, + .flag_setup =3D '-', .flag_data =3D '=3D', .length =3D p->iov.size, }; --=20 2.29.2