Skip to content

Commit b0bf1af

Browse files
jpoimboeaxboe
authored andcommitted
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: 8270cb1 ("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>
1 parent de7007e commit b0bf1af

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/cdrom/cdrom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ static int cdrom_ioctl_media_changed(struct cdrom_device_info *cdi,
23132313
return -EINVAL;
23142314

23152315
/* Prevent arg from speculatively bypassing the length check */
2316-
barrier_nospec();
2316+
arg = array_index_nospec(arg, cdi->capacity);
23172317

23182318
info = kmalloc(sizeof(*info), GFP_KERNEL);
23192319
if (!info)

0 commit comments

Comments
 (0)