Skip to contentSkip to conversation

wifi: mt76: add a check of vzalloc in mt7615_coredump_work

PATCH Superseded Kang Chen 3 participants 7 messages Feb 27, 2023 – Mar 6, 2023

Subsystems (4)
lore
Share & tools
lore

Kang Chen

author
#0 lore raw

PATCH 1/1 wifi: mt76: add a check of vzalloc in mt7615_coredump_work

vzalloc may fails, dump might be null and will cause illegal address access later.

---
 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +3 -0
index a95602473..73d84c301 100644
@@ -2367,6 +2367,9 @@ void mt7615_coredump_work(struct work_struct *work)
 	}
 
 	dump = vzalloc(MT76_CONNAC_COREDUMP_SZ);
+	if (!dump)
+		return;
+
 	data = dump;
 
 	while (true) {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 2 lines

vzalloc may fails, dump might be null and will cause illegal address access later.

can you please add a Fixes tag?

Regards,
Lorenzo

Quoted 23 lines
---
 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +3 -0
index a95602473..73d84c301 100644
@@ -2367,6 +2367,9 @@ void mt7615_coredump_work(struct work_struct *work)
 	}
 
 	dump = vzalloc(MT76_CONNAC_COREDUMP_SZ);
+	if (!dump)
+		return;
+
 	data = dump;
 
 	while (true) {
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 1/1 wifi: mt76: add a check of vzalloc in mt7615_coredump_work

From: Kang Chen <[email protected]>

vzalloc may fails, dump might be null and will cause illegal address access later.

Fixes d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")

---
v2 -> v1: add Fixes tag

 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +3 -0
index a95602473..73d84c301 100644
@@ -2367,6 +2367,9 @@ void mt7615_coredump_work(struct work_struct *work)
 	}
 
 	dump = vzalloc(MT76_CONNAC_COREDUMP_SZ);
+	if (!dump)
+		return;
+
 	data = dump;
 
 	while (true) {
Signature · 1 line
2.34.1
#3 lore raw
Quoted 30 lines

From: Kang Chen <[email protected]>

vzalloc may fails, dump might be null and will cause illegal address access later.

Fixes d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")

---
v2 -> v1: add Fixes tag

 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +3 -0
index a95602473..73d84c301 100644
@@ -2367,6 +2367,9 @@ void mt7615_coredump_work(struct work_struct *work)
 	}
 
 	dump = vzalloc(MT76_CONNAC_COREDUMP_SZ);
+	if (!dump)
+		return;
+
 	data = dump;
 
 	while (true) {
Signature · 1 line
2.34.1

revieweing the code I guess the right approach would be the one used in mt7921_coredump_work():
- free pending skbs
- not run dev_coredumpv()

What do you think?

Regards,
Lorenzo

author
#4 lore raw

Hi, Lorenzo

Thanks for your suggestions.
I totally agree with you.

Best regards,
Kang Chen

Quoted 41 lines · Lorenzo Bianconi
Quoted 29 lines

From: Kang Chen <[email protected]>

vzalloc may fails, dump might be null and will cause illegal address access later.

Fixes d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")

---
v2 -> v1: add Fixes tag

 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +3 -1
index a95602473..73d84c301 100644
@@ -2367,6 +2367,9 @@ void mt7615_coredump_work(struct work_struct *work)
      }
 
      dump = vzalloc(MT76_CONNAC_COREDUMP_SZ);
+     if (!dump)
+             return;
+
      data = dump;
 
      while (true) {
--
Quoted 2 lines

2.34.1

revieweing the code I guess the right approach would be the one used in mt7921_coredump_work():
- free pending skbs
- not run dev_coredumpv()

What do you think?

Regards,
Lorenzo

author
#5 lore raw

PATCH v3 1/1 wifi: mt76: handle failure of vzalloc in mt7615_coredump_work

In reply to Lorenzo Bianconi

From: Kang Chen <[email protected]>

vzalloc may fails, dump might be null and will cause illegal address access later.

Fixes d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")

---
v3 -> v2: fix bugs
v2 -> v1: add Fixes tag

 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +5 -3
index a95602473..796768011 100644
@@ -2380,7 +2380,7 @@ void mt7615_coredump_work(struct work_struct *work)
 			break;
 
 		skb_pull(skb, sizeof(struct mt7615_mcu_rxd));
-		if (data + skb->len - dump > MT76_CONNAC_COREDUMP_SZ) {
+		if (!dump || data + skb->len - dump > MT76_CONNAC_COREDUMP_SZ) {
 			dev_kfree_skb(skb);
 			continue;
 		}
@@ -2390,6 +2390,8 @@ void mt7615_coredump_work(struct work_struct *work)
 
 		dev_kfree_skb(skb);
 	}
-	dev_coredumpv(dev->mt76.dev, dump, MT76_CONNAC_COREDUMP_SZ,
-		      GFP_KERNEL);
+
+	if (dump)
+		dev_coredumpv(dev->mt76.dev, dump, MT76_CONNAC_COREDUMP_SZ,
+			      GFP_KERNEL);
 }
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#6 lore raw

Re: [PATCH v3] wifi: mt76: handle failure of vzalloc in mt7615_coredump_work

Quoted 8 lines · On Mon, Feb 27, 2023 at 10:48:23PM +0800, void0red wrote:

From: Kang Chen <[email protected]>

vzalloc may fails, dump might be null and will cause illegal address access later.

Fixes d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")