Skip to contentSkip to conversation

net: mwifiex: fix a NULL pointer dereference

PATCH Superseded Kangjie Lu 2 participants 2 messages Mar 11, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 net: mwifiex: fix a NULL pointer dereference

In case dev_alloc_skb fails, the fix returns -ENOMEM to avoid NULL pointer dereference.

---
 drivers/net/wireless/marvell/mwifiex/cmdevt.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/marvell/mwifiex/cmdevt.c +6 -0
index 60db2b969e20..5565f18039ab 100644
@@ -341,6 +341,12 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
 		sleep_cfm_tmp =
 			dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
 				      + MWIFIEX_TYPE_LEN);
+		if (!sleep_cfm_tmp) {
+			mwifiex_dbg(adapter, ERROR, 
+				    "SLEEP_CFM: dev_alloc_skb failed\n");
+			return -ENOMEM;
+		}
+
 		skb_put(sleep_cfm_tmp, sizeof(struct mwifiex_opt_sleep_confirm)
 			+ MWIFIEX_TYPE_LEN);
 		put_unaligned_le32(MWIFIEX_USB_TYPE_CMD, sleep_cfm_tmp->data);
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Kangjie Lu

In case dev_alloc_skb fails, the fix returns -ENOMEM to avoid NULL pointer dereference.

---
 drivers/net/wireless/marvell/mwifiex/cmdevt.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/marvell/mwifiex/cmdevt.c +0 -0
index 60db2b969e20..5565f18039ab 100644

drivers/net/wireless/marvell/mwifiex/cmdevt.c static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter) · line 345

Quoted 5 lines
drivers/net/wireless/marvell/mwifiex/cmdevt.c +2 -0
@@ -341,6 +341,12 @@ static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter)
 		sleep_cfm_tmp =
 			dev_alloc_skb(sizeof(struct mwifiex_opt_sleep_confirm)
 				      + MWIFIEX_TYPE_LEN);
+		if (!sleep_cfm_tmp) {
+			mwifiex_dbg(adapter, ERROR, 

You have trailing whitespace. Please run your patches through scripts/checkpatch.pl.

drivers/net/wireless/marvell/mwifiex/cmdevt.c static int mwifiex_dnld_sleep_confirm_cmd(struct mwifiex_adapter *adapter) · line 347

Quoted 2 lines
drivers/net/wireless/marvell/mwifiex/cmdevt.c +2 -0
+				    "SLEEP_CFM: dev_alloc_skb failed\n");
+			return -ENOMEM;

It's not exactly a problem with your patch, but nobody really checks the return status of this function. I think in most (all?) cases, that's probably OK, because we also implicitly communicate the success/failure of this function by modifying the ->ps_state field (basically, a state machine). So this is probably OK.

Other than the whitespace:

Quoted 8 lines
drivers/net/wireless/marvell/mwifiex/cmdevt.c +2 -0
+		}
+
 		skb_put(sleep_cfm_tmp, sizeof(struct mwifiex_opt_sleep_confirm)
 			+ MWIFIEX_TYPE_LEN);
 		put_unaligned_le32(MWIFIEX_USB_TYPE_CMD, sleep_cfm_tmp->data);
Signature · 1 line
2.17.1