Commit 946d077a authored by Sergey Matyukevich's avatar Sergey Matyukevich Committed by Kalle Valo

qtnfmac: fix potential Spectre vulnerabilities

Fix potential Spectre vulnerabilities and other warnings
reported by smatch:

drivers/net/wireless/quantenna/qtnfmac/core.c:49 qtnf_core_get_mac() warn: potential spectre issue 'bus->mac' [r] (local cap)
drivers/net/wireless/quantenna/qtnfmac/core.c:51 qtnf_core_get_mac() warn: possible spectre second half.  'mac'
drivers/net/wireless/quantenna/qtnfmac/event.c:671 qtnf_event_parse() warn: potential spectre issue 'mac->iflist' [r] (local cap)
drivers/net/wireless/quantenna/qtnfmac/pcie/pearl_pcie.c:912 qtnf_pcie_skb_send() warn: variable dereferenced before check 'skb' (see line 881)
Signed-off-by: default avatarSergey Matyukevich <sergey.matyukevich.os@quantenna.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 501c3be1
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
#include <linux/nospec.h>
#include "core.h" #include "core.h"
#include "bus.h" #include "bus.h"
...@@ -41,11 +42,12 @@ struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid) ...@@ -41,11 +42,12 @@ struct qtnf_wmac *qtnf_core_get_mac(const struct qtnf_bus *bus, u8 macid)
{ {
struct qtnf_wmac *mac = NULL; struct qtnf_wmac *mac = NULL;
if (unlikely(macid >= QTNF_MAX_MAC)) { if (macid >= QTNF_MAX_MAC) {
pr_err("invalid MAC index %u\n", macid); pr_err("invalid MAC index %u\n", macid);
return NULL; return NULL;
} }
macid = array_index_nospec(macid, QTNF_MAX_MAC);
mac = bus->mac[macid]; mac = bus->mac[macid];
if (unlikely(!mac)) { if (unlikely(!mac)) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/nospec.h>
#include "cfg80211.h" #include "cfg80211.h"
#include "core.h" #include "core.h"
...@@ -632,18 +633,20 @@ static int qtnf_event_parse(struct qtnf_wmac *mac, ...@@ -632,18 +633,20 @@ static int qtnf_event_parse(struct qtnf_wmac *mac,
int ret = -1; int ret = -1;
u16 event_id; u16 event_id;
u16 event_len; u16 event_len;
u8 vifid;
event = (const struct qlink_event *)event_skb->data; event = (const struct qlink_event *)event_skb->data;
event_id = le16_to_cpu(event->event_id); event_id = le16_to_cpu(event->event_id);
event_len = le16_to_cpu(event->mhdr.len); event_len = le16_to_cpu(event->mhdr.len);
if (likely(event->vifid < QTNF_MAX_INTF)) { if (event->vifid >= QTNF_MAX_INTF) {
vif = &mac->iflist[event->vifid];
} else {
pr_err("invalid vif(%u)\n", event->vifid); pr_err("invalid vif(%u)\n", event->vifid);
return -EINVAL; return -EINVAL;
} }
vifid = array_index_nospec(event->vifid, QTNF_MAX_INTF);
vif = &mac->iflist[vifid];
switch (event_id) { switch (event_id) {
case QLINK_EVENT_STA_ASSOCIATED: case QLINK_EVENT_STA_ASSOCIATED:
ret = qtnf_event_handle_sta_assoc(mac, vif, (const void *)event, ret = qtnf_event_handle_sta_assoc(mac, vif, (const void *)event,
......
...@@ -593,7 +593,7 @@ static int qtnf_pcie_skb_send(struct qtnf_bus *bus, struct sk_buff *skb) ...@@ -593,7 +593,7 @@ static int qtnf_pcie_skb_send(struct qtnf_bus *bus, struct sk_buff *skb)
priv->tx_bd_w_index = i; priv->tx_bd_w_index = i;
tx_done: tx_done:
if (ret && skb) { if (ret) {
pr_err_ratelimited("drop skb\n"); pr_err_ratelimited("drop skb\n");
if (skb->dev) if (skb->dev)
skb->dev->stats.tx_dropped++; skb->dev->stats.tx_dropped++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment