linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cengiz Can <cengiz@kernel.wtf>
To: linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>,
	Anton Vorontsov <anton@enomsg.org>,
	Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>
Cc: Cengiz Can <cengiz@kernel.wtf>
Subject: [PATCH] fs: pstore: fix double-free on ramoops_init_przs
Date: Tue,  7 Jan 2020 14:04:46 +0300	[thread overview]
Message-ID: <20200107110445.162404-1-cengiz@kernel.wtf> (raw)

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.

Signed-off-by: Cengiz Can <cengiz@kernel.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@0x%llx): %d\n",
 				name, record_size,
 				(unsigned long long)*paddr, err);
-			kfree(label);
 
 			while (i > 0) {
 				i--;
-- 
2.24.1


             reply	other threads:[~2020-01-07 11:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-07 11:04 Cengiz Can [this message]
2020-01-07 18:05 ` [PATCH] fs: pstore: fix double-free on ramoops_init_przs Kees Cook
2020-01-07 19:40   ` Cengiz Can
2020-01-08 18:01     ` Kees Cook

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=20200107110445.162404-1-cengiz@kernel.wtf \
    --to=cengiz@kernel.wtf \
    --cc=anton@enomsg.org \
    --cc=ccross@android.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tony.luck@intel.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).