* [PATCH] libahci: Fix possible Spectre-v1 pmp indexing in ahci_led_store()
@ 2018-06-08 10:26 John Garry
2018-06-18 18:04 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: John Garry @ 2018-06-08 10:26 UTC (permalink / raw)
To: tj; +Cc: linux-ide, linux-kernel, dan.carpenter, John Garry
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>
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
--
1.9.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] libahci: Fix possible Spectre-v1 pmp indexing in ahci_led_store()
2018-06-08 10:26 [PATCH] libahci: Fix possible Spectre-v1 pmp indexing in ahci_led_store() John Garry
@ 2018-06-18 18:04 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2018-06-18 18:04 UTC (permalink / raw)
To: John Garry; +Cc: linux-ide, linux-kernel, dan.carpenter
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-06-18 18:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-08 10:26 [PATCH] libahci: Fix possible Spectre-v1 pmp indexing in ahci_led_store() John Garry
2018-06-18 18:04 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®