Skip to contentSkip to conversation

net: ep93xx_eth: Do not crash unloading module

PATCH Applied Florian Fainelli 2 participants 3 messages Dec 5, 2016 – Dec 6, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ep93xx_eth: Do not crash unloading module

When we unload the ep93xx_eth, whether we have opened the network interface or not, we will either hit a kernel paging request error, or a simple NULL pointer de-reference because:

- if ep93xx_open has been called, we have created a valid DMA mapping for ep->descs, when we call ep93xx_stop, we also call ep93xx_free_buffers, ep->descs now has a stale value

- if ep93xx_open has not been called, we have a NULL pointer for ep->descs, so performing any operation against that address just won't work

Fix this by adding a NULL pointer check for ep->descs which means that ep93xx_free_buffers() was able to successfully tear down the descriptors and free the DMA cookie as well.

Fixes 1d22e05df818 ("[PATCH] Cirrus Logic ep93xx ethernet driver")
---
 drivers/net/ethernet/cirrus/ep93xx_eth.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/cirrus/ep93xx_eth.c +4 -0
index de9f7c97d916..9a161e981529 100644
@@ -468,6 +468,9 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 	struct device *dev = ep->dev->dev.parent;
 	int i;
 
+	if (!ep->descs)
+		return;
+
 	for (i = 0; i < RX_QUEUE_ENTRIES; i++) {
 		dma_addr_t d;
 
@@ -490,6 +493,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 
 	dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs,
 							ep->descs_dma_addr);
+	ep->descs = NULL;
 }
 
 static int ep93xx_alloc_buffers(struct ep93xx_priv *ep)
Signature · 1 line
2.9.3
maintainer Applied
#1 lore raw

From: Florian Fainelli <[email protected]>
Date: Sun, 4 Dec 2016 19:22:05 -0800

Quoted 12 lines

When we unload the ep93xx_eth, whether we have opened the network interface or not, we will either hit a kernel paging request error, or a simple NULL pointer de-reference because:

- if ep93xx_open has been called, we have created a valid DMA mapping for ep->descs, when we call ep93xx_stop, we also call ep93xx_free_buffers, ep->descs now has a stale value

- if ep93xx_open has not been called, we have a NULL pointer for ep->descs, so performing any operation against that address just won't work

Quoted 6 lines

Fix this by adding a NULL pointer check for ep->descs which means that ep93xx_free_buffers() was able to successfully tear down the descriptors and free the DMA cookie as well.

Fixes 1d22e05df818 ("[PATCH] Cirrus Logic ep93xx ethernet driver")

Applied, thanks Florian.

#2 lore raw
Quoted 15 lines · David Miller

From: Florian Fainelli <[email protected]>
Date: Sun, 4 Dec 2016 19:22:05 -0800

Quoted 12 lines

When we unload the ep93xx_eth, whether we have opened the network interface or not, we will either hit a kernel paging request error, or a simple NULL pointer de-reference because:

- if ep93xx_open has been called, we have created a valid DMA mapping for ep->descs, when we call ep93xx_stop, we also call ep93xx_free_buffers, ep->descs now has a stale value

- if ep93xx_open has not been called, we have a NULL pointer for ep->descs, so performing any operation against that address just won't work

Quoted 8 lines
Quoted 6 lines

Fix this by adding a NULL pointer check for ep->descs which means that ep93xx_free_buffers() was able to successfully tear down the descriptors and free the DMA cookie as well.

Fixes 1d22e05df818 ("[PATCH] Cirrus Logic ep93xx ethernet driver")

Applied, thanks Florian.

Thanks! Can you also queue this one for -stable? The original commit dates back from 2006, but it should apply with minor hunks to all -stable kernels.

Cheers

Signature · 1 line
Florian