[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202001071002.A236EBCA0@keescook>
Date: Tue, 7 Jan 2020 10:05:11 -0800
From: Kees Cook <keescook@...omium.org>
To: Cengiz Can <cengiz@...nel.wtf>
Cc: linux-kernel@...r.kernel.org, Anton Vorontsov <anton@...msg.org>,
Colin Cross <ccross@...roid.com>,
Tony Luck <tony.luck@...el.com>
Subject: Re: [PATCH] fs: pstore: fix double-free on ramoops_init_przs
On Tue, Jan 07, 2020 at 02:04:46PM +0300, Cengiz Can wrote:
> According to Coverity scanner (CID 1457526) kfree on ram.c:591 frees
> label which has already been freed.
>
> Here's the flow as I have understood (this is my first time reading
> pstore's files):
>
> Whenever `persistent_ram_new` fails, it implicitly calls
> `persistent_ram_free(prz)` which already does `kfree(prz->label)` and a
> `kfree(prz)` consequently.
>
> Removed `kfree(label)` to prevent double-free.
I think this is a false positive (have you actually hit the
double-free?). The logic in this area is:
label = kmalloc(...)
prz[i] = persistent_ram_new(..., label, ...)
if (IS_ERR(prz[i])) {
kfree(label)
while (i > 0) {
i--;
persistent_ram_free(prz[i]);
}
}
nothing was freeing the label on the failed prz, but all the other prz
labels were free (i.e. there is a "i--" that skips the failed prz
alloc).
-Kees
>
> Signed-off-by: Cengiz Can <cengiz@...nel.wtf>
> ---
> fs/pstore/ram.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index 487ee39b4..e196aa08f 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -588,7 +588,6 @@ static int ramoops_init_przs(const char *name,
> dev_err(dev, "failed to request %s mem region (0x%zx@...llx): %d\n",
> name, record_size,
> (unsigned long long)*paddr, err);
> - kfree(label);
>
> while (i > 0) {
> i--;
> --
> 2.24.1
>
--
Kees Cook
Powered by blists - more mailing lists