LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Dmitry Vyukov <dvyukov@google.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	Alexander Potapenko <glider@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andrey Konovalov <adech.fo@gmail.com>,
	kasan-dev <kasan-dev@googlegroups.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] lib/test_kasan.c: Fix memory leak in kmalloc_oob_krealloc_more()
Date: Thu, 23 Jan 2020 17:02:52 +0100
Message-ID: <CACT4Y+bOxBb_fy3jak=prrznOPEbm+nfeq_yUC8yrU+-3RP2UA@mail.gmail.com> (raw)
In-Reply-To: <20200123160115.GA4202@embeddedor>

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
>

      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-23 16:01 Gustavo A. R. Silva
2020-01-23 16:02 ` Dmitry Vyukov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACT4Y+bOxBb_fy3jak=prrznOPEbm+nfeq_yUC8yrU+-3RP2UA@mail.gmail.com' \
    --to=dvyukov@google.com \
    --cc=adech.fo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=glider@google.com \
    --cc=gustavo@embeddedor.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ryabinin.a.a@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git