Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 8270cb1

Browse files
JordyZomeraxboe
authored andcommitted
cdrom: Fix spectre-v1 gadget
This patch fixes a spectre-v1 gadget in cdrom. The gadget could be triggered by speculatively bypassing the cdi->capacity check. Signed-off-by: Jordy Zomer <[email protected]> Link: https://lore.kernel.org/all/[email protected] Reviewed-by: Phillip Potter <[email protected]> Link: https://lore.kernel.org/all/ZI1+1OG9Ut1MqsUC@equinox Signed-off-by: Phillip Potter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 017fb83 commit 8270cb1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/cdrom/cdrom.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
#include <linux/errno.h>
265265
#include <linux/kernel.h>
266266
#include <linux/mm.h>
267+
#include <linux/nospec.h>
267268
#include <linux/slab.h>
268269
#include <linux/cdrom.h>
269270
#include <linux/sysctl.h>
@@ -2311,6 +2312,9 @@ static int cdrom_ioctl_media_changed(struct cdrom_device_info *cdi,
23112312
if (arg >= cdi->capacity)
23122313
return -EINVAL;
23132314

2315+
/* Prevent arg from speculatively bypassing the length check */
2316+
barrier_nospec();
2317+
23142318
info = kmalloc(sizeof(*info), GFP_KERNEL);
23152319
if (!info)
23162320
return -ENOMEM;

0 commit comments

Comments
 (0)