[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 16/17] hw/usb: Add U2F device check to passthru mode
From: |
Gerd Hoffmann |
Subject: |
[PULL 16/17] hw/usb: Add U2F device check to passthru mode |
Date: |
Wed, 19 Aug 2020 07:46:43 +0200 |
From: César Belley <cesar.belley@lse.epita.fr>
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ésar Belley <cesar.belley@lse.epita.fr>
Message-id: 20200812094135.20550-13-cesar.belley@lse.epita.fr
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/usb/u2f-passthru.c | 41 +++++++++++++++++++++++++++++++++++++++++
hw/usb/Makefile.objs | 3 ++-
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/hw/usb/u2f-passthru.c b/hw/usb/u2f-passthru.c
index 106b5abf9ecc..f8771966c747 100644
--- a/hw/usb/u2f-passthru.c
+++ b/hw/usb/u2f-passthru.c
@@ -34,6 +34,12 @@
#include "u2f.h"
+#ifdef CONFIG_LIBUDEV
+#include <libudev.h>
+#endif
+#include <linux/hidraw.h>
+#include <sys/ioctl.h>
+
#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,
}
}
+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[] = {
+ 0x06, 0xd0, 0xf1, /* Usage Page (FIDO) */
+ 0x09, 0x01, /* Usage (FIDO) */
+ };
+
+ /* Get report descriptor size */
+ ret = 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 = rdesc_size;
+ ret = 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)) == 0;
+}
+
static void u2f_passthru_unrealize(U2FKeyState *base)
{
U2FPassthruState *key = PASSTHRU_U2F_KEY(base);
@@ -368,6 +402,13 @@ static void u2f_passthru_realize(U2FKeyState *base, Error
**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 = fd;
u2f_passthru_reset(key);
}
diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs
index 7842a3175f8f..9e7e1f33a51e 100644
--- a/hw/usb/Makefile.objs
+++ b/hw/usb/Makefile.objs
@@ -38,7 +38,8 @@ endif
endif
ifeq ($(CONFIG_USB_U2F),y)
-common-obj-y += u2f.o u2f-passthru.o
+common-obj-y += u2f.o
+common-obj-$(CONFIG_LINUX) += u2f-passthru.o
common-obj-$(CONFIG_U2F) += u2f-emulated.o
u2f-emulated.o-cflags = $(U2F_CFLAGS)
u2f-emulated.o-libs = $(U2F_LIBS)
--
2.18.4
- [PULL 02/17] hw: ehci: destroy sglist in error path, (continued)
- [PULL 02/17] hw: ehci: destroy sglist in error path, Gerd Hoffmann, 2020/08/19
- [PULL 03/17] hw: ehci: check return value of 'usb_packet_map', Gerd Hoffmann, 2020/08/19
- [PULL 01/17] hw: xhci: check return value of 'usb_packet_map', Gerd Hoffmann, 2020/08/19
- [PULL 15/17] scripts: Add u2f-setup-gen script, Gerd Hoffmann, 2020/08/19
- [PULL 14/17] docs/qdev-device-use.txt: Add USB U2F key to the QDEV devices examples, Gerd Hoffmann, 2020/08/19
- [PULL 04/17] ehci: drop pointless warn_report for guest bugs., Gerd Hoffmann, 2020/08/19
- [PULL 05/17] hw/usb: Regroup USB HID protocol values, Gerd Hoffmann, 2020/08/19
- [PULL 17/17] hw/usb: Add U2F device autoscan to passthru mode, Gerd Hoffmann, 2020/08/19
- [PULL 07/17] hw/usb: Add U2F key base class, Gerd Hoffmann, 2020/08/19
- [PULL 06/17] docs: Add USB U2F key device documentation, Gerd Hoffmann, 2020/08/19
- [PULL 16/17] hw/usb: Add U2F device check to passthru mode,
Gerd Hoffmann <=
- [PULL 12/17] configure: Add USB U2F key device, Gerd Hoffmann, 2020/08/19
- [PULL 11/17] hw/usb: Add U2F key build recipe, Gerd Hoffmann, 2020/08/19
- [PULL 10/17] hw/usb: Add U2F key emulated mode, Gerd Hoffmann, 2020/08/19
- [PULL 08/17] hw/usb: Add U2F key base class implementation, Gerd Hoffmann, 2020/08/19
- [PULL 09/17] hw/usb: Add U2F key passthru mode, Gerd Hoffmann, 2020/08/19
- Re: [PULL 00/17] Usb 20200819 patches, Peter Maydell, 2020/08/21