summaryrefslogtreecommitdiff
path: root/drivers/cdrom
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@kernel.org>2024-10-17 15:09:02 -0700
committerJens Axboe <axboe@kernel.dk>2024-10-17 19:47:15 -0600
commitb0bf1afde7c34698cf61422fa8ee60e690dc25c3 (patch)
treedaf137964c811abb93b2a981a03309c6155a824a /drivers/cdrom
parentde7007e9e6fe08dc7b45693d7e8cef41f9499854 (diff)
downloadlwn-b0bf1afde7c34698cf61422fa8ee60e690dc25c3.tar.gz
lwn-b0bf1afde7c34698cf61422fa8ee60e690dc25c3.zip
cdrom: Avoid barrier_nospec() in cdrom_ioctl_media_changed()
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>
Diffstat (limited to 'drivers/cdrom')
-rw-r--r--drivers/cdrom/cdrom.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 9b0f37d4b9d4..6a99a459b80b 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2313,7 +2313,7 @@ static int cdrom_ioctl_media_changed(struct cdrom_device_info *cdi,
return -EINVAL;
/* Prevent arg from speculatively bypassing the length check */
- barrier_nospec();
+ arg = array_index_nospec(arg, cdi->capacity);
info = kmalloc(sizeof(*info), GFP_KERNEL);
if (!info)