linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wifi: mt76: add a check of vzalloc in mt7615_coredump_work
@ 2023-02-27 11:57 Kang Chen
  2023-02-27 13:33 ` Lorenzo Bianconi
  0 siblings, 1 reply; 7+ messages in thread
From: Kang Chen @ 2023-02-27 11:57 UTC (permalink / raw)
  To: shayne.chen
  Cc: sean.wang, kvalo, nbd, lorenzo, ryder.lee, davem, edumazet, kuba,
	pabeni, matthias.bgg, angelogioacchino.delregno, linux-wireless,
	netdev, linux-kernel, linux-arm-kernel, linux-mediatek,
	Kang Chen

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

Signed-off-by: Kang Chen <void0red@gmail.com>
---
 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
index a95602473..73d84c301 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
@@ -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) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] wifi: mt76: add a check of vzalloc in mt7615_coredump_work
  2023-02-27 11:57 [PATCH] wifi: mt76: add a check of vzalloc in mt7615_coredump_work Kang Chen
@ 2023-02-27 13:33 ` Lorenzo Bianconi
  2023-02-27 13:52   ` [PATCH v2] " void0red
  0 siblings, 1 reply; 7+ messages in thread
From: Lorenzo Bianconi @ 2023-02-27 13:33 UTC (permalink / raw)
  To: Kang Chen
  Cc: shayne.chen, sean.wang, kvalo, nbd, lorenzo, ryder.lee, davem,
	edumazet, kuba, pabeni, matthias.bgg, angelogioacchino.delregno,
	linux-wireless, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

[-- Attachment #1: Type: text/plain, Size: 806 bytes --]

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

can you please add a Fixes tag?

Regards,
Lorenzo

> 
> Signed-off-by: Kang Chen <void0red@gmail.com>
> ---
>  drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
> index a95602473..73d84c301 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
> @@ -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) {
> -- 
> 2.34.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] wifi: mt76: add a check of vzalloc in mt7615_coredump_work
  2023-02-27 13:33 ` Lorenzo Bianconi
@ 2023-02-27 13:52   ` void0red
  2023-02-27 14:06     ` Lorenzo Bianconi
  0 siblings, 1 reply; 7+ messages in thread
From: void0red @ 2023-02-27 13:52 UTC (permalink / raw)
  To: lorenzo.bianconi
  Cc: angelogioacchino.delregno, davem, edumazet, kuba, kvalo,
	linux-arm-kernel, linux-kernel, linux-mediatek, linux-wireless,
	lorenzo, matthias.bgg, nbd, netdev, pabeni, ryder.lee, sean.wang,
	shayne.chen, void0red

From: Kang Chen <void0red@gmail.com>

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

Fixes: d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")
Signed-off-by: Kang Chen <void0red@gmail.com>
---
v2 -> v1: add Fixes tag

 drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
index a95602473..73d84c301 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
@@ -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) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] wifi: mt76: add a check of vzalloc in mt7615_coredump_work
  2023-02-27 13:52   ` [PATCH v2] " void0red
@ 2023-02-27 14:06     ` Lorenzo Bianconi
  2023-02-27 14:28       ` Kang Chen
  2023-02-27 14:48       ` [PATCH v3] wifi: mt76: handle failure " void0red
  0 siblings, 2 replies; 7+ messages in thread
From: Lorenzo Bianconi @ 2023-02-27 14:06 UTC (permalink / raw)
  To: void0red
  Cc: angelogioacchino.delregno, davem, edumazet, kuba, kvalo,
	linux-arm-kernel, linux-kernel, linux-mediatek, linux-wireless,
	lorenzo, matthias.bgg, nbd, netdev, pabeni, ryder.lee, sean.wang,
	shayne.chen

[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]

