* [PATCH] lib/test_kasan.c: Fix memory leak in kmalloc_oob_krealloc_more()
@ 2020-01-23 16:01 Gustavo A. R. Silva
2020-01-23 16:02 ` Dmitry Vyukov
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2020-01-23 16:01 UTC (permalink / raw)
To: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov,
Andrew Morton, Andrey Konovalov
Cc: kasan-dev, linux-kernel, Gustavo A. R. Silva
In case memory resources for _ptr2_ were allocated, release them
before return.
Notice that in case _ptr1_ happens to be NULL, krealloc() behaves
exactly like kmalloc().
Addresses-Coverity-ID: 1490594 ("Resource leak")
Fixes: 3f15801cdc23 ("lib: add kasan test module")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
lib/test_kasan.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 328d33beae36..3872d250ed2c 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -158,6 +158,7 @@ static noinline void __init kmalloc_oob_krealloc_more(void)
if (!ptr1 || !ptr2) {
pr_err("Allocation failed\n");
kfree(ptr1);
+ kfree(ptr2);
return;
}
--
2.25.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lib/test_kasan.c: Fix memory leak in kmalloc_oob_krealloc_more()
2020-01-23 16:01 [PATCH] lib/test_kasan.c: Fix memory leak in kmalloc_oob_krealloc_more() Gustavo A. R. Silva
@ 2020-01-23 16:02 ` Dmitry Vyukov
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Vyukov @ 2020-01-23 16:02 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Andrey Ryabinin, Alexander Potapenko, Andrew Morton,
Andrey Konovalov, kasan-dev, LKML
On Thu, Jan 23, 2020 at 4:59 PM Gustavo A. R. Silva
<gustavo@embeddedor.com> wrote:
>
> In case memory resources for _ptr2_ were allocated, release them
> before return.
>
> Notice that in case _ptr1_ happens to be NULL, krealloc() behaves
> exactly like kmalloc().
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
The scenario where ptr1 is NULL, but ptr2 is not NULL is not impossible indeed.
> Addresses-Coverity-ID: 1490594 ("Resource leak")
> Fixes: 3f15801cdc23 ("lib: add kasan test module")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
> lib/test_kasan.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 328d33beae36..3872d250ed2c 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -158,6 +158,7 @@ static noinline void __init kmalloc_oob_krealloc_more(void)
> if (!ptr1 || !ptr2) {
> pr_err("Allocation failed\n");
> kfree(ptr1);
> + kfree(ptr2);
> return;
> }
>
> --
> 2.25.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-01-23 16:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-23 16:01 [PATCH] lib/test_kasan.c: Fix memory leak in kmalloc_oob_krealloc_more() Gustavo A. R. Silva
2020-01-23 16:02 ` Dmitry Vyukov
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).