Skip to content

Commit 0adb8a1

Browse files
GustavoARSilvagregkh
authored andcommitted
applicom: Fix potential Spectre v1 vulnerabilities
commit d7ac3c6 upstream. IndexCard is indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: drivers/char/applicom.c:418 ac_write() warn: potential spectre issue 'apbs' [r] drivers/char/applicom.c:728 ac_ioctl() warn: potential spectre issue 'apbs' [r] (local cap) Fix this by sanitizing IndexCard before using it to index apbs. Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://lore.kernel.org/lkml/20180423164740.GY17484@dhcp22.suse.cz/ Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5d58d89 commit 0adb8a1

1 file changed

Lines changed: 24 additions & 11 deletions

File tree

drivers/char/applicom.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/wait.h>
3333
#include <linux/init.h>
3434
#include <linux/fs.h>
35+
#include <linux/nospec.h>
3536

3637
#include <asm/io.h>
3738
#include <asm/uaccess.h>
@@ -386,7 +387,11 @@ static ssize_t ac_write(struct file *file, const char __user *buf, size_t count,
386387
TicCard = st_loc.tic_des_from_pc; /* tic number to send */
387388
IndexCard = NumCard - 1;
388389

389-
if((NumCard < 1) || (NumCard > MAX_BOARD) || !apbs[IndexCard].RamIO)
390+
if (IndexCard >= MAX_BOARD)
391+
return -EINVAL;
392+
IndexCard = array_index_nospec(IndexCard, MAX_BOARD);
393+
394+
if (!apbs[IndexCard].RamIO)
390395
return -EINVAL;
391396

392397
#ifdef DEBUG
@@ -697,6 +702,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
697702
unsigned char IndexCard;
698703
void __iomem *pmem;
699704
int ret = 0;
705+
static int warncount = 10;
700706
volatile unsigned char byte_reset_it;
701707
struct st_ram_io *adgl;
702708
void __user *argp = (void __user *)arg;
@@ -711,16 +717,12 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
711717
mutex_lock(&ac_mutex);
712718
IndexCard = adgl->num_card-1;
713719

714-
if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
715-
static int warncount = 10;
716-
if (warncount) {
717-
printk( KERN_WARNING "APPLICOM driver IOCTL, bad board number %d\n",(int)IndexCard+1);
718-
warncount--;
719-
}
720-
kfree(adgl);
721-
mutex_unlock(&ac_mutex);
722-
return -EINVAL;
723-
}
720+
if (cmd != 6 && IndexCard >= MAX_BOARD)
721+
goto err;
722+
IndexCard = array_index_nospec(IndexCard, MAX_BOARD);
723+
724+
if (cmd != 6 && !apbs[IndexCard].RamIO)
725+
goto err;
724726

725727
switch (cmd) {
726728

@@ -838,5 +840,16 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
838840
kfree(adgl);
839841
mutex_unlock(&ac_mutex);
840842
return 0;
843+
844+
err:
845+
if (warncount) {
846+
pr_warn("APPLICOM driver IOCTL, bad board number %d\n",
847+
(int)IndexCard + 1);
848+
warncount--;
849+
}
850+
kfree(adgl);
851+
mutex_unlock(&ac_mutex);
852+
return -EINVAL;
853+
841854
}
842855

0 commit comments

Comments
 (0)