public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcin Slusarz <marcin.slusarz@gmail.com>
To: Dan Carpenter <error27@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	eteo@redhat.com, Christoph Hellwig <hch@lst.de>,
	David Woodhouse <dwmw2@infradead.org>
Subject: [PATCH] mtd: fix use after free in register_mtd_blktrans
Date: Sat, 28 Mar 2009 18:44:24 +0100	[thread overview]
Message-ID: <49CE61F8.5090303@gmail.com> (raw)
In-Reply-To: <a63d67fe0903240529v6a0e6b51pf67f8ad6dd6842c4@mail.gmail.com>

Dan Carpenter wrote:
> I added a check to smatch (http://repo.or.cz/w/smatch.git/) to check
> for when we dereference
> freed memory.
> 
> (...)
> drivers/mtd/mtd_blkdevs.c +389 register_mtd_blktrans(49) '*tr->blkcore_priv'
> (...)

Fix:
---
From: Marcin Slusarz <marcin.slusarz@gmail.com>
Subject: [PATCH] mtd: fix use after free in register_mtd_blktrans

Reported-by: Dan Carpenter <error27@gmail.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com>
---
 drivers/mtd/mtd_blkdevs.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 1409f01..4109e0b 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -382,11 +382,12 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
 	tr->blkcore_priv->thread = kthread_run(mtd_blktrans_thread, tr,
 			"%sd", tr->name);
 	if (IS_ERR(tr->blkcore_priv->thread)) {
+		int ret = PTR_ERR(tr->blkcore_priv->thread);
 		blk_cleanup_queue(tr->blkcore_priv->rq);
 		unregister_blkdev(tr->major, tr->name);
 		kfree(tr->blkcore_priv);
 		mutex_unlock(&mtd_table_mutex);
-		return PTR_ERR(tr->blkcore_priv->thread);
+		return ret;
 	}
 
 	INIT_LIST_HEAD(&tr->devs);
-- 
1.6.0.6


  parent reply	other threads:[~2009-03-28 17:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-24 12:29 Dereferencing freed memory bugs Dan Carpenter
2009-03-28 17:17 ` Marcin Slusarz
2009-03-28 17:31 ` Marcin Slusarz
2009-03-28 17:44 ` Marcin Slusarz [this message]
2009-03-28 17:53 ` Marcin Slusarz
2009-03-28 18:18 ` Marcin Slusarz
2009-03-28 18:50 ` Marcin Slusarz
2009-03-28 19:12 ` Marcin Slusarz

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=49CE61F8.5090303@gmail.com \
    --to=marcin.slusarz@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=error27@gmail.com \
    --cc=eteo@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    /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