]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
applicom: Fix potential Spectre v1 vulnerabilities
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Wed, 9 Jan 2019 22:05:10 +0000 (16:05 -0600)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 24 Apr 2019 08:09:12 +0000 (10:09 +0200)
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>
CVE-2017-5753

(cherry picked from commit d7ac3c6ef5d8ce14b6381d52eb7adafdd6c8bb3c)
Signed-off-by: Juerg Haefliger <juergh@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/char/applicom.c

index c0a5b1f3a9863b17bf232d7d432a16943a90d252..4ccc39e00ced33fa1942be81fe6f87f7658adbab 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/wait.h>
 #include <linux/init.h>
 #include <linux/fs.h>
+#include <linux/nospec.h>
 
 #include <asm/io.h>
 #include <linux/uaccess.h>
@@ -386,7 +387,11 @@ static ssize_t ac_write(struct file *file, const char __user *buf, size_t count,
        TicCard = st_loc.tic_des_from_pc;       /* tic number to send            */
        IndexCard = NumCard - 1;
 
-       if((NumCard < 1) || (NumCard > MAX_BOARD) || !apbs[IndexCard].RamIO)
+       if (IndexCard >= MAX_BOARD)
+               return -EINVAL;
+       IndexCard = array_index_nospec(IndexCard, MAX_BOARD);
+
+       if (!apbs[IndexCard].RamIO)
                return -EINVAL;
 
 #ifdef DEBUG
@@ -697,6 +702,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        unsigned char IndexCard;
        void __iomem *pmem;
        int ret = 0;
+       static int warncount = 10;
        volatile unsigned char byte_reset_it;
        struct st_ram_io *adgl;
        void __user *argp = (void __user *)arg;
@@ -711,16 +717,12 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        mutex_lock(&ac_mutex);  
        IndexCard = adgl->num_card-1;
         
-       if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
-               static int warncount = 10;
-               if (warncount) {
-                       printk( KERN_WARNING "APPLICOM driver IOCTL, bad board number %d\n",(int)IndexCard+1);
-                       warncount--;
-               }
-               kfree(adgl);
-               mutex_unlock(&ac_mutex);
-               return -EINVAL;
-       }
+       if (cmd != 6 && IndexCard >= MAX_BOARD)
+               goto err;
+       IndexCard = array_index_nospec(IndexCard, MAX_BOARD);
+
+       if (cmd != 6 && !apbs[IndexCard].RamIO)
+               goto err;
 
        switch (cmd) {
                
@@ -838,5 +840,16 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        kfree(adgl);
        mutex_unlock(&ac_mutex);
        return 0;
+
+err:
+       if (warncount) {
+               pr_warn("APPLICOM driver IOCTL, bad board number %d\n",
+                       (int)IndexCard + 1);
+               warncount--;
+       }
+       kfree(adgl);
+       mutex_unlock(&ac_mutex);
+       return -EINVAL;
+
 }