From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17C5D416878; Fri, 4 Sep 2026 05:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788500775; cv=none; b=QL6/2/UI6e9d9Ovzp7dKvMFekNO4tM1ukrJf0UHkLcgyhZDx29LaOA7ISEVRmJ5VIFDyoB9WjZstdABw4WVER/+2N1+VQZR4XGwC1uuDZ+43vD4fDjdh+UfXmFiNCwzdOACZreaq/ZfkoFMIU0NFOhTnuw2/M+rLNMa1D0SQ/NM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788500775; c=relaxed/simple; bh=NSqdxuBeEhrluUq3gQV42IJZnAGQyNDpeTLBOuZ0K8E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qZkRkepPDP+ppmaLNypMJ9agu728ebD/QevFstJFEYjncgaWFotiBb54JOaw4p8w+Yyo7EozHcIwhPs2RCL3D0mcmsazzxJ8pQgduTRFqtpu7+Spc6ji1AjMQ86m5cwBXKPcZ1cUrX1NRlDCtoyjcYtb0pk098taQdg6QVZCyMs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=m0sEO2qg; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="m0sEO2qg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 309801F00A3D; Fri, 4 Sep 2026 05:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788500773; bh=hBC0Vp+yTY8i7Cy/6PoGsEpGlSGVGMp0pYCBDDLyHJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=m0sEO2qgTrUDasX3HXvcnkX4PEIl2azYtqYRZiMxT5WMZPktUZKqRD1QQVUZcYWpu hc+hSTvxssJDRN65/MB/z8vSpWAIQWahh31CUrHVqeGEnw/NXgokeUTxW9ntzQUW3y +AGDCAb+DTFw0spJzRpYdQiC0p94MCfUYkNbiOqc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ibrahim Hashimov , Jiri Kosina Subject: [PATCH 6.18 176/552] HID: picolcd: clamp eeprom debugfs read to bytes actually received Date: Fri, 4 Sep 2026 06:55:33 +0200 Message-ID: <20260904045753.012337840@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045747.813364717@linuxfoundation.org> References: <20260904045747.813364717@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ibrahim Hashimov commit e9c667395ac1f8024f623250b32bae4c7af9caa0 upstream. picolcd_debug_eeprom_read() trusts resp->raw_data[2] -- a length byte supplied by the device in its REPORT_EE_DATA reply -- clamped only to the caller's read() count: ret = resp->raw_data[2]; if (ret > s) ret = s; if (copy_to_user(u, resp->raw_data+3, ret)) It never checks resp->raw_size, the number of bytes picolcd_raw_event() actually copied into the 64-byte raw_data[] of the kmalloc'd struct picolcd_pending. A device (or a spoofed picoLCD) returning a length byte of 0xff, read with a count >= 255, makes copy_to_user() read past raw_data[] into adjacent slab memory and return it to userspace through the debugfs "eeprom" file: BUG: KASAN: slab-out-of-bounds in _copy_to_user Read of size 255 ... picolcd_debug_eeprom_read+0x214/0x2f0 [hid_picolcd] The debug-dump path in the same file already validates the device length byte against the received size before trusting it; this read does not. The file is created S_IRUSR (root-only) and a crafted device is needed, so it is neither unprivileged- nor remotely-triggerable. Clamp the copy length to resp->raw_size - 3 (the payload actually received, minus the 3-byte header), floored at 0 for short replies. Fixes: 9bbf2b98ba11 ("HID: add experimental access to PicoLCD device's EEPROM and FLASH") Cc: stable@vger.kernel.org Signed-off-by: Ibrahim Hashimov Assisted-by: AuditCode-AI:2026.07 Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-picolcd_debugfs.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/hid/hid-picolcd_debugfs.c +++ b/drivers/hid/hid-picolcd_debugfs.c @@ -98,6 +98,15 @@ static ssize_t picolcd_debug_eeprom_read ret = resp->raw_data[2]; if (ret > s) ret = s; + /* + * raw_data[2] is a device-supplied length; also clamp it to + * what picolcd_raw_event() actually stored (raw_size), or a + * hostile device overruns the raw_data[] buffer. + */ + if (ret > resp->raw_size - 3) + ret = resp->raw_size - 3; + if (ret < 0) + ret = 0; if (copy_to_user(u, resp->raw_data+3, ret)) ret = -EFAULT; else