]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
cdrom: Avoid barrier_nospec() in cdrom_ioctl_media_changed()
authorJosh Poimboeuf <jpoimboe@kernel.org>
Thu, 17 Oct 2024 22:09:02 +0000 (15:09 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 1 Nov 2024 01:02:32 +0000 (02:02 +0100)
commitab6dae64f1f597c98dc5bbd12433cc993a1ea3c9
tree55b35d43fd00ea2ab7740d50d69b43cf52cf6699
parent9509ade927c67075bf438714be2fc46884b62904
cdrom: Avoid barrier_nospec() in cdrom_ioctl_media_changed()

[ Upstream commit b0bf1afde7c34698cf61422fa8ee60e690dc25c3 ]

The barrier_nospec() after the array bounds check is overkill and
painfully slow for arches which implement it.

Furthermore, most arches don't implement it, so they remain exposed to
Spectre v1 (which can affect pretty much any CPU with branch
prediction).

Instead, clamp the user pointer to a valid range so it's guaranteed to
be a valid array index even when the bounds check mispredicts.

Fixes: 8270cb10c068 ("cdrom: Fix spectre-v1 gadget")
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://lore.kernel.org/r/1d86f4d9d8fba68e5ca64cdeac2451b95a8bf872.1729202937.git.jpoimboe@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/cdrom/cdrom.c