From nobody Sat Apr 20 12:37:38 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1576344408; cv=none; d=zohomail.com; s=zohoarc; b=TTUF/ePypiuwBM7+v606v/XgMqnXp0AbMn7pP4K8RZBck2sUEXOFW4btioQgqGwKrMkUQG2R5MznhOhv9mFH51mIllW+11ozeiaGMya1ZHuNffe49lw0A8/A3c59fAltiGt6lJgh8VrW0nTDkYt/eEbIhU/6HV7w0Xl/8GCpVP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576344408; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:To; bh=3xpAVOb+KL2WyUn3cM+eXpfMgDiUH7/tvGN9O3j6Vi8=; b=I1Q9+9FEAtMNxF6goGxZkqi0l2IJwZXJwYdokPxXe5Sfz4hhKOs8cdWcUZERlRiTfRw/6m+ydpaUNa4kbZL6wQm0hbUMZFVMtKAo9z0IYd3deO3qMJfh7yrpoh8n4812VbADJFQGKP4AyR07ds+S8+Mllb/RQEsbduGET3H8Yq4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1576344408384666.0694211984344; Sat, 14 Dec 2019 09:26:48 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 305BD205C4; Sat, 14 Dec 2019 17:26:44 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id DA0A2205C6 for ; Sat, 14 Dec 2019 17:26:29 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) for ; Sat, 14 Dec 2019 09:26:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=7JKdWGe4IkYXpzH6EdwTCEhKAagYN8dGXsDbqqpqkOE=; b=XIMY1WNrbJFdlz975OygxIk29lsVTfFChiUEK2HjlXGge6QxHkbTpK4OeqH/fTSAoQ Z9fCdls9KpYErc5c+wBbruATziy7C/A0bcRddf09EvtAbNyqSOg9aJ24VKMLZWH7va3j 7f1IK4sqQIF5xHR0YRKoRzwSC7f3IGd/2zZyAOwMVWLIRi5Rfv1lfQl/6o7eNlm9o/69 JD307IPLkYCVmAANvjvnijXRSBREU5MHFVZWc8srll7pYk9hfwmtoYkFTkPePmQARxHn ek27SeA60z8G50/8NASJ6Yc0NAUIeaWd1AjM0BJk8CkJWHYtOb5MdhFXX5Du/eeqL97p cjAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=7JKdWGe4IkYXpzH6EdwTCEhKAagYN8dGXsDbqqpqkOE=; b=cqBVcwlheTg1nalwS0KWCWqaOJ/lshinKnzT4qgweppRUTt6X4qCIydbkPpz3eDNfK nY4ZZWBXprZq2vhRLrQNw+EwZtgO7DMpfGgfLG9tyvxKXwkB2WeaHMNtjlms8YFfMq+j q+Owxd4DhDLYUxfNmkw59AhzNiCxx6ZIrPJIrlP0VDzIoTrMvKGuJ5g4vFR6ggojU8P9 P/6cymw/B9lPW6+EoEW3naSmr2HiPaaLbizHnLYXj4Db4WUEfEHMYL7zmR2p/Yg7UFmL 7RwjWoMtvDwbO/MWCA4WPWpq+/8Heb+MOYh/H3/L/87IfucvGX2v9qykBpIR1ea9Qnuv XFBg== X-Gm-Message-State: APjAAAUUAJ5YIs1IjEieFdW3AJ9hrO7Tk4gb8V4EfezWEGCVVt44Q0SI iLN3/g8yObxIGSBW6ktTJn1vW0J4sxDFmhU92MZcV1tdwYc= X-Google-Smtp-Source: APXvYqwEAmnALI1yFYGJIgkoCRHjNSashA5zqtyPXCKkqsDw7XekisviNQbm2K1f6e9NqByfKbJL6gAePm/gAqJtLCw= X-Received: by 2002:a92:860a:: with SMTP id g10mr4823145ild.280.1576344388329; Sat, 14 Dec 2019 09:26:28 -0800 (PST) MIME-Version: 1.0 From: Matt DeVillier Date: Sat, 14 Dec 2019 11:26:17 -0600 Message-ID: To: seabios Message-ID-Hash: ORXWC3XONLEUDIEKX65KKGEF3ANCLEOQ X-Message-ID-Hash: ORXWC3XONLEUDIEKX65KKGEF3ANCLEOQ X-MailFrom: matt.devillier@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.3.1 Precedence: list Subject: [SeaBIOS] [PATCH v3] hw/usb-hid: handle devices with illegal max packet size List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++ X-Spam-Level: *** Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) Content-Type: text/plain; charset="utf-8" Some USB keyboards report 9 or 10-byte max packet sizes, instead of the 8-byte max specified by the USB HID spec. Handle this by increasing the size of the keyevent struct to 10 bytes, and using the key array size of the usbkeyinfo struct as loop bounds rather than that of the keyevent struct (since the former will always be smaller, and within spec). Test: built/boot on Google Pixel Slate, observe keyboard functional Signed-off-by: Matt DeVillier --- src/hw/usb-hid.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hw/usb-hid.c b/src/hw/usb-hid.c index fa4d9a2..bce1b5f 100644 --- a/src/hw/usb-hid.c +++ b/src/hw/usb-hid.c @@ -8,6 +8,7 @@ #include "config.h" // CONFIG_* #include "output.h" // dprintf #include "ps2port.h" // ATKBD_CMD_GETID +#include //memset #include "usb.h" // usb_ctrlrequest #include "usb-hid.h" // usb_keyboard_setup #include "util.h" // process_key @@ -59,8 +60,10 @@ usb_kbd_setup(struct usbdevice_s *usbdev // XXX - this enables the first found keyboard (could be random) return -1; - if (epdesc->wMaxPacketSize !=3D 8) + if (epdesc->wMaxPacketSize > 10) { + dprintf(1, "USB keyboard endpoint wMaxPacketSize > 10; aborting\n"= ); return -1; + } // Enable "boot" protocol. int ret =3D set_protocol(usbdev->defpipe, 0); @@ -163,11 +166,15 @@ static u16 ModifierToScanCode[] VAR16 =3D { #define RELEASEBIT 0x80 -// Format of USB keyboard event data +// Format of USB keyboard event data. +// Some keyboards use a 9/10 byte packet size, +// so account for that here to prevent buffer +// overflow. We'll ignore the 9th/10th bytes +// as it's out of spec. struct keyevent { u8 modifiers; u8 reserved; - u8 keys[6]; + u8 keys[8]; }; // Translate data from KeyToScanCode[] to calls to process_key(). @@ -253,7 +260,7 @@ handle_key(struct keyevent *data) break; int j; for (j=3D0;; j++) { - if (j>=3DARRAY_SIZE(data->keys)) { + if (j>=3DARRAY_SIZE(old.keys)) { // Key released. procscankey(key, RELEASEBIT, data->modifiers); if (i+1 >=3D ARRAY_SIZE(old.keys) || !old.keys[i+1]) @@ -274,7 +281,7 @@ handle_key(struct keyevent *data) // Process new keys procmodkey(data->modifiers & ~old.modifiers, 0); old.modifiers =3D data->modifiers; - for (i=3D0; ikeys); i++) { + for (i=3D0; ikeys[i]; if (!key) continue; --=20 2.20.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org