Skip to contentSkip to conversation

mt76: fix memcpy to potential null pointer on failed allocation

PATCH In review Colin King 3 participants 4 messages Dec 14, 2017 – Jan 8, 2018

Subsystems (5)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 mt76: fix memcpy to potential null pointer on failed allocation

From: Colin Ian King <[email protected]>

Currently if the allocation of skb fails and returns NULL then the call to skb_put will cause a null pointer dereference. Fix this by checking for a null skb and returning NULL. Note that calls to function mt76x2_mcu_msg_alloc don't directly check the null return but instead pass the NULL pointer to mt76x2_mcu_msg_send which checks for the NULL and returns ENOMEM in this case.

Detected by CoverityScan, CID#1462624 ("Dereference null return value")

Fixes 7bc04215a66b ("mt76: add driver code for MT76x2e")
---
 drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c +2 -0
index d45737ee1412..15820b11f9db 100644
@@ -45,6 +45,8 @@ static struct sk_buff *mt76x2_mcu_msg_alloc(const void *data, int len)
 	struct sk_buff *skb;
 
 	skb = alloc_skb(len, GFP_KERNEL);
+	if (!skb)
+		return NULL;
 	memcpy(skb_put(skb, len), data, len);
 
 	return skb;
Signature · 1 line
2.14.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Colin King

From: Colin Ian King <[email protected]>

Currently if the allocation of skb fails and returns NULL then the call to skb_put will cause a null pointer dereference. Fix this by checking for a null skb and returning NULL. Note that calls to function mt76x2_mcu_msg_alloc don't directly check the null return but instead pass the NULL pointer to mt76x2_mcu_msg_send which checks for the NULL and returns ENOMEM in this case.

Quoted 4 lines

Detected by CoverityScan, CID#1462624 ("Dereference null return value")

Fixes 7bc04215a66b ("mt76: add driver code for MT76x2e")
#2 lore raw
In reply to Colin King
Quoted 9 lines · Colin Ian King

From: Colin Ian King <[email protected]>

Currently if the allocation of skb fails and returns NULL then the call to skb_put will cause a null pointer dereference. Fix this by checking for a null skb and returning NULL. Note that calls to function mt76x2_mcu_msg_alloc don't directly check the null return but instead pass the NULL pointer to mt76x2_mcu_msg_send which checks for the NULL and returns ENOMEM in this case.

Quoted 5 lines

Detected by CoverityScan, CID#1462624 ("Dereference null return value")

Fixes 7bc04215a66b ("mt76: add driver code for MT76x2e")

Patch applied to wireless-drivers-next.git, thanks.

364bea50dbea mt76: fix memcpy to potential null pointer on failed allocation

Signature · 3 lines
https://patchwork.kernel.org/patch/10111747/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw
In reply to Colin King
Quoted 9 lines · Colin Ian King

From: Colin Ian King <[email protected]>

Currently if the allocation of skb fails and returns NULL then the call to skb_put will cause a null pointer dereference. Fix this by checking for a null skb and returning NULL. Note that calls to function mt76x2_mcu_msg_alloc don't directly check the null return but instead pass the NULL pointer to mt76x2_mcu_msg_send which checks for the NULL and returns ENOMEM in this case.

Quoted 5 lines

Detected by CoverityScan, CID#1462624 ("Dereference null return value")

Fixes 7bc04215a66b ("mt76: add driver code for MT76x2e")

Patch applied to wireless-drivers-next.git, thanks.

364bea50dbea mt76: fix memcpy to potential null pointer on failed allocation

Signature · 3 lines
https://patchwork.kernel.org/patch/10111747/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches