Skip to contentSkip to conversation

wireless: mwifiex: fix double free

PATCH In review [email protected] 3 participants 3 messages Oct 4, 2020 – Oct 8, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wireless: mwifiex: fix double free

From: Tom Rix <[email protected]>

clang static analysis reports this problem:

sdio.c:2403:3: warning: Attempt to free released memory

        kfree(card->mpa_rx.buf);
        ^~~~~~~~~~~~~~~~~~~~~~~

When mwifiex_init_sdio() fails in its first call to mwifiex_alloc_sdio_mpa_buffer, it falls back to calling it again. If the second alloc of mpa_tx.buf fails, the error handler will try to free the old, previously freed mpa_rx.buf. Reviewing the code, it looks like a second double free would happen with mwifiex_cleanup_sdio().

So set both pointers to NULL when they are freed.

Fixes 5e6e3a92b9a4 ("wireless: mwifiex: initial commit for Marvell mwifiex driver")
---
 drivers/net/wireless/marvell/mwifiex/sdio.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wireless/marvell/mwifiex/sdio.c +2 -0
index 69911c728eb1..bde9e4bbfffe 100644
@@ -2403,6 +2403,8 @@ static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter,
 		kfree(card->mpa_rx.buf);
 		card->mpa_tx.buf_size = 0;
 		card->mpa_rx.buf_size = 0;
+		card->mpa_tx.buf = NULL;
+		card->mpa_rx.buf = NULL;
 	}
 
 	return ret;
Signature · 1 line
2.18.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Sun, Oct 4, 2020 at 6:19 AM <[email protected]> wrote:

From: Tom Rix <[email protected]>

clang static analysis reports this problem:

sdio.c:2403:3: warning: Attempt to free released memory

        kfree(card->mpa_rx.buf);
        ^~~~~~~~~~~~~~~~~~~~~~~

That's some interesting static analysis for a compiler.

Quoted 11 lines

When mwifiex_init_sdio() fails in its first call to mwifiex_alloc_sdio_mpa_buffer, it falls back to calling it again. If the second alloc of mpa_tx.buf fails, the error handler will try to free the old, previously freed mpa_rx.buf. Reviewing the code, it looks like a second double free would happen with mwifiex_cleanup_sdio().

So set both pointers to NULL when they are freed.

Fixes 5e6e3a92b9a4 ("wireless: mwifiex: initial commit for Marvell mwifiex driver")

For whatever it's worth:

#2 lore raw

Re: mwifiex: fix double free

In reply to [email protected]
Quoted 15 lines · [email protected] wrote:

From: Tom Rix <[email protected]>

clang static analysis reports this problem:

sdio.c:2403:3: warning: Attempt to free released memory

        kfree(card->mpa_rx.buf);
        ^~~~~~~~~~~~~~~~~~~~~~~

When mwifiex_init_sdio() fails in its first call to mwifiex_alloc_sdio_mpa_buffer, it falls back to calling it again. If the second alloc of mpa_tx.buf fails, the error handler will try to free the old, previously freed mpa_rx.buf. Reviewing the code, it looks like a second double free would happen with mwifiex_cleanup_sdio().

Quoted 5 lines

So set both pointers to NULL when they are freed.

Fixes 5e6e3a92b9a4 ("wireless: mwifiex: initial commit for Marvell mwifiex driver")

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

53708f4fd9cf mwifiex: fix double free

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

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