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 65BCAC2EA; Tue, 25 Aug 2026 13:43:00 +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=1787665381; cv=none; b=k2NeWznakTNJ/H3u0kTHCTGPQjUPv9W6fLbYtVFmZwihyD8wF2+N0NnDlf0Re52FMlzsqZP4iHzs195e2DUMFqi8kpUFeQtcuVQkXvHDvTOJKFKqVYR1fBR7vNwdmUJlprTJxQDmxi4bIS7mZrTUl604vWAYnMtO3OYCXFyZGvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787665381; c=relaxed/simple; bh=nsEwtzHTQqafTUYDBTudqRc7s7JCe7Jv08d4hmxqJmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QAg8dtNm9aQW27VgbYRN5lSGqiIuaXraNE8WYxEnEyPfjix07Q40zGGjX6rxFXQbOLDqXdGmxmrkyF7xAKp59/rYxPTy/05+LTvazZNWtFbkKoX+ojCeAU5Hz17VvQ3+M/yzFM8dlido9/yPnKf6qpoJiBwgLUoJVkGnr0bQXpo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=g+/nOMmf; 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="g+/nOMmf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B68701F000E9; Tue, 25 Aug 2026 13:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787665380; bh=scXjfGFckextn6u0nslHerMceNoZi6JAEUl5O11vzrU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=g+/nOMmfAT8K0u1/LEUEJwy+IFRmp00Rm8Ugn8IVyNFciiZ+Dcx6dhs6H1d6jhZUQ 0Ww+wR4G4zitqnk5+hpuhIIjBHRg8ictfUBigVohPDIk19F1y4yMp6OtWhAPhid16v phL52myhw+GWiLrjbwmGn01Zqd+6Zo/haA/4XVnQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ibrahim Hashimov , Silvan Jegen , Jiri Kosina Subject: [PATCH 6.18 80/94] HID: nintendo: fix out-of-bounds read in joycon_ctlr_read_handler() Date: Tue, 25 Aug 2026 15:26:16 +0200 Message-ID: <20260825132544.997245966@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260825132541.887883084@linuxfoundation.org> References: <20260825132541.887883084@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 27b376b945c0aac46fcdfcc950b14a85b874b557 upstream. joycon_ctlr_read_handler() casts an incoming HID input report to struct joycon_input_report and parses it, guarding the cast only with a 12-byte length check: if (size >= 12) /* make sure it contains the input report */ joycon_parse_report(ctlr, (struct joycon_input_report *)data); struct joycon_input_report is 49 bytes: a 13-byte header followed by a union whose IMU arm is 36 bytes. For an IMU report joycon_parse_report() -> joycon_parse_imu_report() walks that union (struct offsets 13..48), so a report of exactly 12 bytes with data[0] == JC_INPUT_IMU_DATA passes the guard yet is read up to 37 bytes past its declared length. The over-read bytes are decoded into accelerometer/gyroscope values and forwarded to userspace through the "(IMU)" input device, leaking driver-internal memory. data[0] and size are fully controlled by a malicious or spoofed Joy-Con/Pro Controller. Receive buffers are sized to the maximum report length, so this is an over-read within the allocation rather than a slab OOB, but the decoded bytes still reach userspace. The sibling subcmd path in joycon_ctlr_handle_event() already bounds the same cast correctly: if (size < sizeof(struct joycon_input_report) || data[0] != JC_INPUT_SUBCMD_REPLY) break; Use the same sizeof(struct joycon_input_report) bound here. Fixes: 2af16c1f846b ("HID: nintendo: add nintendo switch controller driver") Cc: stable@vger.kernel.org Signed-off-by: Ibrahim Hashimov Assisted-by: AuditCode-AI:2026.07 Reviewed-by: Silvan Jegen Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-nintendo.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/hid/hid-nintendo.c +++ b/drivers/hid/hid-nintendo.c @@ -2559,7 +2559,12 @@ static int joycon_ctlr_read_handler(stru { if (data[0] == JC_INPUT_SUBCMD_REPLY || data[0] == JC_INPUT_IMU_DATA || data[0] == JC_INPUT_MCU_DATA) { - if (size >= 12) /* make sure it contains the input report */ + /* + * The whole struct is cast and parsed below, including the + * IMU/subcmd union, not just the 12-byte partial header this + * used to check for. + */ + if (size >= sizeof(struct joycon_input_report)) joycon_parse_report(ctlr, (struct joycon_input_report *)data); }