From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 26E743D954F for ; Tue, 4 Aug 2026 01:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785807715; cv=none; b=lwfrvOYNtQUB+qnlMv9hBm4bcQf4B2lMjUgDA/SOREq6yOlLk7gdLJZuluaiDRbdjJslOtZN9dWGdn93oiP27z/osDoiphOnUezQlOqFFo8AIa8B2N4qHM9Gpz47cwKtrzNEuXWfPSxvel6hBnlBYBGGZp69pxlj8h5/MhPmCNY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785807715; c=relaxed/simple; bh=ro+Wx+hreEXUc1+FbWqBmslCj+PhsGQeaz9tmn3EjCs=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=PXuZClZEBGY6VTmxgH0vb/jEQxrA1sDGhmv7jYr+bALJf/gZzMm50MuBEsSTjbXEtYCgjfvx4U1isZJ+EKrkiLrzzPCM1zWCP6UGqgAQG7cN6m/T0ztu5X3ziMHv5A3RRecaxPqlaLVvkHuIIzHnrfEAKcNlppVW46njE7F9VX8= 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=EFxgri2o; arc=none smtp.client-ip=209.85.210.175 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="EFxgri2o" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-84eb992a881so3293807b3a.2 for ; Mon, 03 Aug 2026 18:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785807713; x=1786412513; darn=vger.kernel.org; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CNPgSNpSCLs8Fm5mEm2tT9XyZGyB1J0tABlRmKt+IFM=; b=EFxgri2o4sXW+RL44Ls0BKKaFporJwe6REDeBBcLPTxnZH8uFmYj5rlp0RlfUZ/0ts Nn4dxceJ8hzlv4pxOQ9w45Oa4vlJ134qTcUgopHDVw4tufuBN1kdjI8ZXMKXQPRRdc71 qyG42aqCWEdd6q+btz9eBBH23inZc0VvAO36x1Ig+Zy2X2LMqnn57Z8A90g2uAulNPPi GiLp7+Fz0PlPNuhCoKgSGGTm7tyuYGGLLt4pRQYiexNavf9YXtl4QOftiyGQoSDOP7Qg mytfnriVsSngwmA2TRfZ643uaPVA3XNCDngs+Ifsj1ZcQmvKQNx2bP2ptZ+ceqxbqoFF ZK4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785807713; x=1786412513; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CNPgSNpSCLs8Fm5mEm2tT9XyZGyB1J0tABlRmKt+IFM=; b=YPEnbPb9jkUU/iLkxvazXqnW/R2KGNsJ4CtEJXQN34GUNdIl56ZwStmEG7MjwecVm5 C5LKHC//+ICSVObZFGEpoUnt0nNCQVQ+CKAz9uW8/RdMsp3ssDCZ5JTcrhFrNTZGUeVe 68CnhY1YI8RuZr4su8LVLHqrzJdll4jP7QrbSy5mG2ou1vQQP5WQ3xMLLlZdA20fkgSS YuTDDut6wORkQMYvkw4/hNoGTzKomchZTv7myk4BKv9Hl769r/LDrqqpMhrAF+79FuZG hnIaj40wXufC9LgmmEkdqFbNwAXLK6BZBWImx0UvdsaPx8yK66eetnPKnCQL7oq6nKM9 emPQ== X-Forwarded-Encrypted: i=1; AHgh+Rrdu+GqiRbGDqUBXVsW5oXHwAQv68nKqHE2z3y5HvYWwa6jNQMsooDc4jrXydcL0hW/TL2hN37pnssiVec=@vger.kernel.org X-Gm-Message-State: AOJu0YwO9pJ3D2jq5dKqlN3PD+zVOJ8q5HZaav0YFOI2DRnCgrt9Q732 5ZHba67EXH7ftyW99fetvRKspdPEE0t1zSOhD9lagCn7NcQZ9jlKqBLQ X-Gm-Gg: AR+sD13W8uBfB/Lykde6icZZtx/HWw3iwvsjkKNCtdIqzsFJNQYmdcdmznfS2bbZTE5 m0mDqiEbaiE6AyL2Her38UklUkZ1e+81sxNSwIY0OUnug1KXl4ae22y86kiSb6o2eW/OelB/8Eh DuapEYIk8Sfgsgcs+hPEGw52ur2qpPZeTTcGpxLZPPeQn3j938UkmTlLj0pQCDp+8Ns06CV+ouK eMde45KPywMfne3Nmgc69+qvlh5LCj3eDpapxrV3revB0tQdEr1cFtvb+i9SK9InuwjWWWR7aMo bOoW9qagu7dHsO6iHv4HGs9URfUXbb9rigUEUVCDv4X6Mv6BKjWaiXy1KQpAcecszbiQqrJlli8 ysOrCHx+rpZzED8LpJe3LIzscOzuqRWBOuW7f1HPwYFEfF2Tv+iOS7EXpzWUAM/ljeJHCoWpYCt 1gPda7tMSRyufeI5XIaWs9cVY6ALMpLiTERhiapWJfpE+1MaMzbLiPEvy4yvUYw74uzHuxdcJ9j wd0jcEThcLTgBfCdTE+dbwmmp/Dag== X-Received: by 2002:a05:6a21:111:b0:3c8:e313:8d2a with SMTP id adf61e73a8af0-3c92a9c70dfmr11518181637.43.1785807713318; Mon, 03 Aug 2026 18:41:53 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab1334cfsm39924803c88.1.2026.08.03.18.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 18:41:52 -0700 (PDT) Date: Mon, 3 Aug 2026 18:41:49 -0700 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Kees Cook , linux-kernel@vger.kernel.org, "Wagenaar, C.C.J. (Chris)" , Greg KH Subject: [PATCH] Input: evdev - sanitize event type index when fetching event masks Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Signed-off-by: Dmitry Torokhov --- drivers/input/evdev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 5764c98b4f1f..796ac7ac2b8c 100644 --- 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(unsigned int type) [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 */ -- 2.55.0.629.g250fe7f194-goog -- Dmitry