diff mbox series

libahci: Fix possible Spectre-v1 pmp indexing in ahci_led_store()

Message ID 1528453593-225313-1-git-send-email-john.garry@huawei.com
State Accepted
Commit fae2a63737e5973f1426bc139935a0f42e232844
Headers show
Series libahci: Fix possible Spectre-v1 pmp indexing in ahci_led_store() | expand

Commit Message

John Garry June 8, 2018, 10:26 a.m. UTC
Currently smatch warns of possible Spectre-V1 issue in ahci_led_store():
drivers/ata/libahci.c:1150 ahci_led_store() warn: potential spectre issue 'pp->em_priv' (local cap)

Userspace controls @pmp from following callchain:
em_message->store()
->ata_scsi_em_message_store()
-->ap->ops->em_store()
--->ahci_led_store()

After the mask+shift @pmp is effectively an 8b value, which is used to
index into an array of length 8, so sanitize the array index.

Signed-off-by: John Garry <john.garry@huawei.com>


-- 
1.9.1

Comments

Tejun Heo June 18, 2018, 6:04 p.m. UTC | #1
On Fri, Jun 08, 2018 at 06:26:33PM +0800, John Garry wrote:
> Currently smatch warns of possible Spectre-V1 issue in ahci_led_store():

> drivers/ata/libahci.c:1150 ahci_led_store() warn: potential spectre issue 'pp->em_priv' (local cap)

> 

> Userspace controls @pmp from following callchain:

> em_message->store()

> ->ata_scsi_em_message_store()

> -->ap->ops->em_store()

> --->ahci_led_store()

> 

> After the mask+shift @pmp is effectively an 8b value, which is used to

> index into an array of length 8, so sanitize the array index.

> 

> Signed-off-by: John Garry <john.garry@huawei.com>


Applied to libata/for-4.18-fixes.

Thanks.

-- 
tejun
diff mbox series

Patch

diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 7adcf3c..4ce5bb4 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -35,6 +35,7 @@ 
 #include <linux/kernel.h>
 #include <linux/gfp.h>
 #include <linux/module.h>
+#include <linux/nospec.h>
 #include <linux/blkdev.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
@@ -1142,10 +1143,12 @@  static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
 
 	/* get the slot number from the message */
 	pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
-	if (pmp < EM_MAX_SLOTS)
+	if (pmp < EM_MAX_SLOTS) {
+		pmp = array_index_nospec(pmp, EM_MAX_SLOTS);
 		emp = &pp->em_priv[pmp];
-	else
+	} else {
 		return -EINVAL;
+	}
 
 	/* mask off the activity bits if we are in sw_activity
 	 * mode, user should turn off sw_activity before setting