From nobody Mon Sep 28 06:34:54 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F07072FFF8D for ; Tue, 25 Aug 2026 10:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787653871; cv=none; b=kjyOEyoppYWjIZyl6VJwQ1KFdNYNUyXtRaOhGosSQxNsXjhVeveIU0ziA8Yh56XSRtYi1K9OJsmqE0ajmUvUxm0bLrfe5Vc6ID2SpPgnIlsqCSNNGGhXKzq4q4PqslUN45ZwlFCERCZy5oz9gwvcnczq25YRBJCnxy0fZAqjAPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787653871; c=relaxed/simple; bh=/43KOMS60rSwqm+0h6nol2XjGbfCzZZdtTRs+CP2OHU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EARTzTwoYVu3/tS/8PdX3CvjAcpw4wCwwmePth+h6wBo3GB6PFByzrg/Sr1V4quL9FlThpNtqyiQWC5VJS87ulgsGe4k3Uh37GnzOwNeViolGHBn59W5FClqPXEYqYpiPvmsQyJ1UvakOTLCuiVutgv0x77BFzR7HmF9DSYkMyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lzMVeBY7; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lzMVeBY7" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-38f620399a0so3962925a91.2 for ; Tue, 25 Aug 2026 03:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787653869; x=1788258669; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=zHxpkdrH+ub77zWOCs0hPYLKcUBXeDslDiRjI02XCqo=; b=lzMVeBY7ckKUw+lV86tD3L71zaIJ/Z57diaQeYEgxLGIRKI5D+c5mjrME41KzKlzd7 Qs/bHGeKdWMP7B+Y4AFAx59kKmOz/z+BXqQbmJ/+3++5pgnhT4vB0HNt91/tinmsIMZW 1tSZghtynl0YRTkue9AKua82u15EW1PhoVRb7t4dMLn+N4Lc6g1RPkb/6/0XTreM0LqN nDfG3KkYVlIP6Wz6oFevQrC/hoh3jTLmEjZWkOgsPvY5JDM/3TpKyYcniwpU3H8v3mPs jFkem+AKvf52JxOaUSLOFLs37sPOqcbKoCrFzCaCDPy1rcO5r7vSlmEcAOPoZYtgOKri m85g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787653869; x=1788258669; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zHxpkdrH+ub77zWOCs0hPYLKcUBXeDslDiRjI02XCqo=; b=ZLkTK/XALNAf8WOpZfC7HYB/vuVJX9VuXqkO8KjMmjJjLH943a9JArNNV5NHC61uxZ FOK1TB7lKKFPBQmsKWnYwAstnhvk5g2yusaE5zSB3R2eNBfM1vM2dAH35IeptxNw/R9Q +So8iiQQonnQNG9xFiqjzIjeTrAAwHNoDoKfpisiuzH8cD+SLxXkfTgFONwvaPcjUTBq y4YU68wfF15Hd0DsvDzAcVdPQidy2FaLJSFtyHCillGawRK1W7RZXNspQOdrUhS/geLN fNRSIuYvH4/XJa3it6xfGLOgtbmSOCz0IwAOzfZ08VDQKqrzGIUNpl0ch8dW47ClRdSp XJNg== X-Forwarded-Encrypted: i=1; AHgh+Rq+H5nzWbyveomXMwtt0RtYLQtpMNrLf9i384JMd3R82lSbufOOyRnegb3DfEcF8j7W76g98OoTWIhUiiY=@vger.kernel.org X-Gm-Message-State: AFuF++kEyEph4UwclfB9ZMotmWKUXN5CNZTa3eYt/kszgyo2a4nBap7G jCKBGnl7H4BMDTYd0+jcmwrzaWi7+wvtIa7VHnPSJSco7AjNTTNqtwdE X-Gm-Gg: AR+sD11TQdRL480gczXUPkDw2J3IeJO2QiUbkXGpaSqaPWmF5AJjmi4R3/7p61gNK6e lo1NFJzC1tPV1Pk5n/DKF4SMd03c31KRYXqHPGZeRXF+PDIOrOGV908pZvl97hexEoD7MPO3q+y 1nCbCue9l6dzFkC5sLBfH/FkgyeNF45l6T+ScP6IQwtfqaCStHImyvfVC27SEVXbxPJoAHwahMS z94+WcZ0/b1biEDYiBZlvI58l5DFQG9xbU3lLcHdPx7xnwrr/gUXc7OjV5F4WX93jXvaZwTG8UB JsGZOJGa68yyqh1WugSCzn6IvSwUHqxN7zmZI8gCx0cR8t0RarNEv8e6/SVtaI/YVGwJb6NI76Y 9Yyyn+9XlsGOLtV+ToRX5EWjgWV40+3EOq+0RTP+0mvIunDURJZspRftNoDjp8ajOUFwmLxjWan H47GTQMSOl6m5iHZymrzHkDZk2dDBiHp6RY8YsCbk0rXN0xkZ+p8AS2CcCEBDIViz0jtbhGgkV1 VxI0ihBUn4K64kPO1g1hkRKrQE4WTK4R0M0wLTWo2jEq5RIBzGBxEd7Yzx6fJ+WF+zoEsxpfQ9n ly4gnpeAMt0KdtG/0ZM6DU7G X-Received: by 2002:a17:90b:1b04:b0:38d:dfd1:7c1 with SMTP id 98e67ed59e1d1-395c33406e0mr56047468a91.2.1787653869085; Tue, 25 Aug 2026 03:31:09 -0700 (PDT) Received: from LAPTOP-UUUVNN1I.localdomain (bb119-74-6-224.singnet.com.sg. [119.74.6.224]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39645b17ebasm3358068a91.4.2026.08.25.03.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 03:31:08 -0700 (PDT) From: Wei Jie Law <98lawweijie@gmail.com> To: Ping Cheng , Jason Gerecke , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2] HID: wacom: fix OOB read in wacom_wac_pen_serial_enforce() Date: Tue, 25 Aug 2026 18:31:03 +0800 Message-ID: <20260825103104.12090-1-98lawweijie@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" wacom_wac_pen_serial_enforce() iterates over a field's usages (up to field->maxusage) but indexes the report bits by j * report_size: for (i =3D 0; i < report->maxfield; i++) { for (j =3D 0; j < report->field[i]->maxusage; j++) { ... value =3D hid_field_extract(hdev, raw_data + 1, offset + j * size, size); In hid_add_field() the usage array is sized max(usage_index, report_count), so field->maxusage can be far larger than report_count when a descriptor lists more usages than its Report Count. A field declaring Usage Minimum 0 / Usage Maximum 0x2ffe with Report Count 1 gives maxusage =3D=3D 12288 while the field's bit region is only 8 bits wide. The extract at j =3D=3D 12287 then reads bit offset 12287 * 8, i.e. byte 12287 of raw_data + 1, roughly 12 KB past a 2-byte received report. __extract() performs no bounds check. The value read that way is stored into wacom_wac->serial[0] and can be emitted to userspace as an MSC_SERIAL event by wacom_wac_pen_report(), so this is an information disclosure and not just an out-of-bounds read. A malicious device only has to claim vendor id 0x056a for hid_scan_report() to place it in HID_GROUP_WACOM and have this driver bound to it, and a single crafted input report is enough to trigger the read. Clamp the inner loop to the field's actual report region with min(maxusage, report_count), so usages that have no report data behind them are no longer extracted. Verified on v6.12.104, whose wacom_sys.c is identical to mainline here, with a UHID reproducer and with an emulated USB device (raw-gadget): a hardware watchpoint on wacom_wac->serial[0] fires with an out-of-bounds heap byte while a 2-byte report is being processed, and no longer fires once the loop is clamped. Fixes: 83417206427b ("HID: wacom: Queue events with missing type/serial dat= a for later processing") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Assisted-by: GLM:glm-5.3 Signed-off-by: Wei Jie Law <98lawweijie@gmail.com> --- Changes in v2: - No code change: the diff is identical to v1. Adds the Assisted-by tags required by Documentation/process/coding-assistants.rst. The reproducer is available on request. Compile-tested on bd5f485f3f02, x86_64 defconfig + CONFIG_HID_WACOM=3Dy. v1: https://lore.kernel.org/linux-input/20260822120926.153849-1-98lawweijie= @gmail.com/ drivers/hid/wacom_sys.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 0eafa483b7f7..1ea8763b68a8 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -113,8 +113,10 @@ static int wacom_wac_pen_serial_enforce(struct hid_dev= ice *hdev, =20 /* Queue events which have invalid tool type or serial number */ for (i =3D 0; i < report->maxfield; i++) { - for (j =3D 0; j < report->field[i]->maxusage; j++) { - struct hid_field *field =3D report->field[i]; + struct hid_field *field =3D report->field[i]; + unsigned int count =3D min(field->maxusage, field->report_count); + + for (j =3D 0; j < count; j++) { struct hid_usage *usage =3D &field->usage[j]; unsigned int equivalent_usage =3D wacom_equivalent_usage(usage->hid); unsigned int offset; --=20 2.43.0