* [PATCH] wireless: mwifiex: fix double free
@ 2020-10-04 13:19 trix
2020-10-05 17:58 ` Brian Norris
2020-10-08 10:46 ` Kalle Valo
0 siblings, 2 replies; 3+ messages in thread
From: trix @ 2020-10-04 13:19 UTC (permalink / raw)
To: amitkarwar, ganapathi.bhat, huxinming820, kvalo, davem, kuba,
natechancellor, ndesaulniers, linville, nishants, rramesh, bzhao,
frankh
Cc: linux-wireless, netdev, linux-kernel, clang-built-linux, Tom Rix
From: Tom Rix <trix@redhat.com>
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")
Signed-off-by: Tom Rix <trix@redhat.com>
---
drivers/net/wireless/marvell/mwifiex/sdio.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/wireless/marvell/mwifiex/sdio.c b/drivers/net/wireless/marvell/mwifiex/sdio.c
index 69911c728eb1..bde9e4bbfffe 100644
--- a/drivers/net/wireless/marvell/mwifiex/sdio.c
+++ b/drivers/net/wireless/marvell/mwifiex/sdio.c
@@ -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;
--
2.18.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] wireless: mwifiex: fix double free
2020-10-04 13:19 [PATCH] wireless: mwifiex: fix double free trix
@ 2020-10-05 17:58 ` Brian Norris
2020-10-08 10:46 ` Kalle Valo
1 sibling, 0 replies; 3+ messages in thread
From: Brian Norris @ 2020-10-05 17:58 UTC (permalink / raw)
To: trix
Cc: amit karwar, Ganapathi Bhat, Xinming Hu, Kalle Valo,
David S. Miller, Jakub Kicinski, Nathan Chancellor, ndesaulniers,
linville, Nishant Sarmukadam, rramesh, bzhao, Frank Huang,
linux-wireless, <netdev@vger.kernel.org>,
Linux Kernel, clang-built-linux
On Sun, Oct 4, 2020 at 6:19 AM <trix@redhat.com> wrote:
>
> From: Tom Rix <trix@redhat.com>
>
> 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.
> 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")
> Signed-off-by: Tom Rix <trix@redhat.com>
For whatever it's worth:
Reviewed-by: Brian Norris <briannorris@chromium.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: mwifiex: fix double free
2020-10-04 13:19 [PATCH] wireless: mwifiex: fix double free trix
2020-10-05 17:58 ` Brian Norris
@ 2020-10-08 10:46 ` Kalle Valo
1 sibling, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2020-10-08 10:46 UTC (permalink / raw)
To: trix
Cc: amitkarwar, ganapathi.bhat, huxinming820, davem, kuba,
natechancellor, ndesaulniers, linville, nishants, rramesh, bzhao,
frankh, linux-wireless, netdev, linux-kernel, clang-built-linux,
Tom Rix
trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
>
> 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")
> Signed-off-by: Tom Rix <trix@redhat.com>
> Reviewed-by: Brian Norris <briannorris@chromium.org>
Patch applied to wireless-drivers-next.git, thanks.
53708f4fd9cf mwifiex: fix double free
--
https://patchwork.kernel.org/patch/11815655/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-08 10:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-04 13:19 [PATCH] wireless: mwifiex: fix double free trix
2020-10-05 17:58 ` Brian Norris
2020-10-08 10:46 ` Kalle Valo
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).