]> Git Repo - linux.git/commitdiff
cdrom: Avoid barrier_nospec() in cdrom_ioctl_media_changed()
authorJosh Poimboeuf <[email protected]>
Thu, 17 Oct 2024 22:09:02 +0000 (15:09 -0700)
committerJens Axboe <[email protected]>
Fri, 18 Oct 2024 01:47:15 +0000 (19:47 -0600)
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 <[email protected]>
Link: https://lore.kernel.org/r/1d86f4d9d8fba68e5ca64cdeac2451b95a8bf872.1729202937.git.jpoimboe@kernel.org
Signed-off-by: Jens Axboe <[email protected]>
drivers/cdrom/cdrom.c

index 9b0f37d4b9d49ac4843e9c851643574c9152392d..6a99a459b80b2db3aac45ae6db0f8e77369d0238 100644 (file)
@@ -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)
This page took 0.060194 seconds and 4 git commands to generate.