> From: Kang Chen <void0red@gmail.com>
> 
> vzalloc may fails, dump might be null and will cause
> illegal address access later.
> 
> Fixes: d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")
> Signed-off-by: Kang Chen <void0red@gmail.com>
> ---
> v2 -> v1: add Fixes tag
> 
>  drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
> index a95602473..73d84c301 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
> @@ -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) {
> -- 
> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] wifi: mt76: add a check of vzalloc in mt7615_coredump_work
  2023-02-27 14:06     ` Lorenzo Bianconi
@ 2023-02-27 14:28       ` Kang Chen
  2023-02-27 14:48       ` [PATCH v3] wifi: mt76: handle failure " void0red
  1 sibling, 0 replies; 7+ messages in thread
From: Kang Chen @ 2023-02-27 14:28 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: angelogioacchino.delregno, davem, edumazet, kuba, kvalo,
	linux-arm-kernel, linux-kernel, linux-mediatek, linux-wireless,
	lorenzo, matthias.bgg, nbd, netdev, pabeni, ryder.lee, sean.wang,
	shayne.chen

Hi, Lorenzo

Thanks for your suggestions.
I totally agree with you.

Best regards,
Kang Chen

On Mon, Feb 27, 2023 at 10:07 PM Lorenzo Bianconi
<lorenzo.bianconi@redhat.com> wrote:
>
> > From: Kang Chen <void0red@gmail.com>
> >
> > vzalloc may fails, dump might be null and will cause
> > illegal address access later.
> >
> > Fixes: d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")
> > Signed-off-by: Kang Chen <void0red@gmail.com>
> > ---
> > v2 -> v1: add Fixes tag
> >
> >  drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
> > index a95602473..73d84c301 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
> > @@ -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) {
> > --
> > 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3] wifi: mt76: handle failure of vzalloc in mt7615_coredump_work
  2023-02-27 14:06     ` Lorenzo Bianconi
  2023-02-27 14:28       ` Kang Chen
@ 2023-02-27 14:48       ` void0red
  2023-03-06 11:00         ` Simon Horman
  1 sibling, 1 reply; 7+ messages in thread
From: void0red @ 2023-02-27 14:48 UTC (permalink / raw)
  To: lorenzo.bianconi
  Cc: angelogioacchino.delregno, davem, edumazet, kuba, kvalo,
	linux-arm-kernel, linux-kernel, linux-mediatek, linux-wireless,
	lorenzo, matthias.bgg, nbd, netdev, pabeni, ryder.lee, sean.wang,
	shayne.chen, void0red

From: Kang Chen <void0red@gmail.com>

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

Link: https://lore.kernel.org/all/Y%2Fy5Asxw3T3m4jCw@lore-desk
Fixes: d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")
Signed-off-by: Kang Chen <void0red@gmail.com>
---
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(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
index a95602473..796768011 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c
@@ -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);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] wifi: mt76: handle failure of vzalloc in mt7615_coredump_work
  2023-02-27 14:48       ` [PATCH v3] wifi: mt76: handle failure " void0red
@ 2023-03-06 11:00         ` Simon Horman
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2023-03-06 11:00 UTC (permalink / raw)
  To: void0red
  Cc: lorenzo.bianconi, angelogioacchino.delregno, davem, edumazet,
	kuba, kvalo, linux-arm-kernel, linux-kernel, linux-mediatek,
	linux-wireless, lorenzo, matthias.bgg, nbd, netdev, pabeni,
	ryder.lee, sean.wang, shayne.chen

On Mon, Feb 27, 2023 at 10:48:23PM +0800, void0red wrote:
> From: Kang Chen <void0red@gmail.com>
> 
> vzalloc may fails, dump might be null and will cause
> illegal address access later.
> 
> Link: https://lore.kernel.org/all/Y%2Fy5Asxw3T3m4jCw@lore-desk
> Fixes: d2bf7959d9c0 ("mt76: mt7663: introduce coredump support")
> Signed-off-by: Kang Chen <void0red@gmail.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-06 11:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27 11:57 [PATCH] wifi: mt76: add a check of vzalloc in mt7615_coredump_work Kang Chen
2023-02-27 13:33 ` Lorenzo Bianconi
2023-02-27 13:52   ` [PATCH v2] " void0red
2023-02-27 14:06     ` Lorenzo Bianconi
2023-02-27 14:28       ` Kang Chen
2023-02-27 14:48       ` [PATCH v3] wifi: mt76: handle failure " void0red
2023-03-06 11:00         ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).