2023-02-27 11:57:30

by void0red

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Kang Chen <[email protected]>
---
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



2023-02-27 13:34:30

by Lorenzo Bianconi

[permalink] [raw]
Subject: Re: [PATCH] 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.

can you please add a Fixes tag?

Regards,
Lorenzo

>
> Signed-off-by: Kang Chen <[email protected]>
> ---
> 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
>


Attachments:
(No filename) (775.00 B)
signature.asc (228.00 B)
Download all attachments

2023-02-27 13:52:53

by void0red

[permalink] [raw]
Subject: [PATCH v2] 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")
Signed-off-by: Kang Chen <[email protected]>
---
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


2023-02-27 14:08:01

by Lorenzo Bianconi

[permalink] [raw]
Subject: Re: [PATCH v2] 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")
> Signed-off-by: Kang Chen <[email protected]>
> ---
> 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


Attachments:
(No filename) (1.02 kB)
signature.asc (228.00 B)
Download all attachments

2023-02-27 14:29:14

by void0red

[permalink] [raw]
Subject: Re: [PATCH v2] wifi: mt76: add a check of vzalloc in mt7615_coredump_work

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
<[email protected]> 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")
> > Signed-off-by: Kang Chen <[email protected]>
> > ---
> > 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

2023-02-27 14:48:48

by void0red

[permalink] [raw]
Subject: [PATCH v3] wifi: mt76: handle failure 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.

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


2023-03-06 11:00:20

by Simon Horman

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

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

Reviewed-by: Simon Horman <[email protected]>