From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-input@vger.kernel.org
Subject: Re: [PATCH] Input: evdev - sanitize event type index when fetching event masks
Date: Mon, 3 Aug 2026 21:18:24 -0700 [thread overview]
Message-ID: <anFmI06p-i0vusxe@google.com> (raw)
In-Reply-To: <20260804015414.E04CA1F000E9@smtp.kernel.org>
On Tue, Aug 04, 2026 at 01:54:13AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Incomplete Spectre v1 mitigation due to misunderstanding of speculative execution on branches.
> --
>
> --- Patch [1]: [PATCH] Input: evdev - sanitize event type index when fetching event masks ---
> commit e9eb78cd8dbba1d32ef31f1eec9a5c00e54b5aad
> Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>
> Input: evdev - sanitize event type index when fetching event masks
>
> This commit uses array_index_mask_nospec() in evdev_get_mask_cnt() to clamp
> out-of-bounds event types to 0. It asserts that this is sufficient to prevent
> speculative out-of-bounds memory accesses in functions like evdev_get_mask()
> because the returned count is speculatively forced to 0.
>
> > 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.
>
> [Severity: High]
> This is a pre-existing issue, but does relying on the returned count being 0
> fully prevent speculative out-of-bounds accesses in callers like
> evdev_get_mask() and evdev_set_mask()?
>
> When CPU branch predictors mispredict the conditions checking the count, they
> do not wait for the condition to evaluate.
>
> For example, if the if (cnt > 0) branch in evdev_get_mask() is mispredicted:
>
> drivers/input/evdev.c:evdev_get_mask() {
> ...
> cnt = evdev_get_mask_cnt(type);
> ...
> if (cnt > 0) {
> mask = client->evmasks[type];
> ...
> }
>
> The branch predictor will speculatively execute the block using the
> original, unclamped type variable, performing an out-of-bounds read on
> client->evmasks[type]. The retrieved pointer is then accessed by
> bits_to_user().
No it will not because xfer_size will be 0 and bits_to_user
(copy_to_user) will not dereference the pointer at all.
>
> A similar pattern exists in evdev_set_mask(), where a mispredicted if (!cnt)
> branch can lead to using the unclamped type:
>
> drivers/input/evdev.c:evdev_set_mask() {
> ...
> cnt = evdev_get_mask_cnt(type);
> if (!cnt)
> return 0;
> ...
> oldmask = client->evmasks[type];
> ...
> bitmap_free(oldmask);
> }
>
> The speculative read of oldmask is followed by a dereference in bitmap_free(),
> which creates an exploitable side-channel gadget.
kfree() can not serve as a side-channel gadget. Additionally there are
speculation barriers in copy_from_user() and when taking the spinlock.
>
> This pattern also appears in __evdev_is_filtered(). A mispredicted bounds
> check can lead to speculative out-of-bounds accesses for test_bit(type, mask)
> or mask = client->evmasks[type].
This is internal kernel function and is not user-controlled.
>
> Do we still need to explicitly use array_index_nospec(type, EV_CNT) inside
> these caller functions to prevent the unclamped type from being used during
> speculative execution?
So no.
Thanks.
--
Dmitry
next prev parent reply other threads:[~2026-08-04 4:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 1:41 [PATCH] Input: evdev - sanitize event type index when fetching event masks Dmitry Torokhov
2026-08-04 1:54 ` sashiko-bot
2026-08-04 4:18 ` Dmitry Torokhov [this message]
2026-08-04 10:02 ` Greg KH
2026-08-05 15:54 ` Chris Wagenaar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=anFmI06p-i0vusxe@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox