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 87C3F43D4FA; Mon, 17 Aug 2026 13:56:16 +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=1786974979; cv=none; b=Jd6MTTEgW0GZ3s35POVEpEoLqb37mc0yGKVeYNtvwqVPR0h1r+6JNnPFmPf+fXPmhn3pzJMGlloAANtkmx8Jq/CAWFrB5L3+WIXfGKbwYH7C2ms+TihMMMJz8yRP2gI/aVh8QEXMfH5OoYROfaNaOc91jLC2sG3x2otuhhoLzWg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786974979; c=relaxed/simple; bh=PQ3LFN2npeFTu03ZFvoc7QMXo+8zoomV+xWnmwJsHwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YUBd7EgDHuAidQnfhHtStRqPHgRW0uTSsyiCkdV9ziEm3l8BA4OvyhnkX7XAvjSv1BDr9hwR7o6BOrcvhiRmSpuewjb2wnXFaiFeZhTkDc5GSoHe+LvZrrqVB/aZFRYUo+DfbeM02x2Tc68+4ey9mmR3ZWCXByHraVzouLGiL1s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NSFeGMPO; 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="NSFeGMPO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3AFD1F00A3D; Mon, 17 Aug 2026 13:56:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786974975; bh=VajI/QUjJiT0dbnLq8yYKSl2wA4M2xzGBOLPz4L3xSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NSFeGMPORbnS/U0kQipmm/lA+3qjzYUlAglu5L8dXyYCcG1xQkk3h/Zj5208h8rL+ iBkBF5P1vHXf0QbO0MyWaOut+t+1+ufUtjYilDJBF95zmtTuWkeigGhuEp0jDm9fBI SD5rrB5GkuwzUwXF2FSGxSRyVuDOo+Zh/8/kSkE0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Wagenaar, C.C.J. (Chris)" , Dmitry Torokhov Subject: [PATCH 6.18 112/250] Input: evdev - sanitize event type index when fetching event masks Date: Mon, 17 Aug 2026 15:31:13 +0200 Message-ID: <20260817132541.145547548@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132536.466235697@linuxfoundation.org> References: <20260817132536.466235697@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: Dmitry Torokhov commit 3abd29c61d2ef37c4102cf755b18be53bb9dbea6 upstream. The user-supplied event type index passed to EVIOCGMASK / EVIOCSMASK ioctls is used to index the static counts array in evdev_get_mask_cnt() and client evmasks array in evdev_get_mask(). While the event type is architecturally bounded by EV_CNT, speculative execution may mispredict bounds checks and perform out-of-bounds loads. Sanitize the event type index in evdev_get_mask_cnt() branchlessly using array_index_mask_nospec(). This clamps the index to 0 for safe array access and forces the returned count to 0 speculatively when the index is out of bounds. We do not need additional array_index_nospec() calls in evdev_get_mask() because evdev_get_mask_cnt() speculatively forces the count (and resulting xfer_size) to 0 for out-of-bounds types, preventing any speculative memory access to client evmasks array. Reported-by: "Wagenaar, C.C.J. (Chris)" Cc: stable@vger.kernel.org Assisted-by: Antigravity:gemini-3.6-flash Acked-by: Greg Kroah-Hartman Link: https://patch.msgid.link/anFCAfvxwXB5eJF1@google.com Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/input/evdev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include "input-compat.h" @@ -67,8 +68,10 @@ static size_t evdev_get_mask_cnt(unsigne [EV_SND] = SND_CNT, [EV_FF] = FF_CNT, }; + unsigned long mask = array_index_mask_nospec(type, EV_CNT); - return (type < EV_CNT) ? counts[type] : 0; + /* Returns 0 for out-of-bounds types, including speculatively */ + return counts[type & mask] & mask; } /* requires the buffer lock to be held */