From nobody Fri May 17 21:43:12 2024 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=1598863278; cv=none; d=zohomail.com; s=zohoarc; b=XuUlTlb7T1zCXdcb4BDdcBSa9TVa6/1r7w2BpnWRVZo0Mb3scU3lB3IflxxmlUUvxSQrlMs3uMGpgCHlUzUHJmqO6KSafur6Y/cVVfIbHC4iYOXjbPtzYBuUWb5o978RLg5dXZstEKUG6PQlrr66b418PrGCfR8yXQ87Fim5P2Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863278; 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=mVf/UE+JMYlpL1srU0dpkzi9EtkgTXpYauLVVSsyaJo=; b=M5Yq/zci5k4ZzREiY2M2HhMHuxrPFg+Iu2QmI0qd20Yz3no/IDVZeDNhmnz5nbaiKIiWL1TKpI5IxqYrd/98KMqTyVETaMxmvuYGPpJwYnYrYPsYCrdiXgF1sSQKgUNldQSIZV1Te37ciq19RQL/tNzak8vTrXe/U0JN/J8HyVg= 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 1598863278244953.6223486992882; Mon, 31 Aug 2020 01:41:18 -0700 (PDT) Received: from localhost ([::1]:39582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfNM-0006mD-TG for importer@patchew.org; Mon, 31 Aug 2020 04:41:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFh-0008R5-6k for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58016) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFd-0006d3-5A for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:20 -0400 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-199-wqceQQviMruu0PjBXGVj5g-1; Mon, 31 Aug 2020 04:33:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2CF4802B7B; Mon, 31 Aug 2020 08:33:05 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCF1E81183; Mon, 31 Aug 2020 08:33:02 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id E59359C90; Mon, 31 Aug 2020 10:33:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862796; 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=mVf/UE+JMYlpL1srU0dpkzi9EtkgTXpYauLVVSsyaJo=; b=bAxkrFCspS2Ideqlccu8mbP2j85a+N8BN8DQ2kipEnX6r1fP2IuGovP3Lt0kZKyP2MH8RD TodbMhVj3N8gONAg+BotMWjOlZZ5pqB5/V0S8FBWCgybzXl6rRzXT0htPhAo+OO2vjCK/u a4RZ1d9McugEflKMcV2IF3URHexsqH0= X-MC-Unique: wqceQQviMruu0PjBXGVj5g-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 01/18] hw: xhci: check return value of 'usb_packet_map' Date: Mon, 31 Aug 2020 10:32:44 +0200 Message-Id: <20200831083301.6357-2-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.001 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-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:43:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Li Qiang , Alexander Bulekov , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini 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: Li Qiang Currently we don't check the return value of 'usb_packet_map', this will cause an UAF issue. This is LP#1891341. Following is the reproducer provided in: -->https://bugs.launchpad.net/qemu/+bug/1891341 cat << EOF | ./i386-softmmu/qemu-system-i386 -device nec-usb-xhci \ -trace usb\* -device usb-audio -device usb-storage,drive=3Dmydrive \ -drive id=3Dmydrive,file=3Dnull-co://,size=3D2M,format=3Draw,if=3Dnone \ -nodefaults -nographic -qtest stdio outl 0xcf8 0x80001016 outl 0xcfc 0x3c009f0d outl 0xcf8 0x80001004 outl 0xcfc 0xc77695e writel 0x9f0d000000000040 0xffff3655 writeq 0x9f0d000000002000 0xff2f9e0000000000 write 0x1d 0x1 0x27 write 0x2d 0x1 0x2e write 0x17232 0x1 0x03 write 0x17254 0x1 0x06 write 0x17278 0x1 0x34 write 0x3d 0x1 0x27 write 0x40 0x1 0x2e write 0x41 0x1 0x72 write 0x42 0x1 0x01 write 0x4d 0x1 0x2e write 0x4f 0x1 0x01 writeq 0x9f0d000000002000 0x5c051a0100000000 write 0x34001d 0x1 0x13 write 0x340026 0x1 0x30 write 0x340028 0x1 0x08 write 0x34002c 0x1 0xfe write 0x34002d 0x1 0x08 write 0x340037 0x1 0x5e write 0x34003a 0x1 0x05 write 0x34003d 0x1 0x05 write 0x34004d 0x1 0x13 writeq 0x9f0d000000002000 0xff00010100400009 EOF This patch fixes this. Buglink: https://bugs.launchpad.net/qemu/+bug/1891341 Reported-by: Alexander Bulekov Signed-off-by: Li Qiang Message-id: 20200812153139.15146-1-liq3ea@163.com Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 67a18fe2b64c..46a2186d912a 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1615,7 +1615,10 @@ static int xhci_setup_packet(XHCITransfer *xfer) xhci_xfer_create_sgl(xfer, dir =3D=3D USB_TOKEN_IN); /* Also sets int_= req */ usb_packet_setup(&xfer->packet, dir, ep, xfer->streamid, xfer->trbs[0].addr, false, xfer->int_req); - usb_packet_map(&xfer->packet, &xfer->sgl); + if (usb_packet_map(&xfer->packet, &xfer->sgl)) { + qemu_sglist_destroy(&xfer->sgl); + return -1; + } DPRINTF("xhci: setup packet pid 0x%x addr %d ep %d\n", xfer->packet.pid, ep->dev->addr, ep->nr); return 0; --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598862949; cv=none; d=zohomail.com; s=zohoarc; b=NwbaVBZEH1Stpf2R7I3WEjwT8ZQaU3DeNg+XxaaPzdgxZtCcqprKM5MIiLqaDnoYwq927W3h6yH8Oq1EdiKhsU4ISLo4uo/I0ozQKfs0gFdfa7WAWwaL5HutOtb29LFu8GAa8ke6N2l2H5B52PDDLzFOKGlJo7Ue6ccof3JLjAo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598862949; 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=Xje74MaN8FG/NXyImMEp/+6zvVOF8ojzHUbuRw9nHOI=; b=Ce+fKnW3HJVVoYOhvXy2GpXN5QgHxux9vyDnp3I0zo56Oc3zFCxCvcpZssS7xl+089A7wB+eqWvIiqTqYfzzEurXis9e40WGGYg04IbFMFeIKQjbUTOi4zq36PkbFO2enkT72VvvGjJjftIVU0gXvF0hxfIrOvkYDsd+eticoAE= 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 1598862949460620.4940957090955; Mon, 31 Aug 2020 01:35:49 -0700 (PDT) Received: from localhost ([::1]:39280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfI3-0003Z8-V6 for importer@patchew.org; Mon, 31 Aug 2020 04:35:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFY-00086f-F4 for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:12 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32540 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFV-0006Zf-Ni for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:12 -0400 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-197-jLEnfXIRPaK33l2cbktc5w-1; Mon, 31 Aug 2020 04:33:06 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C31B810ABDAC; Mon, 31 Aug 2020 08:33:05 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFD057BE8B; Mon, 31 Aug 2020 08:33:02 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id EE881ED9; Mon, 31 Aug 2020 10:33:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862789; 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=Xje74MaN8FG/NXyImMEp/+6zvVOF8ojzHUbuRw9nHOI=; b=HdcHzVhfKiU5PrXnSpXRU542AWdraPGCHthEGgfxh/otp64VkZN3CPrcHuyFwxhvdXur0y FCM27sBzBL1s0II/4CsXVNhl6r0h+SaKPn5a7UmFVN2iN8FGBx2YtgR5ITKMHMQ6m0SPve uZt1VzcuAVWgrk6y9M/cs2Sd9WfzmIE= X-MC-Unique: jLEnfXIRPaK33l2cbktc5w-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 02/18] hw: ehci: destroy sglist in error path Date: Mon, 31 Aug 2020 10:32:45 +0200 Message-Id: <20200831083301.6357-3-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.001 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=207.211.31.120; envelope-from=kraxel@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 02:54:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Li Qiang , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini 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: Li Qiang This may cause resource leak. Signed-off-by: Li Qiang Message-Id: <20200812161712.29361-1-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ehci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 1495e8f7fab1..58cceacbf83a 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -1445,6 +1445,7 @@ static int ehci_process_itd(EHCIState *ehci, dev =3D ehci_find_device(ehci, devaddr); if (dev =3D=3D NULL) { ehci_trace_guest_bug(ehci, "no device found"); + qemu_sglist_destroy(&ehci->isgl); return -1; } pid =3D dir ? USB_TOKEN_IN : USB_TOKEN_OUT; --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598862974; cv=none; d=zohomail.com; s=zohoarc; b=TM2eafdzK92WIHCT7IkrH73LYvo4rg/YpRIQfyiTxQbdFcJlkGhIXM629NOJw6hbPQB9NHmJ/YaOR1tOV30CCj6uJ/SclU+mbj78wt5Mg+5TwyEr5VdDFm9QvYR1jO4Dq8gIb2kWc3ZPkEf6fa0yah+QY8kt6trX2jBFARrfIgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598862974; 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=X9130wMPdkUNf8DYOJXaIxhe8PFcuZwIUBzhp+qLksQ=; b=RffE/H3r3uIvKoFvAuhccIrbMk3S7XV+c3qSA96eo8Rg19KPZJ+4h+cKvgKaDwaWTOJo+FLdoK7ihVF9hdLA2w+1nBemV6hAx+3G5sJAcITJfx7dFz+g1xrje/kWbOfmZ/+2g9r9WgydJVrF+ceIEujj+2MGLJIj2GrYXSqSNwg= 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 1598862974989107.65479770620209; Mon, 31 Aug 2020 01:36:14 -0700 (PDT) Received: from localhost ([::1]:42100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfIT-0004m1-KB for importer@patchew.org; Mon, 31 Aug 2020 04:36:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFY-000874-Mx for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44976) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFW-0006Zs-KG for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:12 -0400 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-225-TnNTksJqM-O78N88t1bigA-1; Mon, 31 Aug 2020 04:33:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0087E10ABDAE; Mon, 31 Aug 2020 08:33:06 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id C679C7EB72; Mon, 31 Aug 2020 08:33:02 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 034D97828; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862790; 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=X9130wMPdkUNf8DYOJXaIxhe8PFcuZwIUBzhp+qLksQ=; b=KX+hoF8DCDbboKsU6sbJGSD0vB6e7QzpN1TBvxuh7XkqZqVolXbWaPH1nDbnxCrpx3U0BO O0EBtaLLzLZh4mHzhyuyVo8VIqWWalexrCDVpGFhaP1XVZICwygyhH+4HhNf3SoSBCAvGs 6htIdeMEX/OXoLShLR541aaO02A/phI= X-MC-Unique: TnNTksJqM-O78N88t1bigA-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 03/18] hw: ehci: check return value of 'usb_packet_map' Date: Mon, 31 Aug 2020 10:32:46 +0200 Message-Id: <20200831083301.6357-4-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.001 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-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:43:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Li Qiang , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini 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: Li Qiang If 'usb_packet_map' fails, we should stop to process the usb request. Signed-off-by: Li Qiang Message-Id: <20200812161727.29412-1-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ehci.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 58cceacbf83a..4da446d2de6b 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -1373,7 +1373,10 @@ static int ehci_execute(EHCIPacket *p, const char *a= ction) spd =3D (p->pid =3D=3D USB_TOKEN_IN && NLPTR_TBIT(p->qtd.altnext) = =3D=3D 0); usb_packet_setup(&p->packet, p->pid, ep, 0, p->qtdaddr, spd, (p->qtd.token & QTD_TOKEN_IOC) !=3D 0); - usb_packet_map(&p->packet, &p->sgl); + if (usb_packet_map(&p->packet, &p->sgl)) { + qemu_sglist_destroy(&p->sgl); + return -1; + } p->async =3D EHCI_ASYNC_INITIALIZED; } =20 @@ -1453,7 +1456,10 @@ static int ehci_process_itd(EHCIState *ehci, if (ep && ep->type =3D=3D USB_ENDPOINT_XFER_ISOC) { usb_packet_setup(&ehci->ipacket, pid, ep, 0, addr, false, (itd->transact[i] & ITD_XACT_IOC) !=3D 0); - usb_packet_map(&ehci->ipacket, &ehci->isgl); + if (usb_packet_map(&ehci->ipacket, &ehci->isgl)) { + qemu_sglist_destroy(&ehci->isgl); + return -1; + } usb_handle_packet(dev, &ehci->ipacket); usb_packet_unmap(&ehci->ipacket, &ehci->isgl); } else { --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598862868; cv=none; d=zohomail.com; s=zohoarc; b=K9d/qlEH/GORtSq97A6N0sB9asquiGuicHyDLapYFsCf2MLOq1/fFabmypLaelbKomZ2sI9L/MjCO8fbdqVLwPo6eq2xxvjBp8TcUQk7LJAq0NC8SjGU2HEXe8no+AvzeQLTTMH+xE8ChI7B+1x5qdF+QLFu4nkg0UOlMqYFruQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598862868; 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=7/J0K4csVztYP7o+7FyVdDGJsxMvUqrrvTDjsw7WPVs=; b=NT2nADg2e2+gkUrXC76wxwtD58F0NQGcM+v5uNEaMQzIfTtssqrjx/lYZ0XFusnVhOi5cdtEyYi0j0gUpc6EmyWl2ZRXSXstst2zsalCwG8NsWRVwo//vqRg2xc1a2Hs7920DuO2Yi/hB3r+PddqKxYcesrwy+CioiFLUVEInJk= 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 1598862868231992.3588763516261; Mon, 31 Aug 2020 01:34:28 -0700 (PDT) Received: from localhost ([::1]:33678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfGj-0001LD-Sx for importer@patchew.org; Mon, 31 Aug 2020 04:34:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFX-00085D-Hi for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFV-0006ZQ-L1 for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:11 -0400 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-286-CsdYJ_B6MGyikCWTAhkR0g-1; Mon, 31 Aug 2020 04:33:06 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D73BC10ABDAD for ; Mon, 31 Aug 2020 08:33:05 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9DE92616B; Mon, 31 Aug 2020 08:33:02 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 0C23645B2; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862788; 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=7/J0K4csVztYP7o+7FyVdDGJsxMvUqrrvTDjsw7WPVs=; b=a8chflFx0/vbZ3Aycj8xX7B52ya36db+QCsOusjXD7KfpP4mQzreE4md6BVYxIDQ1n9fVo gf20ygDkJKq8rD58JeBuhE3X53oSfslNVjZNQuC700FCi3fVtW/WlOqNioTNu6F8kIOUWK tdqSTjZXVvV8IvNqxaP5rjmiDGB5KcM= X-MC-Unique: CsdYJ_B6MGyikCWTAhkR0g-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 04/18] ehci: drop pointless warn_report for guest bugs. Date: Mon, 31 Aug 2020 10:32:47 +0200 Message-Id: <20200831083301.6357-5-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=63.128.21.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:02:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We have a tracepoint at the same place which can be enabled if needed. Buglink: https://bugzilla.redhat.com//show_bug.cgi?id=3D1859236 Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20200722072613.10390-1-kraxel@redhat.com> --- hw/usb/hcd-ehci.c | 1 - 1 file changed, 1 deletion(-) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 4da446d2de6b..2b995443fbfd 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -352,7 +352,6 @@ static void ehci_trace_sitd(EHCIState *s, hwaddr addr, static void ehci_trace_guest_bug(EHCIState *s, const char *message) { trace_usb_ehci_guest_bug(message); - warn_report("%s", message); } =20 static inline bool ehci_enabled(EHCIState *s) --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863351; cv=none; d=zohomail.com; s=zohoarc; b=n3Ej9khioK8tTMO4mVJu1nMQS+2C4NjZCW054ucluKn3ANpYg5t0aNFp1pFOz9zcOb1yiRdODtgyl5TqEs+SIFOw94CmdHOVu03rJ6lvJoN2FKkyJ7Bb8qyrwOKmKdETvzNhobnR0os0UfA27emFAIY3Tt99GNlzwBdZru5eAeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863351; 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=1xSE0n02diYqExNHwLoM1kNSqbWL0PPkSAmvh8Hm6qA=; b=YkyJEwlXpsESSGagEsc8gzpsHtZnjgOV02mZi/diAMq0G/hofj9/v63axFpOLzxDS1Fg94OGMHzsLzkxUXB+jYvnfWKVrueFje1jJ9VIHZKbBPiGk9twan3lcPjmv551bice7/HszzG98WiJUp4JyK/hAAjaKgpGH0IxIjnzzhs= 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 1598863351910432.0402675150402; Mon, 31 Aug 2020 01:42:31 -0700 (PDT) Received: from localhost ([::1]:46798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfOY-0001GS-Ge for importer@patchew.org; Mon, 31 Aug 2020 04:42:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFd-0008Iq-T6 for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56202) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFZ-0006an-GZ for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:17 -0400 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-362-kxFImsXYNmKC6RuYLMbwaA-1; Mon, 31 Aug 2020 04:33:08 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 76B02801AC3; Mon, 31 Aug 2020 08:33:07 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAC823A40; Mon, 31 Aug 2020 08:33:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 183CA1FCEE; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862792; 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=1xSE0n02diYqExNHwLoM1kNSqbWL0PPkSAmvh8Hm6qA=; b=TXewZU9is78HD6S9NVTa4SsoI+qs2EprlauuKpUwAd1/s0aDiDdz9uvWvWsUnk9RmbBeJI rtTtqEZyyN/XjuMf9wxY9/IjLPMm0ZZ95uI7W9OPk9dYhBB/MFMPmtdvrLVWZ2nENULDSu xUfdy9TRN+7ciGf3MOn8lyrMHkRhSFM= X-MC-Unique: kxFImsXYNmKC6RuYLMbwaA-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 05/18] hw/usb: Regroup USB HID protocol values Date: Mon, 31 Aug 2020 10:32:48 +0200 Message-Id: <20200831083301.6357-6-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=63.128.21.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:02:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley Group some HID values that are used pretty much everywhere when dealing with HID devices. Signed-off-by: C=C3=A9sar Belley Message-id: 20200812094135.20550-2-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- include/hw/usb/hid.h | 17 +++++++++++++++++ hw/usb/dev-hid.c | 26 +++++++------------------- hw/usb/dev-wacom.c | 12 +++--------- 3 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 include/hw/usb/hid.h diff --git a/include/hw/usb/hid.h b/include/hw/usb/hid.h new file mode 100644 index 000000000000..1c142584ffab --- /dev/null +++ b/include/hw/usb/hid.h @@ -0,0 +1,17 @@ +#ifndef HW_USB_HID_H +#define HW_USB_HID_H + +/* HID interface requests */ +#define HID_GET_REPORT 0xa101 +#define HID_GET_IDLE 0xa102 +#define HID_GET_PROTOCOL 0xa103 +#define HID_SET_REPORT 0x2109 +#define HID_SET_IDLE 0x210a +#define HID_SET_PROTOCOL 0x210b + +/* HID descriptor types */ +#define USB_DT_HID 0x21 +#define USB_DT_REPORT 0x22 +#define USB_DT_PHY 0x23 + +#endif diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c index 89f63b698b8a..c73f7b2fe2c5 100644 --- a/hw/usb/dev-hid.c +++ b/hw/usb/dev-hid.c @@ -32,21 +32,9 @@ #include "qemu/module.h" #include "qemu/timer.h" #include "hw/input/hid.h" +#include "hw/usb/hid.h" #include "hw/qdev-properties.h" =20 -/* HID interface requests */ -#define GET_REPORT 0xa101 -#define GET_IDLE 0xa102 -#define GET_PROTOCOL 0xa103 -#define SET_REPORT 0x2109 -#define SET_IDLE 0x210a -#define SET_PROTOCOL 0x210b - -/* HID descriptor types */ -#define USB_DT_HID 0x21 -#define USB_DT_REPORT 0x22 -#define USB_DT_PHY 0x23 - typedef struct USBHIDState { USBDevice dev; USBEndpoint *intr; @@ -618,38 +606,38 @@ static void usb_hid_handle_control(USBDevice *dev, US= BPacket *p, goto fail; } break; - case GET_REPORT: + case HID_GET_REPORT: if (hs->kind =3D=3D HID_MOUSE || hs->kind =3D=3D HID_TABLET) { p->actual_length =3D hid_pointer_poll(hs, data, length); } else if (hs->kind =3D=3D HID_KEYBOARD) { p->actual_length =3D hid_keyboard_poll(hs, data, length); } break; - case SET_REPORT: + case HID_SET_REPORT: if (hs->kind =3D=3D HID_KEYBOARD) { p->actual_length =3D hid_keyboard_write(hs, data, length); } else { goto fail; } break; - case GET_PROTOCOL: + case HID_GET_PROTOCOL: if (hs->kind !=3D HID_KEYBOARD && hs->kind !=3D HID_MOUSE) { goto fail; } data[0] =3D hs->protocol; p->actual_length =3D 1; break; - case SET_PROTOCOL: + case HID_SET_PROTOCOL: if (hs->kind !=3D HID_KEYBOARD && hs->kind !=3D HID_MOUSE) { goto fail; } hs->protocol =3D value; break; - case GET_IDLE: + case HID_GET_IDLE: data[0] =3D hs->idle; p->actual_length =3D 1; break; - case SET_IDLE: + case HID_SET_IDLE: hs->idle =3D (uint8_t) (value >> 8); hid_set_next_idle(hs); if (hs->kind =3D=3D HID_MOUSE || hs->kind =3D=3D HID_TABLET) { diff --git a/hw/usb/dev-wacom.c b/hw/usb/dev-wacom.c index 8aba44b8bc3d..76fc5a5dabf3 100644 --- a/hw/usb/dev-wacom.c +++ b/hw/usb/dev-wacom.c @@ -29,6 +29,7 @@ #include "qemu/osdep.h" #include "ui/console.h" #include "hw/usb.h" +#include "hw/usb/hid.h" #include "migration/vmstate.h" #include "qemu/module.h" #include "desc.h" @@ -37,13 +38,6 @@ #define WACOM_GET_REPORT 0x2101 #define WACOM_SET_REPORT 0x2109 =20 -/* HID interface requests */ -#define HID_GET_REPORT 0xa101 -#define HID_GET_IDLE 0xa102 -#define HID_GET_PROTOCOL 0xa103 -#define HID_SET_IDLE 0x210a -#define HID_SET_PROTOCOL 0x210b - typedef struct USBWacomState { USBDevice dev; USBEndpoint *intr; @@ -86,11 +80,11 @@ static const USBDescIface desc_iface_wacom =3D { /* HID descriptor */ .data =3D (uint8_t[]) { 0x09, /* u8 bLength */ - 0x21, /* u8 bDescriptorType */ + USB_DT_HID, /* u8 bDescriptorType */ 0x01, 0x10, /* u16 HID_class */ 0x00, /* u8 country_code */ 0x01, /* u8 num_descriptors */ - 0x22, /* u8 type: Report */ + USB_DT_REPORT, /* u8 type: Report */ 0x6e, 0, /* u16 len */ }, }, --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863497; cv=none; d=zohomail.com; s=zohoarc; b=mAHCzA3PU2D7oTjxvfqjPjH8idHzvPsXCSga0ZUr4Lu1QUx6kujGL1xMlIZ01eo/SY16bz0gXCln/yFWOyG4QQiGHaVNLKklqBj1hnjDtoidY5cWB3nuJ7KTk2X8TwIkVjwv0uN6CAxUAZNCyn7oSxOD+rvlvXi7SKCV27hluCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863497; 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=LYMY1TJzScePIyALLqkaqwZt57Dewu7kAwmHWhsDJLk=; b=mqWhz45pIQmymSczgk7jXV7blRUXEUeWDAU82Rf9IxXgCobugTy4TIcL3JFYjagiOAfXzuvFBi8UwSNXAh4CC6qlACK9bi+C/Qs5pgO9aWgnlRYGI+YhPzfBn+slBosMZG+h4ADb1tPiu2UDx7sXmmtED6cpH1uO4+E2Q9+YxVQ= 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 1598863497793754.6183125203365; Mon, 31 Aug 2020 01:44:57 -0700 (PDT) Received: from localhost ([::1]:57882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfQu-0005kB-9b for importer@patchew.org; Mon, 31 Aug 2020 04:44:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFh-0008Sg-RA for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:21552 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFa-0006bR-MO for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:21 -0400 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-112-F0GTGqJWPlm-gG8wr_oZvg-1; Mon, 31 Aug 2020 04:33:11 -0400 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 8288B10ABDB0; Mon, 31 Aug 2020 08:33:10 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id DACB760C04; Mon, 31 Aug 2020 08:33:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 215BD1FCF5; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862793; 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=LYMY1TJzScePIyALLqkaqwZt57Dewu7kAwmHWhsDJLk=; b=P3xeTeysAnVIJRbzN1rLcExudoy5uWo99ks/tbGuXIbg+iJ+eFPPTTkPwIhDLrxE5cM/Oj rxRcLURY2YAmvecWQQJPeXsbo8fYXJxYup1mwMvlWTtTZ1O5orWi7RMiB4CegKUSu4o/pP 926ZofHDwkAg2uROW3QOp/DcYTUJpkw= X-MC-Unique: F0GTGqJWPlm-gG8wr_oZvg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 06/18] docs: Add USB U2F key device documentation Date: Mon, 31 Aug 2020 10:32:49 +0200 Message-Id: <20200831083301.6357-7-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-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.001 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.120; envelope-from=kraxel@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 02:13:08 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley Add USB U2F key device documentation: - USB U2F key device - Building - Using u2f-emulated - Using u2f-passthru - Libu2f-emu Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-3-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- docs/u2f.txt | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 docs/u2f.txt diff --git a/docs/u2f.txt b/docs/u2f.txt new file mode 100644 index 000000000000..f60052882ec3 --- /dev/null +++ b/docs/u2f.txt @@ -0,0 +1,101 @@ +QEMU U2F Key Device Documentation. + +Contents +1. USB U2F key device +2. Building +3. Using u2f-emulated +4. Using u2f-passthru +5. Libu2f-emu + +1. USB U2F key device + +U2F is an open authentication standard that enables relying parties +exposed to the internet to offer a strong second factor option for end +user authentication. + +The standard brings many advantages to both parties, client and server, +allowing to reduce over-reliance on passwords, it increases authentication +security and simplifies passwords. + +The second factor is materialized by a device implementing the U2F +protocol. In case of a USB U2F security key, it is a USB HID device +that implements the U2F protocol. + +In Qemu, the USB U2F key device offers a dedicated support of U2F, allowing +guest USB FIDO/U2F security keys operating in two possible modes: +pass-through and emulated. + +The pass-through mode consists of passing all requests made from the guest +to the physical security key connected to the host machine and vice versa. +In addition, the dedicated pass-through allows to have a U2F security key +shared on several guests which is not possible with a simple host device +assignment pass-through. + +The emulated mode consists of completely emulating the behavior of an +U2F device through software part. Libu2f-emu is used for that. + + +2. Building + +To ensure the build of the u2f-emulated device variant which depends +on libu2f-emu: configuring and building: + + ./configure --enable-u2f && make + + +3. Using u2f-emulated + +To work, an emulated U2F device must have four elements: + * ec x509 certificate + * ec private key + * counter (four bytes value) + * 48 bytes of entropy (random bits) + +To use this type of device, this one has to be configured, and these +four elements must be passed one way or another. + +Assuming that you have a working libu2f-emu installed on the host. +There are three possible ways of configurations: + * ephemeral + * setup directory + * manual + +Ephemeral is the simplest way to configure, it lets the device generate +all the elements it needs for a single use of the lifetime of the device. + + qemu -usb -device u2f-emulated + +Setup directory allows to configure the device from a directory containing +four files: + * certificate.pem: ec x509 certificate + * private-key.pem: ec private key + * counter: counter value + * entropy: 48 bytes of entropy + + qemu -usb -device u2f-emulated,dir=3D$dir + +Manual allows to configure the device more finely by specifying each +of the elements necessary for the device: + * cert + * priv + * counter + * entropy + + qemu -usb -device u2f-emulated,cert=3D$DIR1/$FILE1,priv=3D$DIR2/$FILE2= ,counter=3D$DIR3/$FILE3,entropy=3D$DIR4/$FILE4 + + +4. Using u2f-passthru + +On the host specify the u2f-passthru device with a suitable hidraw: + + qemu -usb -device u2f-passthru,hidraw=3D/dev/hidraw0 + + +5. Libu2f-emu + +The u2f-emulated device uses libu2f-emu for the U2F key emulation. Libu2f-= emu +implements completely the U2F protocol device part for all specified +transport given by the FIDO Alliance. + +For more information about libu2f-emu see this page: +https://github.com/MattGorko/libu2f-emu. --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863026; cv=none; d=zohomail.com; s=zohoarc; b=iNm5oCMCici0TwmhBGANTN+Yg2NeZ0noxlOgxbbOiOmyc7Yl45PRBuy2djdoEy8w2Zx1k5tErrCLdrK/p1G12Gzvsb7mY9qgMq5uRsnLMlqDifxvTPeVvWj06vwagLPIUVBxe1AnZMFC25lG//GgcWnQ0ozNpqlGszBzAiViA2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863026; 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=6J2zt+T0zv9qukEkUS4yvFYuQ+2v0y+WJwvBDg4/bkw=; b=e342n8kdz1eMTpKYTQG50K3DMIdH9Xg30HoaUwhkoIWSMCFg93NI2QRZUL0q+fz6HoDB0JwQXYC3u6MAALvJKdpNP67932pNwmPykF5tsNP3L67luYv9fQBi3nQowIIkT7qxnoERN4y84NNdf9KYF19vgBZl0hVLnPjxf0V80WA= 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 15988630268070.5065849478346536; Mon, 31 Aug 2020 01:37:06 -0700 (PDT) Received: from localhost ([::1]:47736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfJJ-00070d-HJ for importer@patchew.org; Mon, 31 Aug 2020 04:37:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFZ-00089W-Ql for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFX-0006Zz-AY for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:13 -0400 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-244-RB-VYZXqPpmpMqFwe3_-ug-1; Mon, 31 Aug 2020 04:33:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8331110ABDA0; Mon, 31 Aug 2020 08:33:07 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAE66925BB; Mon, 31 Aug 2020 08:33:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2A4F6204AE; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862790; 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=6J2zt+T0zv9qukEkUS4yvFYuQ+2v0y+WJwvBDg4/bkw=; b=N/lu8ZLJz32hWCiwp/ef1lACNKrTf/OUq/Pjw4LeCUxDzdnVaOGI30p3kWF+boTIzUYhvb Hxdhf8kcs35hizE0MrS8chpDCssehXHbv2ROhFd0sQxeAmgNwh01B2pHboh8Kxm5mIXEeK BD0rmj3bued6QB7SFzj7yLct4gJeYoQ= X-MC-Unique: RB-VYZXqPpmpMqFwe3_-ug-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 07/18] hw/usb: Add U2F key base class Date: Mon, 31 Aug 2020 10:32:50 +0200 Message-Id: <20200831083301.6357-8-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.003 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=63.128.21.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:02:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley This patch adds the specification for the U2F key base class. Used to group the common characteristics, this device class will be inherited by its two variants, corresponding to the two modes: passthrough and emulated This prepares the U2F devices hierarchy which is as follow: USB device -> u2f-key -> {u2f-passthru, u2f-emulated}. Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-4-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- hw/usb/u2f.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 hw/usb/u2f.h diff --git a/hw/usb/u2f.h b/hw/usb/u2f.h new file mode 100644 index 000000000000..db30f3586bf7 --- /dev/null +++ b/hw/usb/u2f.h @@ -0,0 +1,92 @@ +/* + * U2F USB device. + * + * Copyright (c) 2020 C=C3=A9sar Belley + * Written by C=C3=A9sar Belley + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef U2F_H +#define U2F_H + +#include "hw/qdev-core.h" + +#define U2FHID_PACKET_SIZE 64 +#define U2FHID_PENDING_IN_NUM 32 + +typedef struct U2FKeyState U2FKeyState; +typedef struct U2FKeyInfo U2FKeyInfo; + +#define TYPE_U2F_KEY "u2f-key" +#define U2F_KEY(obj) \ + OBJECT_CHECK(U2FKeyState, (obj), TYPE_U2F_KEY) +#define U2F_KEY_CLASS(klass) \ + OBJECT_CLASS_CHECK(U2FKeyClass, (klass), TYPE_U2F_KEY) +#define U2F_KEY_GET_CLASS(obj) \ + OBJECT_GET_CLASS(U2FKeyClass, (obj), TYPE_U2F_KEY) + +/* + * Callbacks to be used by the U2F key base device (i.e. hw/u2f.c) + * to interact with its variants (i.e. hw/u2f-*.c) + */ +typedef struct U2FKeyClass { + /*< private >*/ + USBDeviceClass parent_class; + + /*< public >*/ + void (*recv_from_guest)(U2FKeyState *key, + const uint8_t packet[U2FHID_PACKET_SIZE]); + void (*realize)(U2FKeyState *key, Error **errp); + void (*unrealize)(U2FKeyState *key); +} U2FKeyClass; + +/* + * State of the U2F key base device (i.e. hw/u2f.c) + */ +typedef struct U2FKeyState { + USBDevice dev; + USBEndpoint *ep; + uint8_t idle; + + /* Pending packets to be send to the guest */ + uint8_t pending_in[U2FHID_PENDING_IN_NUM][U2FHID_PACKET_SIZE]; + uint8_t pending_in_start; + uint8_t pending_in_end; + uint8_t pending_in_num; +} U2FKeyState; + +/* + * API to be used by the U2F key device variants (i.e. hw/u2f-*.c) + * to interact with the the U2F key base device (i.e. hw/u2f.c) + */ +void u2f_send_to_guest(U2FKeyState *key, + const uint8_t packet[U2FHID_PACKET_SIZE]); + +extern const VMStateDescription vmstate_u2f_key; + +#define VMSTATE_U2F_KEY(_field, _state) { \ + .name =3D (stringify(_field)), \ + .size =3D sizeof(U2FKeyState), \ + .vmsd =3D &vmstate_u2f_key, \ + .flags =3D VMS_STRUCT, \ + .offset =3D vmstate_offset_value(_state, _field, U2FKeyState), \ +} + +#endif /* U2F_H */ --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598862872; cv=none; d=zohomail.com; s=zohoarc; b=MyP8cE0ZjK2CDSXF/d4IL7/GKIhVHfdPXB8guZOThgZeJdo/qkaQkg7H/yH05FFaecUU3azm8+wWUVdcMHdIMdS88WZNNCxwWXrzfT2zAbTu8gGgqtSD1lrRlNsxxxCgvYzI8pW07WZr34UYNHhKBo7OQrZ6OROvL6bmgXnJcz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598862872; 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=dTE+G237rTzPCXBR1JEpjCjPVXH6rj6XiPtZ2JTJp2c=; b=js6Kn+/RIgEv1M1dXhd/rCKLKK9QLv733pc+9kThE7fkyI/ctDak7hpAjnnBbxwkI0yBwvTCf0YnsbARL3SU3EAUM5slDldZnzVnYU+Im4afVg8/MFgLdSs6ghyRfmv/+VdcEdspG/mxgbITkU9Cf1pwmb1XqB0livDLfSwt198= 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 1598862872596479.58581744155754; Mon, 31 Aug 2020 01:34:32 -0700 (PDT) Received: from localhost ([::1]:34194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfGo-0001Xj-Pa for importer@patchew.org; Mon, 31 Aug 2020 04:34:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFa-0008Cz-TX for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:15 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:54720 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFY-0006aE-3y for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:14 -0400 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-382-qbO5k3QLPKuIZuz2HRNM3w-1; Mon, 31 Aug 2020 04:33:08 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DB46656BF5; Mon, 31 Aug 2020 08:33:07 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id E83CF2616B; Mon, 31 Aug 2020 08:33:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 341E531E23; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862791; 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=dTE+G237rTzPCXBR1JEpjCjPVXH6rj6XiPtZ2JTJp2c=; b=DyDG4CRBH3u8HegFomqC0HoOlIaXfn135R9nwUnURdWGRwD5oeVvEHJQ6/16FaVediLYWI KM938JMTn4yquk5hqJLiV1zw3nkJBpQOnEJmsLsOzL6wXD2fMlsCXwAe6h8rttYvxjxpea +7ZOtfX+Kxlts5tsu4CcBg86eLjM4UE= X-MC-Unique: qbO5k3QLPKuIZuz2HRNM3w-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 08/18] hw/usb: Add U2F key base class implementation Date: Mon, 31 Aug 2020 10:32:51 +0200 Message-Id: <20200831083301.6357-9-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.120; envelope-from=kraxel@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 02:13:08 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley This patch adds the U2F key base class implementation. The U2F key base mainly takes care of the HID interfacing with guest. On the one hand, it retrieves the guest U2FHID packets and transmits them to the variant associated according to the mode: pass-through or emulated. On the other hand, it provides the public API used by its variants to send U2FHID packets to the guest. Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-5-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- hw/usb/u2f.c | 352 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 352 insertions(+) create mode 100644 hw/usb/u2f.c diff --git a/hw/usb/u2f.c b/hw/usb/u2f.c new file mode 100644 index 000000000000..bc09191f063e --- /dev/null +++ b/hw/usb/u2f.c @@ -0,0 +1,352 @@ +/* + * U2F USB device. + * + * Copyright (c) 2020 C=C3=A9sar Belley + * Written by C=C3=A9sar Belley + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "hw/usb.h" +#include "hw/usb/hid.h" +#include "migration/vmstate.h" +#include "desc.h" + +#include "u2f.h" + +/* U2F key Vendor / Product */ +#define U2F_KEY_VENDOR_NUM 0x46f4 /* CRC16() of "QEMU" */ +#define U2F_KEY_PRODUCT_NUM 0x0005 + +enum { + STR_MANUFACTURER =3D 1, + STR_PRODUCT, + STR_SERIALNUMBER, + STR_CONFIG, + STR_INTERFACE +}; + +static const USBDescStrings desc_strings =3D { + [STR_MANUFACTURER] =3D "QEMU", + [STR_PRODUCT] =3D "U2F USB key", + [STR_SERIALNUMBER] =3D "0", + [STR_CONFIG] =3D "U2F key config", + [STR_INTERFACE] =3D "U2F key interface" +}; + +static const USBDescIface desc_iface_u2f_key =3D { + .bInterfaceNumber =3D 0, + .bNumEndpoints =3D 2, + .bInterfaceClass =3D USB_CLASS_HID, + .bInterfaceSubClass =3D 0x0, + .bInterfaceProtocol =3D 0x0, + .ndesc =3D 1, + .descs =3D (USBDescOther[]) { + { + /* HID descriptor */ + .data =3D (uint8_t[]) { + 0x09, /* u8 bLength */ + USB_DT_HID, /* u8 bDescriptorType */ + 0x10, 0x01, /* u16 HID_class */ + 0x00, /* u8 country_code */ + 0x01, /* u8 num_descriptors */ + USB_DT_REPORT, /* u8 type: Report */ + 0x22, 0, /* u16 len */ + }, + }, + }, + .eps =3D (USBDescEndpoint[]) { + { + .bEndpointAddress =3D USB_DIR_IN | 0x01, + .bmAttributes =3D USB_ENDPOINT_XFER_INT, + .wMaxPacketSize =3D U2FHID_PACKET_SIZE, + .bInterval =3D 0x05, + }, { + .bEndpointAddress =3D USB_DIR_OUT | 0x01, + .bmAttributes =3D USB_ENDPOINT_XFER_INT, + .wMaxPacketSize =3D U2FHID_PACKET_SIZE, + .bInterval =3D 0x05, + }, + }, + +}; + +static const USBDescDevice desc_device_u2f_key =3D { + .bcdUSB =3D 0x0100, + .bMaxPacketSize0 =3D U2FHID_PACKET_SIZE, + .bNumConfigurations =3D 1, + .confs =3D (USBDescConfig[]) { + { + .bNumInterfaces =3D 1, + .bConfigurationValue =3D 1, + .iConfiguration =3D STR_CONFIG, + .bmAttributes =3D USB_CFG_ATT_ONE, + .bMaxPower =3D 15, + .nif =3D 1, + .ifs =3D &desc_iface_u2f_key, + }, + }, +}; + +static const USBDesc desc_u2f_key =3D { + .id =3D { + .idVendor =3D U2F_KEY_VENDOR_NUM, + .idProduct =3D U2F_KEY_PRODUCT_NUM, + .bcdDevice =3D 0, + .iManufacturer =3D STR_MANUFACTURER, + .iProduct =3D STR_PRODUCT, + .iSerialNumber =3D STR_SERIALNUMBER, + }, + .full =3D &desc_device_u2f_key, + .str =3D desc_strings, +}; + +static const uint8_t u2f_key_hid_report_desc[] =3D { + 0x06, 0xd0, 0xf1, /* Usage Page (FIDO) */ + 0x09, 0x01, /* Usage (FIDO) */ + 0xa1, 0x01, /* Collection (HID Application) */ + 0x09, 0x20, /* Usage (FIDO data in) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x26, 0xFF, 0x00, /* Logical Maximum (0xff) */ + 0x75, 0x08, /* Report Size (8) */ + 0x95, 0x40, /* Report Count (0x40) */ + 0x81, 0x02, /* Input (Data, Variable, Absolute) */ + 0x09, 0x21, /* Usage (FIDO data out) */ + 0x15, 0x00, /* Logical Minimum (0) */ + 0x26, 0xFF, 0x00, /* Logical Maximum (0xFF) */ + 0x75, 0x08, /* Report Size (8) */ + 0x95, 0x40, /* Report Count (0x40) */ + 0x91, 0x02, /* Output (Data, Variable, Absolute) */ + 0xC0 /* End Collection */ +}; + +static void u2f_key_reset(U2FKeyState *key) +{ + key->pending_in_start =3D 0; + key->pending_in_end =3D 0; + key->pending_in_num =3D 0; +} + +static void u2f_key_handle_reset(USBDevice *dev) +{ + U2FKeyState *key =3D U2F_KEY(dev); + + u2f_key_reset(key); +} + +static void u2f_key_handle_control(USBDevice *dev, USBPacket *p, + int request, int value, int index, int length, uint8_t *dat= a) +{ + U2FKeyState *key =3D U2F_KEY(dev); + int ret; + + ret =3D usb_desc_handle_control(dev, p, request, value, index, length,= data); + if (ret >=3D 0) { + return; + } + + switch (request) { + case InterfaceRequest | USB_REQ_GET_DESCRIPTOR: + switch (value >> 8) { + case 0x22: + memcpy(data, u2f_key_hid_report_desc, + sizeof(u2f_key_hid_report_desc)); + p->actual_length =3D sizeof(u2f_key_hid_report_desc); + break; + default: + goto fail; + } + break; + case HID_GET_IDLE: + data[0] =3D key->idle; + p->actual_length =3D 1; + break; + case HID_SET_IDLE: + key->idle =3D (uint8_t)(value >> 8); + break; + default: + fail: + p->status =3D USB_RET_STALL; + break; + } + +} + +static void u2f_key_recv_from_guest(U2FKeyState *key, USBPacket *p) +{ + U2FKeyClass *kc =3D U2F_KEY_GET_CLASS(key); + uint8_t packet[U2FHID_PACKET_SIZE]; + + if (kc->recv_from_guest =3D=3D NULL || p->iov.size !=3D U2FHID_PACKET_= SIZE) { + return; + } + + usb_packet_copy(p, packet, p->iov.size); + kc->recv_from_guest(key, packet); +} + +static void u2f_pending_in_add(U2FKeyState *key, + const uint8_t packet[U2FHID_PACKET_SIZE]) +{ + uint8_t index; + + if (key->pending_in_num >=3D U2FHID_PENDING_IN_NUM) { + return; + } + + index =3D key->pending_in_end; + key->pending_in_end =3D (index + 1) % U2FHID_PENDING_IN_NUM; + ++key->pending_in_num; + + memcpy(key->pending_in[index], packet, U2FHID_PACKET_SIZE); +} + +static uint8_t *u2f_pending_in_get(U2FKeyState *key) +{ + uint8_t index; + + if (key->pending_in_num =3D=3D 0) { + return NULL; + } + + index =3D key->pending_in_start; + key->pending_in_start =3D (index + 1) % U2FHID_PENDING_IN_NUM; + --key->pending_in_num; + + return key->pending_in[index]; +} + +static void u2f_key_handle_data(USBDevice *dev, USBPacket *p) +{ + U2FKeyState *key =3D U2F_KEY(dev); + uint8_t *packet_in; + + /* Endpoint number check */ + if (p->ep->nr !=3D 1) { + p->status =3D USB_RET_STALL; + return; + } + + switch (p->pid) { + case USB_TOKEN_OUT: + u2f_key_recv_from_guest(key, p); + break; + case USB_TOKEN_IN: + packet_in =3D u2f_pending_in_get(key); + if (packet_in =3D=3D NULL) { + p->status =3D USB_RET_NAK; + return; + } + usb_packet_copy(p, packet_in, U2FHID_PACKET_SIZE); + break; + default: + p->status =3D USB_RET_STALL; + break; + } +} + +void u2f_send_to_guest(U2FKeyState *key, + const uint8_t packet[U2FHID_PACKET_SIZE]) +{ + u2f_pending_in_add(key, packet); + usb_wakeup(key->ep, 0); +} + +static void u2f_key_unrealize(USBDevice *dev) +{ + U2FKeyState *key =3D U2F_KEY(dev); + U2FKeyClass *kc =3D U2F_KEY_GET_CLASS(key); + + if (kc->unrealize !=3D NULL) { + kc->unrealize(key); + } +} + +static void u2f_key_realize(USBDevice *dev, Error **errp) +{ + U2FKeyState *key =3D U2F_KEY(dev); + U2FKeyClass *kc =3D U2F_KEY_GET_CLASS(key); + Error *local_err =3D NULL; + + usb_desc_create_serial(dev); + usb_desc_init(dev); + u2f_key_reset(key); + + if (kc->realize !=3D NULL) { + kc->realize(key, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + } + key->ep =3D usb_ep_get(dev, USB_TOKEN_IN, 1); +} + +const VMStateDescription vmstate_u2f_key =3D { + .name =3D "u2f-key", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_USB_DEVICE(dev, U2FKeyState), + VMSTATE_UINT8(idle, U2FKeyState), + VMSTATE_UINT8_2DARRAY(pending_in, U2FKeyState, + U2FHID_PENDING_IN_NUM, U2FHID_PACKET_SIZE), + VMSTATE_UINT8(pending_in_start, U2FKeyState), + VMSTATE_UINT8(pending_in_end, U2FKeyState), + VMSTATE_UINT8(pending_in_num, U2FKeyState), + VMSTATE_END_OF_LIST() + } +}; + +static void u2f_key_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + USBDeviceClass *uc =3D USB_DEVICE_CLASS(klass); + + uc->product_desc =3D "QEMU U2F USB key"; + uc->usb_desc =3D &desc_u2f_key; + uc->handle_reset =3D u2f_key_handle_reset; + uc->handle_control =3D u2f_key_handle_control; + uc->handle_data =3D u2f_key_handle_data; + uc->handle_attach =3D usb_desc_attach; + uc->realize =3D u2f_key_realize; + uc->unrealize =3D u2f_key_unrealize; + dc->desc =3D "QEMU U2F key"; + dc->vmsd =3D &vmstate_u2f_key; +} + +static const TypeInfo u2f_key_info =3D { + .name =3D TYPE_U2F_KEY, + .parent =3D TYPE_USB_DEVICE, + .instance_size =3D sizeof(U2FKeyState), + .abstract =3D true, + .class_size =3D sizeof(U2FKeyClass), + .class_init =3D u2f_key_class_init, +}; + +static void u2f_key_register_types(void) +{ + type_register_static(&u2f_key_info); + usb_legacy_register(TYPE_U2F_KEY, "u2f-key", NULL); +} + +type_init(u2f_key_register_types) --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863424; cv=none; d=zohomail.com; s=zohoarc; b=Q0BoODbp5QhTmnKwElUvdNe6SUpfQCrFE9TCGrNnOVzYoufgo1O8rHJIyv2uoJnTEzkACDWQ9n2BZ6pfQ2aCuULu0AyJk0IBS36dDq2n6tANEE5WtzQXmkiKgb6xDSGn/NFF3BBDzYEgBDXksV8zR7YpOZheFUzTNG72WMqwNJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863424; 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=xfX8++UP0VaXTlvY6Xl3dnABweKyPnmkj4qOIGoSEoA=; b=j0zV/WnFFbd8E3jDoQvO8HvuGO8zVV7Lg70cHpe3+1NQDFX10QCKnM8013rStFh6Ycs1KLiUOGtqGmCryBZoKGM1du3YFvg8SuzArkhAhod8l8B1SsbUWcpd4xSDw3FrgwuYltqNF1TvCOV60aGc2Lo4TKmLQ1aXDpbjKXxP9Rs= 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 1598863424971727.8590016421266; Mon, 31 Aug 2020 01:43:44 -0700 (PDT) Received: from localhost ([::1]:52666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfPj-0003cl-KS for importer@patchew.org; Mon, 31 Aug 2020 04:43:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFi-0008Tr-9A for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:22 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24280 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFb-0006bd-1u for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:21 -0400 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-122-X8wqLdjoOUq4rjQ8JdzFuw-1; Mon, 31 Aug 2020 04:33:11 -0400 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 975DD801AC4; Mon, 31 Aug 2020 08:33:10 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id E82E75C221; Mon, 31 Aug 2020 08:33:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 3E06631E68; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862794; 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=xfX8++UP0VaXTlvY6Xl3dnABweKyPnmkj4qOIGoSEoA=; b=h3dEG6FP00l4PNUUIr+AICqIL+Uo17DLfqFT94g+wcdhKr7GRCvowOuGH/uvZJOacq8JcP Gq6JwYFMw+zKZK2Wn9hatCaeW9fAq5o7VfyL/soqD9I+bFO1w4ZqsuPPT8CmIdPyVzKD7I si+nAu24xtnqYgiP5Uz/rBzDzuNGgKw= X-MC-Unique: X8wqLdjoOUq4rjQ8JdzFuw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 09/18] hw/usb: Add U2F key passthru mode Date: Mon, 31 Aug 2020 10:32:52 +0200 Message-Id: <20200831083301.6357-10-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-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.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.120; envelope-from=kraxel@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 02:13:08 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley This patch adds the U2F key pass-through mode. The pass-through mode consists of passing all requests made from the guest to the physical security key connected to the host machine and vice versa. In addition, the dedicated pass-through allows to have a U2F security key shared on several guests which is not possible with a simple host device assignment pass-through. The pass-through mode is associated with a device inheriting from u2f-key base. To work, it needs the path to a U2F hidraw, obtained from the Qemu command line, and passed by the user: qemu -usb -device u2f-passthru,hidraw=3D/dev/hidrawX Autoscan and U2F compatibility checking features are given at the end of the patch series. Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-6-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- hw/usb/u2f-passthru.c | 423 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 423 insertions(+) create mode 100644 hw/usb/u2f-passthru.c diff --git a/hw/usb/u2f-passthru.c b/hw/usb/u2f-passthru.c new file mode 100644 index 000000000000..52b44670775d --- /dev/null +++ b/hw/usb/u2f-passthru.c @@ -0,0 +1,423 @@ +/* + * U2F USB Passthru device. + * + * Copyright (c) 2020 C=C3=A9sar Belley + * Written by C=C3=A9sar Belley + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qemu/main-loop.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/usb.h" +#include "migration/vmstate.h" + +#include "u2f.h" + +#define NONCE_SIZE 8 +#define BROADCAST_CID 0xFFFFFFFF +#define TRANSACTION_TIMEOUT 120000 + +struct transaction { + uint32_t cid; + uint16_t resp_bcnt; + uint16_t resp_size; + + /* Nonce for broadcast isolation */ + uint8_t nonce[NONCE_SIZE]; +}; + +typedef struct U2FPassthruState U2FPassthruState; + +#define CURRENT_TRANSACTIONS_NUM 4 + +struct U2FPassthruState { + U2FKeyState base; + + /* Host device */ + char *hidraw; + int hidraw_fd; + + /* Current Transactions */ + struct transaction current_transactions[CURRENT_TRANSACTIONS_NUM]; + uint8_t current_transactions_start; + uint8_t current_transactions_end; + uint8_t current_transactions_num; + + /* Transaction time checking */ + int64_t last_transaction_time; + QEMUTimer timer; +}; + +#define TYPE_U2F_PASSTHRU "u2f-passthru" +#define PASSTHRU_U2F_KEY(obj) \ + OBJECT_CHECK(U2FPassthruState, (obj), TYPE_U2F_PASSTHRU) + +/* Init packet sizes */ +#define PACKET_INIT_HEADER_SIZE 7 +#define PACKET_INIT_DATA_SIZE (U2FHID_PACKET_SIZE - PACKET_INIT_HEADER_SIZ= E) + +/* Cont packet sizes */ +#define PACKET_CONT_HEADER_SIZE 5 +#define PACKET_CONT_DATA_SIZE (U2FHID_PACKET_SIZE - PACKET_CONT_HEADER_SIZ= E) + +struct packet_init { + uint32_t cid; + uint8_t cmd; + uint8_t bcnth; + uint8_t bcntl; + uint8_t data[PACKET_INIT_DATA_SIZE]; +} QEMU_PACKED; + +static inline uint32_t packet_get_cid(const void *packet) +{ + return *((uint32_t *)packet); +} + +static inline bool packet_is_init(const void *packet) +{ + return ((uint8_t *)packet)[4] & (1 << 7); +} + +static inline uint16_t packet_init_get_bcnt( + const struct packet_init *packet_init) +{ + uint16_t bcnt =3D 0; + bcnt |=3D packet_init->bcnth << 8; + bcnt |=3D packet_init->bcntl; + + return bcnt; +} + +static void u2f_passthru_reset(U2FPassthruState *key) +{ + timer_del(&key->timer); + qemu_set_fd_handler(key->hidraw_fd, NULL, NULL, key); + key->last_transaction_time =3D 0; + key->current_transactions_start =3D 0; + key->current_transactions_end =3D 0; + key->current_transactions_num =3D 0; +} + +static void u2f_timeout_check(void *opaque) +{ + U2FPassthruState *key =3D opaque; + int64_t time =3D qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL); + + if (time > key->last_transaction_time + TRANSACTION_TIMEOUT) { + u2f_passthru_reset(key); + } else { + timer_mod(&key->timer, time + TRANSACTION_TIMEOUT / 4); + } +} + +static int u2f_transaction_get_index(U2FPassthruState *key, uint32_t cid) +{ + for (int i =3D 0; i < key->current_transactions_num; ++i) { + int index =3D (key->current_transactions_start + i) + % CURRENT_TRANSACTIONS_NUM; + if (cid =3D=3D key->current_transactions[index].cid) { + return index; + } + } + return -1; +} + +static struct transaction *u2f_transaction_get(U2FPassthruState *key, + uint32_t cid) +{ + int index =3D u2f_transaction_get_index(key, cid); + if (index < 0) { + return NULL; + } + return &key->current_transactions[index]; +} + +static struct transaction *u2f_transaction_get_from_nonce(U2FPassthruState= *key, + const uint8_t nonce[NONCE_SIZE]) +{ + for (int i =3D 0; i < key->current_transactions_num; ++i) { + int index =3D (key->current_transactions_start + i) + % CURRENT_TRANSACTIONS_NUM; + if (key->current_transactions[index].cid =3D=3D BROADCAST_CID + && memcmp(nonce, key->current_transactions[index].nonce, + NONCE_SIZE) =3D=3D 0) { + return &key->current_transactions[index]; + } + } + return NULL; +} + +static void u2f_transaction_close(U2FPassthruState *key, uint32_t cid) +{ + int index, next_index; + index =3D u2f_transaction_get_index(key, cid); + if (index < 0) { + return; + } + next_index =3D (index + 1) % CURRENT_TRANSACTIONS_NUM; + + /* Rearrange to ensure the oldest is at the start position */ + while (next_index !=3D key->current_transactions_end) { + memcpy(&key->current_transactions[index], + &key->current_transactions[next_index], + sizeof(struct transaction)); + + index =3D next_index; + next_index =3D (index + 1) % CURRENT_TRANSACTIONS_NUM; + } + + key->current_transactions_end =3D index; + --key->current_transactions_num; + + if (key->current_transactions_num =3D=3D 0) { + u2f_passthru_reset(key); + } +} + +static void u2f_transaction_add(U2FPassthruState *key, uint32_t cid, + const uint8_t nonce[NONCE_SIZE]) +{ + uint8_t index; + struct transaction *transaction; + + if (key->current_transactions_num >=3D CURRENT_TRANSACTIONS_NUM) { + /* Close the oldest transaction */ + index =3D key->current_transactions_start; + transaction =3D &key->current_transactions[index]; + u2f_transaction_close(key, transaction->cid); + } + + /* Index */ + index =3D key->current_transactions_end; + key->current_transactions_end =3D (index + 1) % CURRENT_TRANSACTIONS_N= UM; + ++key->current_transactions_num; + + /* Transaction */ + transaction =3D &key->current_transactions[index]; + transaction->cid =3D cid; + transaction->resp_bcnt =3D 0; + transaction->resp_size =3D 0; + + /* Nonce */ + if (nonce !=3D NULL) { + memcpy(transaction->nonce, nonce, NONCE_SIZE); + } +} + +static void u2f_passthru_read(void *opaque); + +static void u2f_transaction_start(U2FPassthruState *key, + const struct packet_init *packet_init) +{ + int64_t time; + + /* Transaction */ + if (packet_init->cid =3D=3D BROADCAST_CID) { + u2f_transaction_add(key, packet_init->cid, packet_init->data); + } else { + u2f_transaction_add(key, packet_init->cid, NULL); + } + + /* Time */ + time =3D qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL); + if (key->last_transaction_time =3D=3D 0) { + qemu_set_fd_handler(key->hidraw_fd, u2f_passthru_read, NULL, key); + timer_init_ms(&key->timer, QEMU_CLOCK_VIRTUAL, u2f_timeout_check, = key); + timer_mod(&key->timer, time + TRANSACTION_TIMEOUT / 4); + } + key->last_transaction_time =3D time; +} + +static void u2f_passthru_recv_from_host(U2FPassthruState *key, + const uint8_t packet[U2FHID_PACKET_SIZ= E]) +{ + struct transaction *transaction; + uint32_t cid; + + /* Retrieve transaction */ + cid =3D packet_get_cid(packet); + if (cid =3D=3D BROADCAST_CID) { + struct packet_init *packet_init; + if (!packet_is_init(packet)) { + return; + } + packet_init =3D (struct packet_init *)packet; + transaction =3D u2f_transaction_get_from_nonce(key, packet_init->d= ata); + } else { + transaction =3D u2f_transaction_get(key, cid); + } + + /* Ignore no started transaction */ + if (transaction =3D=3D NULL) { + return; + } + + if (packet_is_init(packet)) { + struct packet_init *packet_init =3D (struct packet_init *)packet; + transaction->resp_bcnt =3D packet_init_get_bcnt(packet_init); + transaction->resp_size =3D PACKET_INIT_DATA_SIZE; + + if (packet_init->cid =3D=3D BROADCAST_CID) { + /* Nonce checking for legitimate response */ + if (memcmp(transaction->nonce, packet_init->data, NONCE_SIZE) + !=3D 0) { + return; + } + } + } else { + transaction->resp_size +=3D PACKET_CONT_DATA_SIZE; + } + + /* Transaction end check */ + if (transaction->resp_size >=3D transaction->resp_bcnt) { + u2f_transaction_close(key, cid); + } + u2f_send_to_guest(&key->base, packet); +} + +static void u2f_passthru_read(void *opaque) +{ + U2FPassthruState *key =3D opaque; + U2FKeyState *base =3D &key->base; + uint8_t packet[2 * U2FHID_PACKET_SIZE]; + int ret; + + /* Full size base queue check */ + if (base->pending_in_num >=3D U2FHID_PENDING_IN_NUM) { + return; + } + + ret =3D read(key->hidraw_fd, packet, sizeof(packet)); + if (ret < 0) { + /* Detach */ + if (base->dev.attached) { + usb_device_detach(&base->dev); + u2f_passthru_reset(key); + } + return; + } + if (ret !=3D U2FHID_PACKET_SIZE) { + return; + } + u2f_passthru_recv_from_host(key, packet); +} + +static void u2f_passthru_recv_from_guest(U2FKeyState *base, + const uint8_t packet[U2FHID_PACKET_SIZ= E]) +{ + U2FPassthruState *key =3D PASSTHRU_U2F_KEY(base); + uint8_t host_packet[U2FHID_PACKET_SIZE + 1]; + ssize_t written; + + if (packet_is_init(packet)) { + u2f_transaction_start(key, (struct packet_init *)packet); + } + + host_packet[0] =3D 0; + memcpy(host_packet + 1, packet, U2FHID_PACKET_SIZE); + + written =3D write(key->hidraw_fd, host_packet, sizeof(host_packet)); + if (written !=3D sizeof(host_packet)) { + error_report("%s: Bad written size (req 0x%zu, val 0x%zd)", + TYPE_U2F_PASSTHRU, sizeof(host_packet), written); + } +} + +static void u2f_passthru_unrealize(U2FKeyState *base) +{ + U2FPassthruState *key =3D PASSTHRU_U2F_KEY(base); + + u2f_passthru_reset(key); + qemu_close(key->hidraw_fd); +} + +static void u2f_passthru_realize(U2FKeyState *base, Error **errp) +{ + U2FPassthruState *key =3D PASSTHRU_U2F_KEY(base); + int fd; + + if (key->hidraw =3D=3D NULL) { + error_setg(errp, "%s: Missing hidraw", TYPE_U2F_PASSTHRU); + return; + } + + fd =3D qemu_open(key->hidraw, O_RDWR); + if (fd < 0) { + error_setg(errp, "%s: Failed to open %s", TYPE_U2F_PASSTHRU, + key->hidraw); + return; + } + key->hidraw_fd =3D fd; + u2f_passthru_reset(key); +} + +static int u2f_passthru_post_load(void *opaque, int version_id) +{ + U2FPassthruState *key =3D opaque; + u2f_passthru_reset(key); + return 0; +} + +static const VMStateDescription u2f_passthru_vmstate =3D { + .name =3D "u2f-key-passthru", + .version_id =3D 1, + .minimum_version_id =3D 1, + .post_load =3D u2f_passthru_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_U2F_KEY(base, U2FPassthruState), + VMSTATE_END_OF_LIST() + } +}; + +static Property u2f_passthru_properties[] =3D { + DEFINE_PROP_STRING("hidraw", U2FPassthruState, hidraw), + DEFINE_PROP_END_OF_LIST(), +}; + +static void u2f_passthru_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + U2FKeyClass *kc =3D U2F_KEY_CLASS(klass); + + kc->realize =3D u2f_passthru_realize; + kc->unrealize =3D u2f_passthru_unrealize; + kc->recv_from_guest =3D u2f_passthru_recv_from_guest; + dc->desc =3D "QEMU U2F passthrough key"; + dc->vmsd =3D &u2f_passthru_vmstate; + device_class_set_props(dc, u2f_passthru_properties); +} + +static const TypeInfo u2f_key_passthru_info =3D { + .name =3D TYPE_U2F_PASSTHRU, + .parent =3D TYPE_U2F_KEY, + .instance_size =3D sizeof(U2FPassthruState), + .class_init =3D u2f_passthru_class_init +}; + +static void u2f_key_passthru_register_types(void) +{ + type_register_static(&u2f_key_passthru_info); +} + +type_init(u2f_key_passthru_register_types) --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863141; cv=none; d=zohomail.com; s=zohoarc; b=UVB20FgJPJX/CX3q8Fw4eXWLUPSYoUdH+oYiP6SYyxFHKMcAMaQ4qCQT4azfUHgBfIigoxbjbHdbl5DppsxXVLNrBU7/YUTYFuEHRYuk4z2GpjgXo9b4MIbFvV6KflAIUTm3URT94UbGDPaTD2lVWJSWckNw0dSQWiMLUtx9Us8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863141; 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=4FAgqbOoChHUalvFenlqqEy3ehfL0sTPRx5XtHq0V9o=; b=QdLTRgQ8iserQO10EZ+DX74xhiOX8dbxBOrUHqltIDDeoSEAMIGgqq6NjbzWUinigbc7QnQ7ProGVjFzzbdjFFGZ9hbhCxSuYuS0I0tbiZLDEW8SVdOhoqTFYEpm8TtQPEGZJnuar0K8Df2onsuXnRRtNrK+2uDNHj3OgpeS9p4= 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 15988631415016.804200065985242; Mon, 31 Aug 2020 01:39:01 -0700 (PDT) Received: from localhost ([::1]:56170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfLA-0001zw-4N for importer@patchew.org; Mon, 31 Aug 2020 04:39:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFe-0008Ke-Qk for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:18 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25798 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFZ-0006ar-N0 for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:18 -0400 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-244-wWql7zb9N-2_Idb14j_nkQ-1; Mon, 31 Aug 2020 04:33:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D45A310ABDA4; Mon, 31 Aug 2020 08:33:07 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB1D1614F9; Mon, 31 Aug 2020 08:33:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 480C231E7F; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862792; 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=4FAgqbOoChHUalvFenlqqEy3ehfL0sTPRx5XtHq0V9o=; b=HICuvCdH3tSea4flRkmLnD68tqhXX0Yi/X7wYqp77xcwCiHsMaLNz8NdNs0oDFXyVGF8vs GmfASM38/kYW/8RKI7YCNaiicSMbnoWixbYrGisvqgK0AjZQ4CWYSymsOsCBcdp+ysj0cf 9hw09yZUOg3fyABhijBkq4hWcPS642M= X-MC-Unique: wWql7zb9N-2_Idb14j_nkQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 10/18] hw/usb: Add U2F key emulated mode Date: Mon, 31 Aug 2020 10:32:53 +0200 Message-Id: <20200831083301.6357-11-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.120; envelope-from=kraxel@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 02:13:08 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley This patch adds the U2F key emulated mode. The emulated mode consists of completely emulating the behavior of a U2F device through software part. Libu2f-emu is used for that. The emulated mode is associated with a device inheriting from u2f-key base. To work, an emulated U2F device must have differents elements which can be given in different ways. This is detailed in docs/u2f.txt. The Ephemeral one is the simplest way to configure, it lets the device generate all the elements it needs for a single use of the lifetime of the device: qemu -usb -device u2f-emulated For more information about libu2f-emu see this page: https://github.com/MattGorko/libu2f-emu. Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-7-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- hw/usb/u2f-emulated.c | 405 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 405 insertions(+) create mode 100644 hw/usb/u2f-emulated.c diff --git a/hw/usb/u2f-emulated.c b/hw/usb/u2f-emulated.c new file mode 100644 index 000000000000..9e1b829f3d32 --- /dev/null +++ b/hw/usb/u2f-emulated.c @@ -0,0 +1,405 @@ +/* + * U2F USB Emulated device. + * + * Copyright (c) 2020 C=C3=A9sar Belley + * Written by C=C3=A9sar Belley + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qemu/thread.h" +#include "qemu/main-loop.h" +#include "qapi/error.h" +#include "hw/usb.h" +#include "hw/qdev-properties.h" + +#include + +#include "u2f.h" + +/* Counter which sync with a file */ +struct synced_counter { + /* Emulated device counter */ + struct u2f_emu_vdev_counter vdev_counter; + + /* Private attributes */ + uint32_t value; + FILE *fp; +}; + +static void counter_increment(struct u2f_emu_vdev_counter *vdev_counter) +{ + struct synced_counter *counter =3D (struct synced_counter *)vdev_count= er; + ++counter->value; + + /* Write back */ + if (fseek(counter->fp, 0, SEEK_SET) =3D=3D -1) { + return; + } + fprintf(counter->fp, "%u\n", counter->value); +} + +static uint32_t counter_read(struct u2f_emu_vdev_counter *vdev_counter) +{ + struct synced_counter *counter =3D (struct synced_counter *)vdev_count= er; + return counter->value; +} + +typedef struct U2FEmulatedState U2FEmulatedState; + +#define PENDING_OUT_NUM 32 + +struct U2FEmulatedState { + U2FKeyState base; + + /* U2F virtual emulated device */ + u2f_emu_vdev *vdev; + QemuMutex vdev_mutex; + + /* Properties */ + char *dir; + char *cert; + char *privkey; + char *entropy; + char *counter; + struct synced_counter synced_counter; + + /* Pending packets received from the guest */ + uint8_t pending_out[PENDING_OUT_NUM][U2FHID_PACKET_SIZE]; + uint8_t pending_out_start; + uint8_t pending_out_end; + uint8_t pending_out_num; + QemuMutex pending_out_mutex; + + /* Emulation thread and sync */ + QemuCond key_cond; + QemuMutex key_mutex; + QemuThread key_thread; + bool stop_thread; + EventNotifier notifier; +}; + +#define TYPE_U2F_EMULATED "u2f-emulated" +#define EMULATED_U2F_KEY(obj) \ + OBJECT_CHECK(U2FEmulatedState, (obj), TYPE_U2F_EMULATED) + +static void u2f_emulated_reset(U2FEmulatedState *key) +{ + key->pending_out_start =3D 0; + key->pending_out_end =3D 0; + key->pending_out_num =3D 0; +} + +static void u2f_pending_out_add(U2FEmulatedState *key, + const uint8_t packet[U2FHID_PACKET_SIZE]) +{ + int index; + + if (key->pending_out_num >=3D PENDING_OUT_NUM) { + return; + } + + index =3D key->pending_out_end; + key->pending_out_end =3D (index + 1) % PENDING_OUT_NUM; + ++key->pending_out_num; + + memcpy(&key->pending_out[index], packet, U2FHID_PACKET_SIZE); +} + +static uint8_t *u2f_pending_out_get(U2FEmulatedState *key) +{ + int index; + + if (key->pending_out_num =3D=3D 0) { + return NULL; + } + + index =3D key->pending_out_start; + key->pending_out_start =3D (index + 1) % PENDING_OUT_NUM; + --key->pending_out_num; + + return key->pending_out[index]; +} + +static void u2f_emulated_recv_from_guest(U2FKeyState *base, + const uint8_t packet[U2FHID_PACKET_SIZ= E]) +{ + U2FEmulatedState *key =3D EMULATED_U2F_KEY(base); + + qemu_mutex_lock(&key->pending_out_mutex); + u2f_pending_out_add(key, packet); + qemu_mutex_unlock(&key->pending_out_mutex); + + qemu_mutex_lock(&key->key_mutex); + qemu_cond_signal(&key->key_cond); + qemu_mutex_unlock(&key->key_mutex); +} + +static void *u2f_emulated_thread(void* arg) +{ + U2FEmulatedState *key =3D arg; + uint8_t packet[U2FHID_PACKET_SIZE]; + uint8_t *packet_out =3D NULL; + + + while (true) { + /* Wait signal */ + qemu_mutex_lock(&key->key_mutex); + qemu_cond_wait(&key->key_cond, &key->key_mutex); + qemu_mutex_unlock(&key->key_mutex); + + /* Exit thread check */ + if (key->stop_thread) { + key->stop_thread =3D false; + break; + } + + qemu_mutex_lock(&key->pending_out_mutex); + packet_out =3D u2f_pending_out_get(key); + if (packet_out =3D=3D NULL) { + qemu_mutex_unlock(&key->pending_out_mutex); + continue; + } + memcpy(packet, packet_out, U2FHID_PACKET_SIZE); + qemu_mutex_unlock(&key->pending_out_mutex); + + qemu_mutex_lock(&key->vdev_mutex); + u2f_emu_vdev_send(key->vdev, U2F_EMU_USB, packet, + U2FHID_PACKET_SIZE); + + /* Notify response */ + if (u2f_emu_vdev_has_response(key->vdev, U2F_EMU_USB)) { + event_notifier_set(&key->notifier); + } + qemu_mutex_unlock(&key->vdev_mutex); + } + return NULL; +} + +static ssize_t u2f_emulated_read(const char *path, char *buffer, + size_t buffer_len) +{ + int fd; + ssize_t ret; + + fd =3D qemu_open(path, O_RDONLY); + if (fd < 0) { + return -1; + } + + ret =3D read(fd, buffer, buffer_len); + close(fd); + + return ret; +} + +static bool u2f_emulated_setup_counter(const char *path, + struct synced_counter *counter) +{ + int fd, ret; + FILE *fp; + + fd =3D qemu_open(path, O_RDWR); + if (fd < 0) { + return false; + } + fp =3D fdopen(fd, "r+"); + if (fp =3D=3D NULL) { + close(fd); + return false; + } + ret =3D fscanf(fp, "%u", &counter->value); + if (ret =3D=3D EOF) { + fclose(fp); + return false; + } + counter->fp =3D fp; + counter->vdev_counter.counter_increment =3D counter_increment; + counter->vdev_counter.counter_read =3D counter_read; + + return true; +} + +static u2f_emu_rc u2f_emulated_setup_vdev_manualy(U2FEmulatedState *key) +{ + ssize_t ret; + char cert_pem[4096], privkey_pem[2048]; + struct u2f_emu_vdev_setup setup_info; + + /* Certificate */ + ret =3D u2f_emulated_read(key->cert, cert_pem, sizeof(cert_pem)); + if (ret < 0) { + return -1; + } + + /* Private key */ + ret =3D u2f_emulated_read(key->privkey, privkey_pem, sizeof(privkey_pe= m)); + if (ret < 0) { + return -1; + } + + /* Entropy */ + ret =3D u2f_emulated_read(key->entropy, (char *)&setup_info.entropy, + sizeof(setup_info.entropy)); + if (ret < 0) { + return -1; + } + + /* Counter */ + if (!u2f_emulated_setup_counter(key->counter, &key->synced_counter)) { + return -1; + } + + /* Setup */ + setup_info.certificate =3D cert_pem; + setup_info.private_key =3D privkey_pem; + setup_info.counter =3D (struct u2f_emu_vdev_counter *)&key->synced_cou= nter; + + return u2f_emu_vdev_new(&key->vdev, &setup_info); +} + +static void u2f_emulated_event_handler(EventNotifier *notifier) +{ + U2FEmulatedState *key =3D container_of(notifier, U2FEmulatedState, not= ifier); + size_t packet_size; + uint8_t *packet_in =3D NULL; + + event_notifier_test_and_clear(&key->notifier); + qemu_mutex_lock(&key->vdev_mutex); + while (u2f_emu_vdev_has_response(key->vdev, U2F_EMU_USB)) { + packet_size =3D u2f_emu_vdev_get_response(key->vdev, U2F_EMU_USB, + &packet_in); + if (packet_size =3D=3D U2FHID_PACKET_SIZE) { + u2f_send_to_guest(&key->base, packet_in); + } + u2f_emu_vdev_free_response(packet_in); + } + qemu_mutex_unlock(&key->vdev_mutex); +} + +static void u2f_emulated_realize(U2FKeyState *base, Error **errp) +{ + U2FEmulatedState *key =3D EMULATED_U2F_KEY(base); + u2f_emu_rc rc; + + if (key->cert !=3D NULL || key->privkey !=3D NULL || key->entropy !=3D= NULL + || key->counter !=3D NULL) { + if (key->cert !=3D NULL && key->privkey !=3D NULL + && key->entropy !=3D NULL && key->counter !=3D NULL) { + rc =3D u2f_emulated_setup_vdev_manualy(key); + } else { + error_setg(errp, "%s: cert, priv, entropy and counter " + "parameters must be provided to manualy configure " + "the emulated device", TYPE_U2F_EMULATED); + return; + } + } else if (key->dir !=3D NULL) { + rc =3D u2f_emu_vdev_new_from_dir(&key->vdev, key->dir); + } else { + rc =3D u2f_emu_vdev_new_ephemeral(&key->vdev); + } + + if (rc !=3D U2F_EMU_OK) { + error_setg(errp, "%s: Failed to setup the key", TYPE_U2F_EMULATED); + return; + } + + if (event_notifier_init(&key->notifier, false) < 0) { + error_setg(errp, "%s: Failed to initialize notifier", + TYPE_U2F_EMULATED); + return; + } + /* Notifier */ + event_notifier_set_handler(&key->notifier, u2f_emulated_event_handler); + + /* Synchronization */ + qemu_cond_init(&key->key_cond); + qemu_mutex_init(&key->vdev_mutex); + qemu_mutex_init(&key->pending_out_mutex); + qemu_mutex_init(&key->key_mutex); + u2f_emulated_reset(key); + + /* Thread */ + key->stop_thread =3D false; + qemu_thread_create(&key->key_thread, "u2f-key", u2f_emulated_thread, + key, QEMU_THREAD_JOINABLE); +} + +static void u2f_emulated_unrealize(U2FKeyState *base) +{ + U2FEmulatedState *key =3D EMULATED_U2F_KEY(base); + + /* Thread */ + key->stop_thread =3D true; + qemu_cond_signal(&key->key_cond); + qemu_thread_join(&key->key_thread); + + /* Notifier */ + event_notifier_set_handler(&key->notifier, NULL); + event_notifier_cleanup(&key->notifier); + + /* Synchronization */ + qemu_cond_destroy(&key->key_cond); + qemu_mutex_destroy(&key->vdev_mutex); + qemu_mutex_destroy(&key->key_mutex); + qemu_mutex_destroy(&key->pending_out_mutex); + + /* Vdev */ + u2f_emu_vdev_free(key->vdev); + if (key->synced_counter.fp !=3D NULL) { + fclose(key->synced_counter.fp); + } +} + +static Property u2f_emulated_properties[] =3D { + DEFINE_PROP_STRING("dir", U2FEmulatedState, dir), + DEFINE_PROP_STRING("cert", U2FEmulatedState, cert), + DEFINE_PROP_STRING("privkey", U2FEmulatedState, privkey), + DEFINE_PROP_STRING("entropy", U2FEmulatedState, entropy), + DEFINE_PROP_STRING("counter", U2FEmulatedState, counter), + DEFINE_PROP_END_OF_LIST(), +}; + +static void u2f_emulated_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + U2FKeyClass *kc =3D U2F_KEY_CLASS(klass); + + kc->realize =3D u2f_emulated_realize; + kc->unrealize =3D u2f_emulated_unrealize; + kc->recv_from_guest =3D u2f_emulated_recv_from_guest; + dc->desc =3D "QEMU U2F emulated key"; + device_class_set_props(dc, u2f_emulated_properties); +} + +static const TypeInfo u2f_key_emulated_info =3D { + .name =3D TYPE_U2F_EMULATED, + .parent =3D TYPE_U2F_KEY, + .instance_size =3D sizeof(U2FEmulatedState), + .class_init =3D u2f_emulated_class_init +}; + +static void u2f_key_emulated_register_types(void) +{ + type_register_static(&u2f_key_emulated_info); +} + +type_init(u2f_key_emulated_register_types) --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863248; cv=none; d=zohomail.com; s=zohoarc; b=mY7CpZvoC3smZ5AJachipwBx3cdXkSV83fM3SkorQ6xhxdAHk1pO2M2E4KbrOlo4Pr4wGzRTSViCt3lMfVzWQGNoHCeXZ5UKx1c7+t5YyiwuiKS8C4eCEfg413+mvJR8Lg3Aocwp5Zmr8n3AJXb+TtJLBOaWuyQRPn2daHQrzx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863248; 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=hb6mji1t6o7RyM8/HLLvWch7l8WoCA0NUDV8RprI/SE=; b=RHt4hrsLy8O7zcJT9iw43sSkzn+9kR5mrxm70v2ewsECDkrhE2Jy2K7VfAi+hSLvvxyE2vHiA5BB0H+oxhD3j8uWSXwTRsM9sKIknX2O7YRe1KhflfuDzBXw88i41/TKraHHivgoahJ3J/JZWZAih6VhlsHTaxU3PrkpOSH25wM= 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 1598863248910667.4392092256443; Mon, 31 Aug 2020 01:40:48 -0700 (PDT) Received: from localhost ([::1]:36420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfMt-0005Vo-HV for importer@patchew.org; Mon, 31 Aug 2020 04:40:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFf-0008LC-1N for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:19 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:59985 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFa-0006b6-1P for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:18 -0400 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-91-O1dQhoNoNmKXGVV9qUUnaQ-1; Mon, 31 Aug 2020 04:33:09 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 52C031007466; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAD841002D59; Mon, 31 Aug 2020 08:33:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 57A4F31E88; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862793; 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=hb6mji1t6o7RyM8/HLLvWch7l8WoCA0NUDV8RprI/SE=; b=AW/NP4dMldmUw4GqHnv5lEhEEWlj4cSPtA4bVGmbUdovx95ut4IzV9u11bFUtyd8MjH/VB hCUUlhHL83Aw3RiyMdiAgIeQ9p5ykD0R1sN0rNXSMp6nS7V5cvHh/7NH7c4tZHp6Y8ZGyQ 4H3jiA1hH2RDaiZ0+u62rcW4IdLJi+g= X-MC-Unique: O1dQhoNoNmKXGVV9qUUnaQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 11/18] meson: Add U2F key to meson Date: Mon, 31 Aug 2020 10:32:54 +0200 Message-Id: <20200831083301.6357-12-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=207.211.31.81; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:06:35 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-8-cesar.belley@lse.epita.fr [ fixes suggested by paolo ] Signed-off-by: Gerd Hoffmann --- configure | 8 +++++++- meson_options.txt | 1 + hw/usb/Kconfig | 5 +++++ hw/usb/meson.build | 7 +++++++ meson.build | 7 +++++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 6ecaff429b1b..8dc981684bb9 100755 --- a/configure +++ b/configure @@ -495,6 +495,7 @@ trace_file=3D"trace" spice=3D"" rbd=3D"" smartcard=3D"" +u2f=3D"auto" libusb=3D"" usb_redir=3D"" opengl=3D"" @@ -1415,6 +1416,10 @@ for opt do ;; --enable-smartcard) smartcard=3D"yes" ;; + --disable-u2f) u2f=3D"disabled" + ;; + --enable-u2f) u2f=3D"enabled" + ;; --disable-libusb) libusb=3D"no" ;; --enable-libusb) libusb=3D"yes" @@ -1945,6 +1950,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: libiscsi iscsi support libnfs nfs support smartcard smartcard support (libcacard) + u2f U2F support (u2f-emu) libusb libusb (for usb passthrough) live-block-migration Block migration in the main migration stream usb-redir usb network redirection support @@ -8229,7 +8235,7 @@ NINJA=3D${ninja:-$PWD/ninjatool} $meson setup \ -Db_coverage=3D$(if test "$gcov" =3D yes; then echo true; else ech= o false; fi) \ -Dsdl=3D$sdl -Dsdl_image=3D$sdl_image \ -Dvnc=3D$vnc -Dvnc_sasl=3D$vnc_sasl -Dvnc_jpeg=3D$vnc_jpeg -Dvnc_png=3D$v= nc_png \ - -Dgettext=3D$gettext -Dxkbcommon=3D$xkbcommon \ + -Dgettext=3D$gettext -Dxkbcommon=3D$xkbcommon -Du2f=3D$u2f\ $cross_arg \ "$PWD" "$source_path" =20 diff --git a/meson_options.txt b/meson_options.txt index c55f9cd94cb2..aef2de652332 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,6 +1,7 @@ option('gettext', type : 'boolean', value : true) option('sdl', type : 'feature', value : 'auto') option('sdl_image', type : 'feature', value : 'auto') +option('u2f', type : 'feature', value : 'auto') option('vnc', type : 'feature', value : 'enabled') option('vnc_jpeg', type : 'feature', value : 'auto') option('vnc_png', type : 'feature', value : 'auto') diff --git a/hw/usb/Kconfig b/hw/usb/Kconfig index 5e63dc75f815..3fc8fbe3c74c 100644 --- a/hw/usb/Kconfig +++ b/hw/usb/Kconfig @@ -96,6 +96,11 @@ config USB_STORAGE_MTP default y depends on USB =20 +config USB_U2F + bool + default y + depends on USB + config IMX_USBPHY bool default y diff --git a/hw/usb/meson.build b/hw/usb/meson.build index 3c44a1b06954..a25109b88c91 100644 --- a/hw/usb/meson.build +++ b/hw/usb/meson.build @@ -50,6 +50,13 @@ if config_host.has_key('CONFIG_SMARTCARD') hw_usb_modules +=3D {'smartcard': usbsmartcard_ss} endif =20 +# U2F +softmmu_ss.add(when: 'CONFIG_USB_U2F', if_true: files('u2f.c')) +softmmu_ss.add(when: ['CONFIG_LINUX', 'CONFIG_USB_U2F'], if_true: files('u= 2f-passthru.c')) +if u2f.found() + softmmu_ss.add(when: 'CONFIG_USB_U2F', if_true: [u2f, files('u2f-emulate= d.c')]) +endif + # usb redirect if config_host.has_key('CONFIG_USB_REDIR') usbredir_ss =3D ss.source_set() diff --git a/meson.build b/meson.build index 74f8ea0c2e11..1e7aee85e33a 100644 --- a/meson.build +++ b/meson.build @@ -377,6 +377,12 @@ if 'CONFIG_SMARTCARD' in config_host cacard =3D declare_dependency(compile_args: config_host['SMARTCARD_CFLAG= S'].split(), link_args: config_host['SMARTCARD_LIBS'].spl= it()) endif +u2f =3D not_found +if have_system + u2f =3D dependency('u2f-emu', required: get_option('u2f'), + method: 'pkg-config', + static: enable_static) +endif usbredir =3D not_found if 'CONFIG_USB_REDIR' in config_host usbredir =3D declare_dependency(compile_args: config_host['USB_REDIR_CFL= AGS'].split(), @@ -1375,6 +1381,7 @@ summary_info +=3D {'spice support': config_host.h= as_key('CONFIG_SPICE')} summary_info +=3D {'rbd support': config_host.has_key('CONFIG_RBD')} summary_info +=3D {'xfsctl support': config_host.has_key('CONFIG_XFS')} summary_info +=3D {'smartcard support': config_host.has_key('CONFIG_SMARTC= ARD')} +summary_info +=3D {'U2F support': u2f.found()} summary_info +=3D {'libusb': config_host.has_key('CONFIG_USB_LI= BUSB')} summary_info +=3D {'usb net redir': config_host.has_key('CONFIG_USB_RE= DIR')} summary_info +=3D {'OpenGL support': config_host.has_key('CONFIG_OPENGL= ')} --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863324; cv=none; d=zohomail.com; s=zohoarc; b=OEN5I4mbiKdCn+pk1ZzABQ5WGlXnUeJW/SkNvzGkBus0NwFV2inGZkdJ7r9UXln63/170+qh32K9M2F/2KzXZs+9Rx4fP7P7tLNWo/ShRLTBQylj+RYKh5utTOYgIcozLKlYgm12PiUavk243iNxt2zNrBK6WyQ5O36sq9BhehA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863324; 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=Nz2sZrJX4qzBF63OonFqdCb3a+jIn0R8qkWmHt5YvFQ=; b=YdHjSxJI7xZVUEfrh7NPqVVAZhVd+GpK2j3ExjXofO4wi1kAkzKkOGLnbHsdpeSYVzYqbblpDWQiY5dfdKMyQxZLsY7/XH+JRf8rIe+dzqTd8XaRpYgsyk5c+voY2R8dsA5T002Htpjaad4Ul+suotfvS2UwlxB5Zo5D4yvMv/s= 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 1598863324128736.3216848123287; Mon, 31 Aug 2020 01:42:04 -0700 (PDT) Received: from localhost ([::1]:44768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfO6-0000R9-U3 for importer@patchew.org; Mon, 31 Aug 2020 04:42:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFg-0008P9-Ir for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:20 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:25701 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFa-0006b9-5j for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:20 -0400 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-204-5EeA2ekFNRyn3DrF34dVdg-1; Mon, 31 Aug 2020 04:33:11 -0400 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 1DFC218A2241; Mon, 31 Aug 2020 08:33:10 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id E83335C22B; Mon, 31 Aug 2020 08:33:06 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 6066D31F09; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862793; 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=Nz2sZrJX4qzBF63OonFqdCb3a+jIn0R8qkWmHt5YvFQ=; b=Fi89GcZwj6SAKX3sIWj2hI2LlGe4xVxD1A6AD8IYddWWnk9Y4PUvwk6f9RIEJafTO83cTi DAXZJwk98DD1HMSKiiSwA3wmlwKDcHr6JKIuKQOg/tRxXJzZwpSDnm08QfiuGWP+hDRfwZ JdmqB5re9QLi3Q7A9ZMCwNN11waR+OY= X-MC-Unique: 5EeA2ekFNRyn3DrF34dVdg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 12/18] docs/system: Add U2F key to the USB devices examples Date: Mon, 31 Aug 2020 10:32:55 +0200 Message-Id: <20200831083301.6357-13-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-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.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.120; envelope-from=kraxel@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 02:13:08 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-9-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- docs/system/usb.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/system/usb.rst b/docs/system/usb.rst index ddfa828d74ae..9a2f1927c451 100644 --- a/docs/system/usb.rst +++ b/docs/system/usb.rst @@ -81,6 +81,9 @@ option or the ``device_add`` monitor command. Available d= evices are: ``usb-audio`` USB audio device =20 +``u2f-{emulated,passthru}`` + Universal Second Factor device + .. _host_005fusb_005fdevices: =20 Using host USB devices on a Linux host --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863184; cv=none; d=zohomail.com; s=zohoarc; b=RLmla/uCfcm9UgB35Ul4mcEl2997e8LPvJ44qjKJgTP7VqFE6gR+IV1f2kJztxpC7J9Q2NDKweNvTbcr8hUPSW/xwV8xoqW8aWIqAwKndNWtM2JOwTM8QthyNT1FsTUbK6cR/hvtKWO6/GMx41t4shXI7qgrj33qmD2XtDznd7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863184; 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=Pj6QbpvhXb4xod3nciQRVD0Eay61+3ZfpSS93t0PtVU=; b=YQ6aIpBx40qcM/GIHIRvn6m68b8972k/ysr/ImzkZ8yvec6oQDmYaO/2ppCrj61wk4FZYq2+FmniETpPSkj5UVjy4NthWHsxavX026yemf1vNVALgI0PF/12W3/kEWnkEt6xTJl7Pv369/wneDuYZ2POxrAeVRHpZt3yf4VCxtg= 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 1598863184374471.2307861521783; Mon, 31 Aug 2020 01:39:44 -0700 (PDT) Received: from localhost ([::1]:59440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfLq-0003Jk-W3 for importer@patchew.org; Mon, 31 Aug 2020 04:39:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFg-0008Og-DX for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48611) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFa-0006bU-Mt for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:20 -0400 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-91-6XZfvslvPPq3eBdjEmMCXA-1; Mon, 31 Aug 2020 04:33:09 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8BCA8802B7B; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 392B987A70; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 6987931FBC; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862793; 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=Pj6QbpvhXb4xod3nciQRVD0Eay61+3ZfpSS93t0PtVU=; b=iHqbwqUiAHhCIM7r81yZR38mNjaqt1/MJZVFp9WAfhaFIgTplJXSoq6qrnAmd1fy/V5m8W PHqaLwWqOIMVlJyX2ssSFWi2zPr1NdClRUjEavAKQDDVepbAEZO3A8bAedamOQI9it+NVX Crc06LAq6TrATBzqt7E4VcEw+4SGLuE= X-MC-Unique: 6XZfvslvPPq3eBdjEmMCXA-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 13/18] docs/qdev-device-use.txt: Add USB U2F key to the QDEV devices examples Date: Mon, 31 Aug 2020 10:32:56 +0200 Message-Id: <20200831083301.6357-14-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:43:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-10-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- docs/qdev-device-use.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt index f8d0d2fe297a..9889521e3c07 100644 --- a/docs/qdev-device-use.txt +++ b/docs/qdev-device-use.txt @@ -325,6 +325,7 @@ The new way is -device DEVNAME,DEV-OPTS... Details dep= end on DRIVER: * mouse -device usb-mouse * tablet -device usb-tablet * wacom-tablet -device usb-wacom-tablet +* u2f -device u2f-{emulated,passthru} * braille See "Character Devices" =20 =3D=3D=3D Watchdog Devices =3D=3D=3D --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863445; cv=none; d=zohomail.com; s=zohoarc; b=DtpCIFgfSr1tlAxUoG1zMzMnKVzpsXIVFsniqXWQojN5eZ9fPEcU/4G89KXbxxIPPl+RjBx9pwblj3VmUiwJOSE6unVWUa8fkVFgTwfGYWueKqb/e1rnpve72qYH48QO+D+yUXpuT47aAceJTn1H7hXrm4LNgPJLu5Y5WE6D4iQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863445; 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=wq5Pda4Lt5SRqI7o7hjLCdVq24fwCUMV/EoS3UXA+x0=; b=Hn1OHLx7XVC9lvrDrRwj0YDbQ9Kr1NH3XSWYRH3Tdlch6NiDDymt/dcMFwcrp3k3hsws9AXqYtZJN7cWjqKju7HlhxV8YGVZVG8LFk7toGcNf0a8ns1wvc8RhWbW/nwQOzBaGAy586tizZ4tXtXVTyS38WHQfiNzrwrXAD9m1tI= 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 1598863445422550.0654573446516; Mon, 31 Aug 2020 01:44:05 -0700 (PDT) Received: from localhost ([::1]:54516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfQ4-0004N4-45 for importer@patchew.org; Mon, 31 Aug 2020 04:44:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFf-0008N3-Ne for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:19 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:43960 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFa-0006bP-Lx for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:19 -0400 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-54-X9GvElQKNqeC8Ba6-s7K6Q-1; Mon, 31 Aug 2020 04:33:10 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4FB6F18A224A; Mon, 31 Aug 2020 08:33:09 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7BE32616B; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 72EF331FC3; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862793; 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=wq5Pda4Lt5SRqI7o7hjLCdVq24fwCUMV/EoS3UXA+x0=; b=HSg0yUqvL8D12IENb4tTuqxL3Wef3gjCjKLB3miL5cCL1+Kjk0IMdFQTe9iWsuH5UegE8B p9L+GmQ3N06UGantAUs/7ar8NbckIYTXxA+cCQVwEwdPTvgl+Ge3MlT5Yu4Mkgp5Hudinn x5WfYNwGxgQ+xJV8jVsV2I7em+Ro1So= X-MC-Unique: X9GvElQKNqeC8Ba6-s7K6Q-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 14/18] scripts: Add u2f-setup-gen script Date: Mon, 31 Aug 2020 10:32:57 +0200 Message-Id: <20200831083301.6357-15-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.61; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:56:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley This patch adds the script used to generate setup directories, needed for the device u2f-emulated configuration in directory mode: python u2f-setup-gen.py $DIR qemu -usb -device u2f-emulated,dir=3D$DIR Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-11-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- scripts/u2f-setup-gen.py | 170 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100755 scripts/u2f-setup-gen.py diff --git a/scripts/u2f-setup-gen.py b/scripts/u2f-setup-gen.py new file mode 100755 index 000000000000..2122598fed8e --- /dev/null +++ b/scripts/u2f-setup-gen.py @@ -0,0 +1,170 @@ +#!/usr/bin/env python3 +# +# Libu2f-emu setup directory generator for USB U2F key emulation. +# +# Copyright (c) 2020 C=C3=A9sar Belley +# Written by C=C3=A9sar Belley +# +# This work is licensed under the terms of the GNU GPL, version 2 +# or, at your option, any later version. See the COPYING file in +# the top-level directory. + +import sys +import os +from random import randint +from typing import Tuple + +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives.asymmetric import ec +from cryptography.hazmat.primitives.serialization import Encoding, \ + NoEncryption, PrivateFormat, PublicFormat +from OpenSSL import crypto + + +def write_setup_dir(dirpath: str, privkey_pem: bytes, cert_pem: bytes, + entropy: bytes, counter: int) -> None: + """ + Write the setup directory. + + Args: + dirpath: The directory path. + key_pem: The private key PEM. + cert_pem: The certificate PEM. + entropy: The 48 bytes of entropy. + counter: The counter value. + """ + # Directory + os.mkdir(dirpath) + + # Private key + with open(f'{dirpath}/private-key.pem', 'bw') as f: + f.write(privkey_pem) + + # Certificate + with open(f'{dirpath}/certificate.pem', 'bw') as f: + f.write(cert_pem) + + # Entropy + with open(f'{dirpath}/entropy', 'wb') as f: + f.write(entropy) + + # Counter + with open(f'{dirpath}/counter', 'w') as f: + f.write(f'{str(counter)}\n') + + +def generate_ec_key_pair() -> Tuple[str, str]: + """ + Generate an ec key pair. + + Returns: + The private and public key PEM. + """ + # Key generation + privkey =3D ec.generate_private_key(ec.SECP256R1, default_backend()) + pubkey =3D privkey.public_key() + + # PEM serialization + privkey_pem =3D privkey.private_bytes(encoding=3DEncoding.PEM, + format=3DPrivateFormat.Traditional= OpenSSL, + encryption_algorithm=3DNoEncryptio= n()) + pubkey_pem =3D pubkey.public_bytes(encoding=3DEncoding.PEM, + format=3DPublicFormat.SubjectPublicKe= yInfo) + return privkey_pem, pubkey_pem + + +def generate_certificate(privkey_pem: str, pubkey_pem: str) -> str: + """ + Generate a x509 certificate from a key pair. + + Args: + privkey_pem: The private key PEM. + pubkey_pem: The public key PEM. + + Returns: + The certificate PEM. + """ + # Convert key pair + privkey =3D crypto.load_privatekey(crypto.FILETYPE_PEM, privkey_pem) + pubkey =3D crypto.load_publickey(crypto.FILETYPE_PEM, pubkey_pem) + + # New x509v3 certificate + cert =3D crypto.X509() + cert.set_version(0x2) + + # Serial number + cert.set_serial_number(randint(1, 2 ** 64)) + + # Before / After + cert.gmtime_adj_notBefore(0) + cert.gmtime_adj_notAfter(4 * (365 * 24 * 60 * 60)) + + # Public key + cert.set_pubkey(pubkey) + + # Subject name and issueer + cert.get_subject().CN =3D "U2F emulated" + cert.set_issuer(cert.get_subject()) + + # Extensions + cert.add_extensions([ + crypto.X509Extension(b"subjectKeyIdentifier", + False, b"hash", subject=3Dcert), + ]) + cert.add_extensions([ + crypto.X509Extension(b"authorityKeyIdentifier", + False, b"keyid:always", issuer=3Dcert), + ]) + cert.add_extensions([ + crypto.X509Extension(b"basicConstraints", True, b"CA:TRUE") + ]) + + # Signature + cert.sign(privkey, 'sha256') + + return crypto.dump_certificate(crypto.FILETYPE_PEM, cert) + + +def generate_setup_dir(dirpath: str) -> None: + """ + Generates the setup directory. + + Args: + dirpath: The directory path. + """ + # Key pair + privkey_pem, pubkey_pem =3D generate_ec_key_pair() + + # Certificate + certificate_pem =3D generate_certificate(privkey_pem, pubkey_pem) + + # Entropy + entropy =3D os.urandom(48) + + # Counter + counter =3D 0 + + # Write + write_setup_dir(dirpath, privkey_pem, certificate_pem, entropy, counte= r) + + +def main() -> None: + """ + Main function + """ + # Dir path + if len(sys.argv) !=3D 2: + sys.stderr.write(f'Usage: {sys.argv[0]} \n') + exit(2) + dirpath =3D sys.argv[1] + + # Dir non existence + if os.path.exists(dirpath): + sys.stderr.write(f'Directory: {dirpath} already exists.\n') + exit(1) + + generate_setup_dir(dirpath) + + +if __name__ =3D=3D '__main__': + main() --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863176; cv=none; d=zohomail.com; s=zohoarc; b=LApGJrjtLW5I6Ea/r6u5C4gT/grsxSpTb6zidX8bspvgX6NyT0//xWJN6qnNDemwj1esvNeYOTTa2jsSYR6kNXT4LB5Q3cY4tyGvQEEOKKRgwuiGvtprpRWTxBKfWzOBZGHg7qXek/Yybxq0IbiijbhVnmFaFdm4T4bb86H0rZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863176; 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=iMjAeZE8KysOCotHdYlErXQLpMhSFzcspX0W4u/w6y8=; b=RGEO4OmakScuOm775j0ebQpJ+uUA+LxlKs08QZWoELy+LgHWqd6O6RMkm8gpZd9pEikqhQrTYdAAGbF0McnzCmRZxU2o1LBkJt/FUcXfc8pdsUTTpTip55Vkp1WNeBopQv/S6tdnGuc3iJhd4pj7EDYB1Hw4DeU1AL5m+mPCan8= 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 1598863176926311.7338527674166; Mon, 31 Aug 2020 01:39:36 -0700 (PDT) Received: from localhost ([::1]:58762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfLj-00031m-GM for importer@patchew.org; Mon, 31 Aug 2020 04:39:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFd-0008H7-5O for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:17 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:35914 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFY-0006aS-PV for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:16 -0400 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-576-9E0N5tIaMmGDELe9sUCw7w-1; Mon, 31 Aug 2020 04:33:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E14418A225C; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35D073A40; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 7BFA831FC5; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862792; 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=iMjAeZE8KysOCotHdYlErXQLpMhSFzcspX0W4u/w6y8=; b=QflCidQXSqnCw1AY0+vBflRXJ2XH2Lu7QZIDyVJAytv76bSrjl4C4/M975mUeX7CeVffk2 tZjqXGuTDDaZA5/R3OqxbB9A/HvXYo5LZxtqX+aeyz5o5EsmSdpRVKJHlUPDJ11Bi749wH 8KuNeHhJlhQypdA+GUHyW9xNX5vDnsU= X-MC-Unique: 9E0N5tIaMmGDELe9sUCw7w-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 15/18] hw/usb: Add U2F device check to passthru mode Date: Mon, 31 Aug 2020 10:32:58 +0200 Message-Id: <20200831083301.6357-16-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.61; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:56:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley This patchs adds a check to verify that the device passed through the hidraw property is a U2F device. The check is done by ensuring that the first values of the report descriptor (USAGE PAGE and USAGE) correspond to those of a U2F device. Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-12-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- hw/usb/u2f-passthru.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/hw/usb/u2f-passthru.c b/hw/usb/u2f-passthru.c index 52b44670775d..74d4ae6e9294 100644 --- a/hw/usb/u2f-passthru.c +++ b/hw/usb/u2f-passthru.c @@ -34,6 +34,12 @@ =20 #include "u2f.h" =20 +#ifdef CONFIG_LIBUDEV +#include +#endif +#include +#include + #define NONCE_SIZE 8 #define BROADCAST_CID 0xFFFFFFFF #define TRANSACTION_TIMEOUT 120000 @@ -344,6 +350,34 @@ static void u2f_passthru_recv_from_guest(U2FKeyState *= base, } } =20 +static bool u2f_passthru_is_u2f_device(int fd) +{ + int ret, rdesc_size; + struct hidraw_report_descriptor rdesc; + const uint8_t u2f_hid_report_desc_header[] =3D { + 0x06, 0xd0, 0xf1, /* Usage Page (FIDO) */ + 0x09, 0x01, /* Usage (FIDO) */ + }; + + /* Get report descriptor size */ + ret =3D ioctl(fd, HIDIOCGRDESCSIZE, &rdesc_size); + if (ret < 0 || rdesc_size < sizeof(u2f_hid_report_desc_header)) { + return false; + } + + /* Get report descriptor */ + memset(&rdesc, 0x0, sizeof(rdesc)); + rdesc.size =3D rdesc_size; + ret =3D ioctl(fd, HIDIOCGRDESC, &rdesc); + if (ret < 0) { + return false; + } + + /* Header bytes cover specific U2F rdesc values */ + return memcmp(u2f_hid_report_desc_header, rdesc.value, + sizeof(u2f_hid_report_desc_header)) =3D=3D 0; +} + static void u2f_passthru_unrealize(U2FKeyState *base) { U2FPassthruState *key =3D PASSTHRU_U2F_KEY(base); @@ -368,6 +402,13 @@ static void u2f_passthru_realize(U2FKeyState *base, Er= ror **errp) key->hidraw); return; } + + if (!u2f_passthru_is_u2f_device(fd)) { + qemu_close(fd); + error_setg(errp, "%s: Passed hidraw does not represent " + "a U2F HID device", TYPE_U2F_PASSTHRU); + return; + } key->hidraw_fd =3D fd; u2f_passthru_reset(key); } --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598862979; cv=none; d=zohomail.com; s=zohoarc; b=jh5oCsNWHoo2xrIZgN+MFtWgoIY+EJNLmpyh3V9Krou+ZHHX3GlW/7I3OI7thuGKpiJMjyq86hDkUELY9VnPYUP+B0PZTq0lhsnpP1JEjRZwdtm9WiMD8isYbIo9OLxjb+XE4hzIqaQv0AX/+B6jZoyZtvVOOFEhruQzQ6glY7w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598862979; 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=sJ/vUDTa8rToYl7gXD645Fj7KHedX4qEsoI1hsq6SB8=; b=JMCToE8yNk9nsODl2YFG9LscK7uOnhXlWkt/sUBP/BalPExEgRlVkGPIfRq6Er2KuopnsHRlEfNxrJR6OVBi7gcDGWPy2d7UmJ/5xGhnd0auPaOEGOAQGu0HkBOZkTRq9cNsaqgos6u6//PjxWagJYcVS32lqa3WDdbQ5E4v3fQ= 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 1598862979640655.02060063703; Mon, 31 Aug 2020 01:36:19 -0700 (PDT) Received: from localhost ([::1]:42668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfIY-0004zw-Bx for importer@patchew.org; Mon, 31 Aug 2020 04:36:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFb-0008EW-Uc for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:15 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:36722 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFZ-0006ad-4G for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:15 -0400 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-532-RX_4cIgxOcaLDqsV-Y9H9A-1; Mon, 31 Aug 2020 04:33:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30457100746D; Mon, 31 Aug 2020 08:33:09 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB274614F9; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8F0C031FC6; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862792; 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=sJ/vUDTa8rToYl7gXD645Fj7KHedX4qEsoI1hsq6SB8=; b=JLTNlqwg2w1Xw0k9yCBo+08ajQxakfOkPtwKp6MdBQjU4aVBjWTo7Nne5If+9oW4wY1KMl y2NSnYa+G8CUEDKaiyM1dGmXXposwMzsliB4nTH3MRP0HhpehGEc53Uu32E+KzGnRPQMtj 5hiah9m8b+ER/zW2GxDOyVtiaKlzdGg= X-MC-Unique: RX_4cIgxOcaLDqsV-Y9H9A-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 16/18] hw/usb: Add U2F device autoscan to passthru mode Date: Mon, 31 Aug 2020 10:32:59 +0200 Message-Id: <20200831083301.6357-17-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.120; envelope-from=kraxel@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 02:13:08 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?C=C3=A9sar=20Belley?= , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9sar Belley This patch adds an autoscan to let u2f-passthru choose the first U2F device it finds. The autoscan is performed using libudev with an enumeration of all the hidraw devices present on the host. The first device which happens to be a U2F device is taken to do the passtru. Signed-off-by: C=C3=A9sar Belley Message-id: 20200826114209.28821-13-cesar.belley@lse.epita.fr Signed-off-by: Gerd Hoffmann --- docs/u2f.txt | 9 ++++ hw/usb/u2f-passthru.c | 113 +++++++++++++++++++++++++++++++++++++----- hw/usb/meson.build | 2 +- 3 files changed, 110 insertions(+), 14 deletions(-) diff --git a/docs/u2f.txt b/docs/u2f.txt index f60052882ec3..8f44994818a2 100644 --- a/docs/u2f.txt +++ b/docs/u2f.txt @@ -42,6 +42,10 @@ on libu2f-emu: configuring and building: =20 ./configure --enable-u2f && make =20 +The pass-through mode is built by default on Linux. To take advantage +of the autoscan option it provides, make sure you have a working libudev +installed on the host. + =20 3. Using u2f-emulated =20 @@ -90,6 +94,11 @@ On the host specify the u2f-passthru device with a suita= ble hidraw: =20 qemu -usb -device u2f-passthru,hidraw=3D/dev/hidraw0 =20 +Alternately, the u2f-passthru device can autoscan to take the first +U2F device it finds on the host (this requires a working libudev): + + qemu -usb -device u2f-passthru + =20 5. Libu2f-emu =20 diff --git a/hw/usb/u2f-passthru.c b/hw/usb/u2f-passthru.c index 74d4ae6e9294..e9c8aa459586 100644 --- a/hw/usb/u2f-passthru.c +++ b/hw/usb/u2f-passthru.c @@ -378,6 +378,84 @@ static bool u2f_passthru_is_u2f_device(int fd) sizeof(u2f_hid_report_desc_header)) =3D=3D 0; } =20 +#ifdef CONFIG_LIBUDEV +static int u2f_passthru_open_from_device(struct udev_device *device) +{ + const char *devnode =3D udev_device_get_devnode(device); + + int fd =3D qemu_open(devnode, O_RDWR); + if (fd < 0) { + return -1; + } else if (!u2f_passthru_is_u2f_device(fd)) { + qemu_close(fd); + return -1; + } + return fd; +} + +static int u2f_passthru_open_from_enumerate(struct udev *udev, + struct udev_enumerate *enumera= te) +{ + struct udev_list_entry *devices, *entry; + int ret, fd; + + ret =3D udev_enumerate_scan_devices(enumerate); + if (ret < 0) { + return -1; + } + + devices =3D udev_enumerate_get_list_entry(enumerate); + udev_list_entry_foreach(entry, devices) { + struct udev_device *device; + const char *syspath =3D udev_list_entry_get_name(entry); + + if (syspath =3D=3D NULL) { + continue; + } + + device =3D udev_device_new_from_syspath(udev, syspath); + if (device =3D=3D NULL) { + continue; + } + + fd =3D u2f_passthru_open_from_device(device); + udev_device_unref(device); + if (fd >=3D 0) { + return fd; + } + } + return -1; +} + +static int u2f_passthru_open_from_scan(void) +{ + struct udev *udev; + struct udev_enumerate *enumerate; + int ret, fd =3D -1; + + udev =3D udev_new(); + if (udev =3D=3D NULL) { + return -1; + } + + enumerate =3D udev_enumerate_new(udev); + if (enumerate =3D=3D NULL) { + udev_unref(udev); + return -1; + } + + ret =3D udev_enumerate_add_match_subsystem(enumerate, "hidraw"); + if (ret >=3D 0) { + fd =3D u2f_passthru_open_from_enumerate(udev, enumerate); + } + + udev_enumerate_unref(enumerate); + udev_unref(udev); + + return fd; +} +#endif + static void u2f_passthru_unrealize(U2FKeyState *base) { U2FPassthruState *key =3D PASSTHRU_U2F_KEY(base); @@ -392,22 +470,31 @@ static void u2f_passthru_realize(U2FKeyState *base, E= rror **errp) int fd; =20 if (key->hidraw =3D=3D NULL) { +#ifdef CONFIG_LIBUDEV + fd =3D u2f_passthru_open_from_scan(); + if (fd < 0) { + error_setg(errp, "%s: Failed to find a U2F USB device", + TYPE_U2F_PASSTHRU); + return; + } +#else error_setg(errp, "%s: Missing hidraw", TYPE_U2F_PASSTHRU); return; - } +#endif + } else { + fd =3D qemu_open(key->hidraw, O_RDWR); + if (fd < 0) { + error_setg(errp, "%s: Failed to open %s", TYPE_U2F_PASSTHRU, + key->hidraw); + return; + } =20 - fd =3D qemu_open(key->hidraw, O_RDWR); - if (fd < 0) { - error_setg(errp, "%s: Failed to open %s", TYPE_U2F_PASSTHRU, - key->hidraw); - return; - } - - if (!u2f_passthru_is_u2f_device(fd)) { - qemu_close(fd); - error_setg(errp, "%s: Passed hidraw does not represent " - "a U2F HID device", TYPE_U2F_PASSTHRU); - return; + if (!u2f_passthru_is_u2f_device(fd)) { + qemu_close(fd); + error_setg(errp, "%s: Passed hidraw does not represent " + "a U2F HID device", TYPE_U2F_PASSTHRU); + return; + } } key->hidraw_fd =3D fd; u2f_passthru_reset(key); diff --git a/hw/usb/meson.build b/hw/usb/meson.build index a25109b88c91..b7c7ff23bfbd 100644 --- a/hw/usb/meson.build +++ b/hw/usb/meson.build @@ -52,7 +52,7 @@ endif =20 # U2F softmmu_ss.add(when: 'CONFIG_USB_U2F', if_true: files('u2f.c')) -softmmu_ss.add(when: ['CONFIG_LINUX', 'CONFIG_USB_U2F'], if_true: files('u= 2f-passthru.c')) +softmmu_ss.add(when: ['CONFIG_LINUX', 'CONFIG_USB_U2F'], if_true: [libudev= , files('u2f-passthru.c')]) if u2f.found() softmmu_ss.add(when: 'CONFIG_USB_U2F', if_true: [u2f, files('u2f-emulate= d.c')]) endif --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863059; cv=none; d=zohomail.com; s=zohoarc; b=atGhSDBVejAu4nqoJ4tUyUefGAQDcdRT9WiWy47LplcND7kDmOMtaTy/pMSHB4+uUyVi9CgZKUvxuLdHd/Yy7TYGstiE+vDw5SB2lqQ29hYl/Azxlx/F0VuRN7GO6xQR6B0ZrqtrTyH6tm23kdHZwCvKASMUlZVJ4pXTnZm3Xj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863059; 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=e7ADtjUCvvlcoWLUsdaaSfb862SflFQHg7D9hEwKRwc=; b=C6d29SOUXiNKdPYa/mGuiYRK6nH9kITsHKZO/slIQgZzWBQBCwH53MT3YyMuhecMvUJIZr93joR5qMwL1/PRc2XovVfhhUSVgEOoPcBDjlLY0jIx0AgkEu4g8xsZy3RlK91MuY4O8PP6Eo9Pg1ZB3TvDp9MbZ68gcuJdchHVh/s= 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 1598863059531877.554216436906; Mon, 31 Aug 2020 01:37:39 -0700 (PDT) Received: from localhost ([::1]:50370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfJq-000831-6Z for importer@patchew.org; Mon, 31 Aug 2020 04:37:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFa-0008AD-4Y for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:14 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:43594 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFY-0006aB-14 for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:13 -0400 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-578-KjjZgV3_MBG5nV7cKHXOEQ-1; Mon, 31 Aug 2020 04:33:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9AEC4100748B for ; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D5F37EB74; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 97DED31FC7; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862791; 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=e7ADtjUCvvlcoWLUsdaaSfb862SflFQHg7D9hEwKRwc=; b=TO7fg66RCqK+oc65hd5q2JVDeczp2Y48XMGp3ystvd/EWLKXW3cwW3gFgCmUIABcyNuIVq ZSi3JazOtyDzagjIzpyk8CaKB0MV7LhpgY4+SB789oiqUzwmSjJSlzosQQTzL4WeewDHX0 BEw3UQcEPG05VHPtpoLX8Sg4I1ZA1bc= X-MC-Unique: KjjZgV3_MBG5nV7cKHXOEQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 17/18] usb-host: workaround libusb bug Date: Mon, 31 Aug 2020 10:33:00 +0200 Message-Id: <20200831083301.6357-18-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.001 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=205.139.110.61; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 03:56:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , Eduardo Habkost , Cleber Rosa 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" libusb_get_device_speed() does not work for libusb_wrap_sys_device() devices in v1.0.23. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1871090 Signed-off-by: Gerd Hoffmann Message-id: 20200824110057.32089-1-kraxel@redhat.com --- hw/usb/host-libusb.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index c474551d8456..08604f787fdf 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -39,6 +39,11 @@ #endif #include =20 +#ifdef CONFIG_LINUX +#include +#include +#endif + #include "qapi/error.h" #include "migration/vmstate.h" #include "monitor/monitor.h" @@ -885,6 +890,7 @@ static void usb_host_ep_update(USBHostDevice *s) static int usb_host_open(USBHostDevice *s, libusb_device *dev, int hostfd) { USBDevice *udev =3D USB_DEVICE(s); + int libusb_speed; int bus_num =3D 0; int addr =3D 0; int rc; @@ -935,7 +941,36 @@ static int usb_host_open(USBHostDevice *s, libusb_devi= ce *dev, int hostfd) usb_ep_init(udev); usb_host_ep_update(s); =20 - udev->speed =3D speed_map[libusb_get_device_speed(dev)]; + libusb_speed =3D libusb_get_device_speed(dev); +#ifdef CONFIG_LINUX + if (hostfd && libusb_speed =3D=3D 0) { + /* + * Workaround libusb bug: libusb_get_device_speed() does not + * work for libusb_wrap_sys_device() devices in v1.0.23. + * + * Speeds are defined in linux/usb/ch9.h, file not included + * due to name conflicts. + */ + int rc =3D ioctl(hostfd, USBDEVFS_GET_SPEED, NULL); + switch (rc) { + case 1: /* low */ + libusb_speed =3D LIBUSB_SPEED_LOW; + break; + case 2: /* full */ + libusb_speed =3D LIBUSB_SPEED_FULL; + break; + case 3: /* high */ + case 4: /* wireless */ + libusb_speed =3D LIBUSB_SPEED_HIGH; + break; + case 5: /* super */ + case 6: /* super plus */ + libusb_speed =3D LIBUSB_SPEED_SUPER; + break; + } + } +#endif + udev->speed =3D speed_map[libusb_speed]; usb_host_speed_compat(s); =20 if (s->ddesc.iProduct) { --=20 2.27.0 From nobody Fri May 17 21:43:12 2024 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=1598863079; cv=none; d=zohomail.com; s=zohoarc; b=W3LQ9zIEs4vG28snVhVaATCdSCJdnc/sHSBshVAPVrfH1T/KhYCqnLoMXwhdCXjr5kKfRtAAc175RraT5/j3zUqNgbGQQjeIw4gTHlq1v1EPkonlBWnF4yfTMI2GUneEXRg9SsjMgutt2tmzZPjmjYQ0/pWWAm99ghllKCoOHPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598863079; 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=5y2VjtPVE1Av1o0uG6hgmniru7Si3R0syXMBys/8m9U=; b=Uwc7zYmYC+ZothyWl0Shbys0bp6hn35hMTqNtVsf+0IVbKm4Zr+QsmSoAA2YcLXI1YMT91/JYfDXBNs0IsPTUV508lTG6pQ2Nhj0HDRK6xAEKTlPR5iSykXmDATp55pP/3wrH3LAIA1HCH5s+TE1Iga77zPPNxWyy5TrdUbfB/c= 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 1598863079588883.5121907056769; Mon, 31 Aug 2020 01:37:59 -0700 (PDT) Received: from localhost ([::1]:51128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCfKA-0008Mg-9C for importer@patchew.org; Mon, 31 Aug 2020 04:37:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCfFc-0008Ff-FS for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:16 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53150 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kCfFZ-0006ak-Dq for qemu-devel@nongnu.org; Mon, 31 Aug 2020 04:33:16 -0400 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-54-nCjlxet-PwCuxqUnZCjqAA-1; Mon, 31 Aug 2020 04:33:10 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4491B10ABDAB; Mon, 31 Aug 2020 08:33:09 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id C41607BE8B; Mon, 31 Aug 2020 08:33:08 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A0CD331FC8; Mon, 31 Aug 2020 10:33:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598862792; 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=5y2VjtPVE1Av1o0uG6hgmniru7Si3R0syXMBys/8m9U=; b=JfWCtXpi29JPVMCkXkC6QveKBzeawC72FczckDLDeUXKoOvOQQflgx93UpZIHmqYqyN/7S taxgVS39iJemfWisLd7QTy5CHw9teQzjI3QBibOQmk2Fva5Kk9FP9jH0huUdvqohLFNEcD fAKiw9uq/oLLFOcHg8xHqEdpdKmDDr8= X-MC-Unique: nCjlxet-PwCuxqUnZCjqAA-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 18/18] usb: fix setup_len init (CVE-2020-14364) Date: Mon, 31 Aug 2020 10:33:01 +0200 Message-Id: <20200831083301.6357-19-kraxel@redhat.com> In-Reply-To: <20200831083301.6357-1-kraxel@redhat.com> References: <20200831083301.6357-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0.001 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=205.139.110.120; envelope-from=kraxel@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 02:13:08 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Li Qiang , Gonglei , Gerd Hoffmann , Cleber Rosa , Paolo Bonzini 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" Store calculated setup_len in a local variable, verify it, and only write it to the struct (USBDevice->setup_len) in case it passed the sanity checks. This prevents other code (do_token_{in,out} functions specifically) from working with invalid USBDevice->setup_len values and overrunning the USBDevice->setup_buf[] buffer. Fixes: CVE-2020-14364 Signed-off-by: Gerd Hoffmann Tested-by: Gonglei Reviewed-by: Li Qiang Message-id: 20200825053636.29648-1-kraxel@redhat.com --- hw/usb/core.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/usb/core.c b/hw/usb/core.c index 5abd128b6bc5..5234dcc73fea 100644 --- a/hw/usb/core.c +++ b/hw/usb/core.c @@ -129,6 +129,7 @@ void usb_wakeup(USBEndpoint *ep, unsigned int stream) static void do_token_setup(USBDevice *s, USBPacket *p) { int request, value, index; + unsigned int setup_len; =20 if (p->iov.size !=3D 8) { p->status =3D USB_RET_STALL; @@ -138,14 +139,15 @@ static void do_token_setup(USBDevice *s, USBPacket *p) usb_packet_copy(p, s->setup_buf, p->iov.size); s->setup_index =3D 0; p->actual_length =3D 0; - s->setup_len =3D (s->setup_buf[7] << 8) | s->setup_buf[6]; - if (s->setup_len > sizeof(s->data_buf)) { + setup_len =3D (s->setup_buf[7] << 8) | s->setup_buf[6]; + if (setup_len > sizeof(s->data_buf)) { fprintf(stderr, "usb_generic_handle_packet: ctrl buffer too small (%d > %z= u)\n", - s->setup_len, sizeof(s->data_buf)); + setup_len, sizeof(s->data_buf)); p->status =3D USB_RET_STALL; return; } + s->setup_len =3D setup_len; =20 request =3D (s->setup_buf[0] << 8) | s->setup_buf[1]; value =3D (s->setup_buf[3] << 8) | s->setup_buf[2]; @@ -259,26 +261,28 @@ static void do_token_out(USBDevice *s, USBPacket *p) static void do_parameter(USBDevice *s, USBPacket *p) { int i, request, value, index; + unsigned int setup_len; =20 for (i =3D 0; i < 8; i++) { s->setup_buf[i] =3D p->parameter >> (i*8); } =20 s->setup_state =3D SETUP_STATE_PARAM; - s->setup_len =3D (s->setup_buf[7] << 8) | s->setup_buf[6]; s->setup_index =3D 0; =20 request =3D (s->setup_buf[0] << 8) | s->setup_buf[1]; value =3D (s->setup_buf[3] << 8) | s->setup_buf[2]; index =3D (s->setup_buf[5] << 8) | s->setup_buf[4]; =20 - if (s->setup_len > sizeof(s->data_buf)) { + setup_len =3D (s->setup_buf[7] << 8) | s->setup_buf[6]; + if (setup_len > sizeof(s->data_buf)) { fprintf(stderr, "usb_generic_handle_packet: ctrl buffer too small (%d > %z= u)\n", - s->setup_len, sizeof(s->data_buf)); + setup_len, sizeof(s->data_buf)); p->status =3D USB_RET_STALL; return; } + s->setup_len =3D setup_len; =20 if (p->pid =3D=3D USB_TOKEN_OUT) { usb_packet_copy(p, s->data_buf, s->setup_len); --=20 2.27.0