From nobody Sat Jul 25 05:29:19 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 5E7CB3A75BD for ; Fri, 17 Jul 2026 09:16:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784279793; cv=none; b=UMerEWEgSb1o0CZHoGnmiUXa8DEiBpPNHbKPGq5PSx2mgOhHF9V8dXcQeEPhtQX3dE9JQVuSJ5Dc3HjxvmyHs1P3iwv5Bb2TQRRqzXfe+t/lQ+C6zzrncPzTGOthjxvI++kOIMv9VM9u7gKR3Mg7DwWrHdVbf7zRgCTnWEjH8Tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784279793; c=relaxed/simple; bh=HDcBmvwtIazuzQyAN/7w+ZhNN3Jy4GpM7mlse59y/K0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C7hbzuUWMP4wS/IXYDntbHfiMHUHsWvnHNmiWGU72xa9rhKIjn9QFuFb/hybuc2OV+DnlBs+5WlnY5W19qdcEevo+AnufQR0dqRUKdICaMBNIN+49FLruKUfNCZr2HkZuQITooWwmajW7HjUrYZ9aQ66jw5Fmb14rRpO4fe+cyQ= 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=A5Th67Lf; arc=none smtp.client-ip=209.85.214.177 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="A5Th67Lf" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2caed617615so86024085ad.3 for ; Fri, 17 Jul 2026 02:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784279790; x=1784884590; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pCpmT4pbrNtqEfg5rTMCgVzYOvryZpyfEkqoROTNER4=; b=A5Th67Lfzs7sBwv+vvXDwqYbhObRwxH0S0LBdqt9W1/7HonNwuWrKvJFth05Y6EDu2 Nec2IDJNrt+7+7VMNLSfQciz3tuhlIY+15G84WamUJVhOSDG7QDhlKD2AOC6pJ15dzYm FStVX0fTltg4PLA0i+Ld4wlm0peZp9QD4cWYCYVF7A+WCAjszvrSW59WB6GnlGc9tH25 URUfkZHyc2zLa9pwrjHc0JfZeV9Curv9S/lAwxvAdixvySV3AA203SWszItB7sz/s+SG RZiAU6PgGVmBeHh7ixsvytqVv19SBWXvo1xRdbu5U2qr7B9KTIExarPdO13obSLy6MDx 8J2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784279790; x=1784884590; h=content-transfer-encoding:mime-version:references:in-reply-to :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=pCpmT4pbrNtqEfg5rTMCgVzYOvryZpyfEkqoROTNER4=; b=hTK9VmLpqPt9+87T2cTUh+0grKPMc9CmUwDzY7x7YV9zysgPMq5p2LUNofNSQP9KB0 WolUt6udPMcijiKtj/qaJlXWnnGrUqeAfyN0M+qpSlAt0zXpElQg/WtMyzqEvBExpjn+ /ZtxEN1YIi5KGLakq/Jyb5OoEyk8/l08ltFPr/Ydyb8fIbVTUwhiLWZGrL/MXkrXrV6a T3y1RY06MCdCGchoFHd37d2cwAVtooEWtGPz2E83TJl/q+UZy5Z9JLyMM3G410cFRkjq KOekGz1mTFaproLyetBjkMUbz4eShChx+jmjrCLd9N4l260jyh9XY+LdLo4JXzBDyYGN 4xYA== X-Forwarded-Encrypted: i=1; AHgh+Rqbkw4rvYz5sul0qnXlRsTiKA65BFlmiw8Gidy72y0FOXq5/6XbE1YOMSDOdGbIHkm2ffW6SgPDTNDMHQg=@vger.kernel.org X-Gm-Message-State: AOJu0YwHhOlmijMWlG1ksb7ND3VoUYgBz95NnEVdQbcBa8f6mxsk0GMQ hEL05RVwvzSiHtrarwKwxzuAg0Qu6zD9fWKxTIx57kE1De3bTENrufD3 X-Gm-Gg: AfdE7cmglosRpWSt8bw7MJsZtx1GMtkyccaSg+rs0L/rFqgAJ5C+4wGOCrWJKh5AVLA 4UXmgtYFn6EsR4jJewKd/Db6jAIgD5RR7Ptb8J2jqHQlx1iRRONkw1ixuOFjjiUcEDmlaFJcTMN d+u/A/JjxNNR/ouKsxmchEzwrHiqv1XwVE+d4m1FFe6buJd7Vf94H8bbaBrCty2AgnBtw/VbhRV 9xgxy3hZSiEMHKtupEiObYUwdGsZb+2nTFABl0IOCBwd2oKvGFdbT/wYm5DegkhBAulDAJpygQZ pyd3yBLhBaPXMqDT+OkbtlmwZtX+aS6ZJKjxnNFRdzBMVsX9SqimK7e3BVYKgJwzzkqeNNs89wA Z8cQvjNThi+UQ9HH2aRTE/qzlw4s9EUNlZxO/UklyWZ697YU6PPbukHn81FrXc8laOwTYs25KFS g5HiVq5LZENH2X5/FXgrx+56YUCUmOSFjlRryxxAmPvK6/76B08AQnZAnW2R8I8arngLQ= X-Received: by 2002:a17:902:f70d:b0:2c6:9f6a:9f6f with SMTP id d9443c01a7336-2cf349b8d41mr18806065ad.28.1784279790317; Fri, 17 Jul 2026 02:16:30 -0700 (PDT) Received: from nugod-NUC15CRHU5.tail9f095a.ts.net ([218.237.104.87]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf34490361sm7407205ad.17.2026.07.17.02.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 02:16:29 -0700 (PDT) From: HyeongJun An To: Even Xu , Xinpeng Sun , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, HyeongJun An Subject: [PATCH v2] HID: intel-thc-hid: intel-quickspi: validate report size before copy Date: Fri, 17 Jul 2026 18:16:22 +0900 Message-ID: <20260717091622.1744196-1-sammiee5311@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260628133717.941389-1-sammiee5311@gmail.com> References: <20260628133717.941389-1-sammiee5311@gmail.com> 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" write_cmd_to_txdma() builds an output report in qsdev->report_buf, a heap buffer allocated in quickspi_alloc_report_buf() to the device-descriptor derived max_report_len (a few hundred bytes for a touch controller). It copies the caller-supplied report into that buffer: memcpy(write_buf->content, report_buf, report_buf_len); The HID core caps a report at HID_MAX_BUFFER_SIZE (16384) by default, and quickspi_hid_ll_driver does not set max_buffer_size, so the length reaches the driver unbounded. A hidraw SET_REPORT/SET_FEATURE ioctl carrying a report larger than max_report_len therefore overflows report_buf with attacker-controlled length and content. Record the report_buf allocation size and reject reports that do not fit before copying, matching the equivalent guard in the intel-quicki2c sibling (quicki2c_init_write_buf()) and the hid-goodix-spi fix. write_cmd_to_txdma() writes the output report header ahead of the content in the same buffer, so size the allocation to cover the header as well. That keeps the added bound from rejecting a maximum-sized report. Fixes: 9d8d51735a3a ("HID: intel-thc-hid: intel-quickspi: Add HIDSPI protoc= ol implementation") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-8 Signed-off-by: HyeongJun An Reviewed-by: Even Xu --- v2: Size report_buf to cover the output report header as well, so the added bound cannot reject a valid maximum-sized report (raised by the Sashiko AI review of v1). No other change. v1: https://lore.kernel.org/all/20260628133717.941389-1-sammiee5311@gmail.c= om/ drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c | 9 ++++++++- drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h | 1 + .../hid/intel-thc-hid/intel-quickspi/quickspi-protocol.c | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c b/driv= ers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c index 4ae2e1718b30..da5ecfcd0fbf 100644 --- a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +++ b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c @@ -555,7 +555,14 @@ static int quickspi_alloc_report_buf(struct quickspi_d= evice *qsdev) max_report_len =3D max(le16_to_cpu(qsdev->dev_desc.max_output_len), le16_to_cpu(qsdev->dev_desc.max_input_len)); =20 - qsdev->report_buf =3D devm_kzalloc(qsdev->dev, max_report_len, GFP_KERNEL= ); + /* + * write_cmd_to_txdma() writes the output report header ahead of the + * content in this buffer, so it has to hold both. + */ + qsdev->report_buf_size =3D HIDSPI_OUTPUT_REPORT_SIZE(max_report_len); + + qsdev->report_buf =3D devm_kzalloc(qsdev->dev, qsdev->report_buf_size, + GFP_KERNEL); if (!qsdev->report_buf) return -ENOMEM; =20 diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h b/driv= ers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h index bf5e18f5a5f4..0ed964bfe3dd 100644 --- a/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h +++ b/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h @@ -157,6 +157,7 @@ struct quickspi_device { u8 *report_descriptor; u8 *input_buf; u8 *report_buf; + u32 report_buf_size; u32 report_len; =20 wait_queue_head_t reset_ack_wq; diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-protocol.c b= /drivers/hid/intel-thc-hid/intel-quickspi/quickspi-protocol.c index cb19057f1191..db6054843e77 100644 --- a/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-protocol.c +++ b/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-protocol.c @@ -30,6 +30,9 @@ static int write_cmd_to_txdma(struct quickspi_device *qsd= ev, =20 write_buf =3D (struct output_report *)qsdev->report_buf; =20 + if (HIDSPI_OUTPUT_REPORT_SIZE(report_buf_len) > qsdev->report_buf_size) + return -EINVAL; + write_buf->output_hdr.report_type =3D report_type; write_buf->output_hdr.content_len =3D cpu_to_le16(report_buf_len); write_buf->output_hdr.content_id =3D report_id; --=20 2.43.0