All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxin B John <maxin.john@gmail.com>
To: akpm@linux-foundation.org
Cc: segooon@gmail.com, jkosina@suse.cz, tj@kernel.org,
	tglx@linutronix.de, eike-kernel@sf-tec.de,
	linux-kernel@vger.kernel.org
Subject: [PATCH] [RESEND] devres: Fix possible use after free
Date: Tue, 14 Jun 2011 10:07:32 +0300	[thread overview]
Message-ID: <20110614070732.GA3355@maxin> (raw)

A freed pointer is passed as an argument to the function "devres_destroy()" in
"kernel/irq/devres.c" and "lib/devres.c". This patch fixes the possible use 
after free.

It's notabug at this time, but the code is dangerous.

Signed-off-by: Maxin B. John <maxin.john@gmail.com>
Reviewed-by: Rolf Eike Beer <eike-kernel@sf-tec.de>
Acked-by: Tejun Heo <tj@kernel.org>
---
diff --git a/kernel/irq/devres.c b/kernel/irq/devres.c
index 1ef4ffc..bd8e788 100644
--- a/kernel/irq/devres.c
+++ b/kernel/irq/devres.c
@@ -87,8 +87,8 @@ void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id)
 {
 	struct irq_devres match_data = { irq, dev_id };
 
-	free_irq(irq, dev_id);
 	WARN_ON(devres_destroy(dev, devm_irq_release, devm_irq_match,
 			       &match_data));
+	free_irq(irq, dev_id);
 }
 EXPORT_SYMBOL(devm_free_irq);
diff --git a/lib/devres.c b/lib/devres.c
index 6efddf5..7c0e953 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -79,9 +79,9 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
  */
 void devm_iounmap(struct device *dev, void __iomem *addr)
 {
-	iounmap(addr);
 	WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
 			       (void *)addr));
+	iounmap(addr);
 }
 EXPORT_SYMBOL(devm_iounmap);
 

             reply	other threads:[~2011-06-14  7:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-14  7:07 Maxin B John [this message]
2011-06-14  7:15 ` [PATCH] [RESEND] devres: Fix possible use after free Tejun Heo
2011-06-14 14:09   ` Maxin B John
2011-06-15  8:13     ` Tejun Heo
2011-06-15  9:59       ` Maxin B John
2011-06-15 10:00       ` Rolf Eike Beer
2011-06-15 10:12         ` Maxin B John
  -- strict thread matches above, loose matches on Subject: below --
2011-06-15 17:14 Maxin B John

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=20110614070732.GA3355@maxin \
    --to=maxin.john@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=eike-kernel@sf-tec.de \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=segooon@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.