diff mbox

mailbox/tegra-hsp: Use after free in tegra_hsp_remove_doorbells()

Message ID 20161118113410.GC3150@mwanda
State Accepted
Headers show

Commit Message

Dan Carpenter Nov. 18, 2016, 11:34 a.m. UTC
We have to use the _safe version of list_for_each() because we're
freeing the pointer as we go along.  (This might not show up testing
depending on what config options you have enabled).

Fixes: ed65ee43e397 ("mailbox: Add Tegra HSP driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Thierry Reding Nov. 18, 2016, 1:31 p.m. UTC | #1
On Fri, Nov 18, 2016 at 02:34:10PM +0300, Dan Carpenter wrote:
> We have to use the _safe version of list_for_each() because we're
> freeing the pointer as we go along.  (This might not show up testing
> depending on what config options you have enabled).
> 
> Fixes: ed65ee43e397 ("mailbox: Add Tegra HSP driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Good catch! I've applied this on top of the original driver patch that
Jassi acked earlier and I updated the Fixes: line with the new commit
SHA1.

Thanks,
Thierry
diff mbox

Patch

diff --git a/drivers/mailbox/tegra-hsp.c b/drivers/mailbox/tegra-hsp.c
index 17b256a..87be8d3 100644
--- a/drivers/mailbox/tegra-hsp.c
+++ b/drivers/mailbox/tegra-hsp.c
@@ -397,12 +397,12 @@  static struct mbox_chan *of_tegra_hsp_xlate(struct mbox_controller *mbox,
 
 static void tegra_hsp_remove_doorbells(struct tegra_hsp *hsp)
 {
-	struct tegra_hsp_doorbell *db;
+	struct tegra_hsp_doorbell *db, *tmp;
 	unsigned long flags;
 
 	spin_lock_irqsave(&hsp->lock, flags);
 
-	list_for_each_entry(db, &hsp->doorbells, list)
+	list_for_each_entry_safe(db, tmp, &hsp->doorbells, list)
 		__tegra_hsp_doorbell_destroy(db);
 
 	spin_unlock_irqrestore(&hsp->lock, flags);