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 86BFD421225; Mon, 17 Aug 2026 13:45:12 +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=1786974317; cv=none; b=DW9S+6IMRXmsLB4eemK1QtSkh8wfRPB4P86yxTR3BKJQ8z+lYXdiyAywURZQgS+kdQLzwBfDD/pokvX9CDtcNUGd6jRUWjBveiKp3Ub5qVpSoQga5/j7eCsGhdhDQjcRHraM1G16tte4gJpEnGXTqlPdz2I1+/PI6Rx4ew9QFwk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786974317; c=relaxed/simple; bh=vc45S9/Xay1PGIuFANt895fGnh2SS43D1fepHNpv0R4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mQvwTkBMw1VHtvuNjIyuVDbSuQj8Lmekq/o9GKYGbE0D8dcdiLfC6vPA+NysyJ/ml8xVBx9i4LSeMR8quFCap0ZhK0aAgOEkeb5vp49YKrir+MDxXadgtUwuILooDX76F9SitCWDq0tD0TrXMaQP57aYf5Rd6L0yvUot6Z5ZhlY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=F5NEyY4R; 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="F5NEyY4R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C95461F00A3A; Mon, 17 Aug 2026 13:45:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786974312; bh=omLpcom0nAD4qLZ/HeQ/+UVy6saIpClA/DFez6zPM8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F5NEyY4R7Z9AL2G4q8bL9gTuGigzuGKH+czKYdZv/qfvUMoG+7cGMnNlebqfXfl+3 g5aMrLPR52HaLCq4j17JpPqsIVCwLdEZO4dZCzBzEq3OhlrbpERIYbCNfjWTmVGE/8 r3eTOuQVWkBGnDROCa7B3x4OIhBu/koRbQ1847LY= 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 7.1 125/271] Input: evdev - sanitize event type index when fetching event masks Date: Mon, 17 Aug 2026 15:30:50 +0200 Message-ID: <20260817132542.005066761@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132536.752504388@linuxfoundation.org> References: <20260817132536.752504388@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 7.1-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 */