Skip to contentSkip to conversation

dma: mv_xor: fix kernel crash on probe error

PATCH New Aaro Koskinen 5 participants 7 messages Dec 12, 2013 – Dec 18, 2013 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma: mv_xor: fix kernel crash on probe error

If the non-DT channel add path fails, the kernel will crash as the channel is not set to NULL and it will try to release the channel using the error value. Fix that.

---
 drivers/dma/mv_xor.c | 1 +
 1 file changed, 1 insertion(+)
drivers/dma/mv_xor.c +1 -0
index 7807f0ef4e20..2cb35a62c7f0 100644
@@ -1227,6 +1227,7 @@ static int mv_xor_probe(struct platform_device *pdev)
 						   cd->cap_mask, irq);
 			if (IS_ERR(xordev->channels[i])) {
 				ret = PTR_ERR(xordev->channels[i]);
+				xordev->channels[i] = NULL;
 				goto err_channel_add;
 			}
 		}
Signature · 1 line
1.8.5.1
#1 lore raw

PATCH 1/1 dma: mv_xor: fix kernel crash on probe error

Quoted 8 lines · Aaro Koskinen

If the non-DT channel add path fails, the kernel will crash as the channel is not set to NULL and it will try to release the channel using the error value. Fix that.

---
 drivers/dma/mv_xor.c | 1 +
 1 file changed, 1 insertion(+)

thx,

Jason.

#2 lore raw

PATCH 1/1 dma: mv_xor: fix kernel crash on probe error

In reply to Aaro Koskinen
Quoted 14 lines · Aaro Koskinen

If the non-DT channel add path fails, the kernel will crash as the channel is not set to NULL and it will try to release the channel using the error value. Fix that.

---
 drivers/dma/mv_xor.c | 1 +
 1 file changed, 1 insertion(+)
drivers/dma/mv_xor.c +0 -0
index 7807f0ef4e20..2cb35a62c7f0 100644

drivers/dma/mv_xor.c static int mv_xor_probe(struct platform_device *pdev) · line 1233

Quoted 7 lines
drivers/dma/mv_xor.c +1 -0
@@ -1227,6 +1227,7 @@ static int mv_xor_probe(struct platform_device *pdev)
 						   cd->cap_mask, irq);
 			if (IS_ERR(xordev->channels[i])) {
 				ret = PTR_ERR(xordev->channels[i]);
+				xordev->channels[i] = NULL;
 				goto err_channel_add;
 			}
 		}

Yes, I found this too, and although this is _a_ fix, it's not my preferred. I'd much prefer this instead - avoid writing invalid channels to xordev->channels[i] in the first place... Slightly larger patch but IMHO more correct.

drivers/dma/mv_xor.c +13 -11
index 7807f0ef4e20..a7e91090443e 100644
@@ -1176,6 +1176,7 @@ static int mv_xor_probe(struct platform_device *pdev)
 		int i = 0;
 
 		for_each_child_of_node(pdev->dev.of_node, np) {
+			struct mv_xor_chan *chan;
 			dma_cap_mask_t cap_mask;
 			int irq;
 
@@ -1193,21 +1194,21 @@ static int mv_xor_probe(struct platform_device *pdev)
 				goto err_channel_add;
 			}
 
-			xordev->channels[i] =
-				mv_xor_channel_add(xordev, pdev, i,
-						   cap_mask, irq);
-			if (IS_ERR(xordev->channels[i])) {
-				ret = PTR_ERR(xordev->channels[i]);
-				xordev->channels[i] = NULL;
+			chan = mv_xor_channel_add(xordev, pdev, i,
+						  cap_mask, irq);
+			if (IS_ERR(chan)) {
+				ret = PTR_ERR(chan);
 				irq_dispose_mapping(irq);
 				goto err_channel_add;
 			}
 
+			xordev->channels[i] = chan;
 			i++;
 		}
 	} else if (pdata && pdata->channels) {
 		for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) {
 			struct mv_xor_channel_data *cd;
+			struct mv_xor_chan *chan;
 			int irq;
 
 			cd = &pdata->channels[i];
@@ -1222,13 +1223,14 @@ static int mv_xor_probe(struct platform_device *pdev)
 				goto err_channel_add;
 			}
 
-			xordev->channels[i] =
-				mv_xor_channel_add(xordev, pdev, i,
-						   cd->cap_mask, irq);
-			if (IS_ERR(xordev->channels[i])) {
-				ret = PTR_ERR(xordev->channels[i]);
+			chan = mv_xor_channel_add(xordev, pdev, i,
+						  cd->cap_mask, irq);
+			if (IS_ERR(chan)) {
+				ret = PTR_ERR(chan);
 				goto err_channel_add;
 			}
+
+			xordev->channels[i] = chan;
 		}
 	}
 
#3 lore raw

PATCH 1/1 dma: mv_xor: fix kernel crash on probe error

Quoted 19 lines · Russell King - ARM Linux
Quoted 18 lines · Aaro Koskinen

If the non-DT channel add path fails, the kernel will crash as the channel is not set to NULL and it will try to release the channel using the error value. Fix that.

---
 drivers/dma/mv_xor.c | 1 +
 1 file changed, 1 insertion(+)
drivers/dma/mv_xor.c +1 -0
index 7807f0ef4e20..2cb35a62c7f0 100644
@@ -1227,6 +1227,7 @@ static int mv_xor_probe(struct platform_device *pdev)
                                                 cd->cap_mask, irq);
                      if (IS_ERR(xordev->channels[i])) {
                              ret = PTR_ERR(xordev->channels[i]);
+                             xordev->channels[i] = NULL;
Quoted 9 lines

drivers/dma/mv_xor.c static int mv_xor_probe(struct platform_device *pdev) · line 1203

Quoted 3 lines
drivers/dma/mv_xor.c +0 -0
                              goto err_channel_add;
                      }
              }

Yes, I found this too, and although this is _a_ fix, it's not my preferred. I'd much prefer this instead - avoid writing invalid channels to xordev->channels[i] in the first place... Slightly larger patch but IMHO more correct.

Looks good to me. Aaro?

Can I have one with a sign-off?

#4 lore raw

PATCH 1/1 dma: mv_xor: fix kernel crash on probe error

Quoted 31 lines · Dan Williams
Quoted 19 lines · Russell King - ARM Linux
Quoted 18 lines · Aaro Koskinen

If the non-DT channel add path fails, the kernel will crash as the channel is not set to NULL and it will try to release the channel using the error value. Fix that.

---
 drivers/dma/mv_xor.c | 1 +
 1 file changed, 1 insertion(+)
drivers/dma/mv_xor.c +1 -0
index 7807f0ef4e20..2cb35a62c7f0 100644
@@ -1227,6 +1227,7 @@ static int mv_xor_probe(struct platform_device *pdev)
                                                 cd->cap_mask, irq);
                      if (IS_ERR(xordev->channels[i])) {
                              ret = PTR_ERR(xordev->channels[i]);
+                             xordev->channels[i] = NULL;
Quoted 9 lines

drivers/dma/mv_xor.c static int mv_xor_probe(struct platform_device *pdev) · line 1203

Quoted 3 lines
drivers/dma/mv_xor.c +0 -0
                              goto err_channel_add;
                      }
              }

Yes, I found this too, and although this is _a_ fix, it's not my preferred. I'd much prefer this instead - avoid writing invalid channels to xordev->channels[i] in the first place... Slightly larger patch but IMHO more correct.

Quoted 1 line

Looks good to me. Aaro?

I'm also fine this version. Just to be sure, I tested the error path on my Marvell OpenRD client, so you can put my Tested-by to the final patch.

A.

#5 lore raw

PATCH 1/1 dma: mv_xor: fix kernel crash on probe error

From: Russell King <[email protected]>
Subject: [PATCH] dmaengine: mv_xor: fix oops when channels fail to initialise

When a channel fails to initialise, we error out and clean up any previously unregistered channels by walking the entire xordev->channels array. Unfortunately, there are paths which end up storing an error pointer in this array, which we then try and dereference in the cleanup code, which causes an oops.

Fix this by avoiding writing invalid pointers to this array in the first place.

---
 drivers/dma/mv_xor.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)
drivers/dma/mv_xor.c +13 -11
index 7807f0ef4e20..a7e91090443e 100644
@@ -1176,6 +1176,7 @@ static int mv_xor_probe(struct platform_device *pdev)
 		int i = 0;
 
 		for_each_child_of_node(pdev->dev.of_node, np) {
+			struct mv_xor_chan *chan;
 			dma_cap_mask_t cap_mask;
 			int irq;
 
@@ -1193,21 +1194,21 @@ static int mv_xor_probe(struct platform_device *pdev)
 				goto err_channel_add;
 			}
 
-			xordev->channels[i] =
-				mv_xor_channel_add(xordev, pdev, i,
-						   cap_mask, irq);
-			if (IS_ERR(xordev->channels[i])) {
-				ret = PTR_ERR(xordev->channels[i]);
-				xordev->channels[i] = NULL;
+			chan = mv_xor_channel_add(xordev, pdev, i,
+						  cap_mask, irq);
+			if (IS_ERR(chan)) {
+				ret = PTR_ERR(chan);
 				irq_dispose_mapping(irq);
 				goto err_channel_add;
 			}
 
+			xordev->channels[i] = chan;
 			i++;
 		}
 	} else if (pdata && pdata->channels) {
 		for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) {
 			struct mv_xor_channel_data *cd;
+			struct mv_xor_chan *chan;
 			int irq;
 
 			cd = &pdata->channels[i];
@@ -1222,13 +1223,14 @@ static int mv_xor_probe(struct platform_device *pdev)
 				goto err_channel_add;
 			}
 
-			xordev->channels[i] =
-				mv_xor_channel_add(xordev, pdev, i,
-						   cd->cap_mask, irq);
-			if (IS_ERR(xordev->channels[i])) {
-				ret = PTR_ERR(xordev->channels[i]);
+			chan = mv_xor_channel_add(xordev, pdev, i,
+						  cd->cap_mask, irq);
+			if (IS_ERR(chan)) {
+				ret = PTR_ERR(chan);
 				goto err_channel_add;
 			}
+
+			xordev->channels[i] = chan;
 		}
 	}
 
#6 lore raw

PATCH 1/1 dma: mv_xor: fix kernel crash on probe error

Quoted 9 lines · Russell King - ARM Linux

From: Russell King <[email protected]>
Subject: [PATCH] dmaengine: mv_xor: fix oops when channels fail to initialise

When a channel fails to initialise, we error out and clean up any previously unregistered channels by walking the entire xordev->channels array. Unfortunately, there are paths which end up storing an error pointer in this array, which we then try and dereference in the cleanup code, which causes an oops.

Quoted 5 lines

Fix this by avoiding writing invalid pointers to this array in the first place.

--
~Vinod

Quoted 64 lines
---
 drivers/dma/mv_xor.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)
drivers/dma/mv_xor.c +13 -11
index 7807f0ef4e20..a7e91090443e 100644
@@ -1176,6 +1176,7 @@ static int mv_xor_probe(struct platform_device *pdev)
 		int i = 0;
 
 		for_each_child_of_node(pdev->dev.of_node, np) {
+			struct mv_xor_chan *chan;
 			dma_cap_mask_t cap_mask;
 			int irq;
 
@@ -1193,21 +1194,21 @@ static int mv_xor_probe(struct platform_device *pdev)
 				goto err_channel_add;
 			}
 
-			xordev->channels[i] =
-				mv_xor_channel_add(xordev, pdev, i,
-						   cap_mask, irq);
-			if (IS_ERR(xordev->channels[i])) {
-				ret = PTR_ERR(xordev->channels[i]);
-				xordev->channels[i] = NULL;
+			chan = mv_xor_channel_add(xordev, pdev, i,
+						  cap_mask, irq);
+			if (IS_ERR(chan)) {
+				ret = PTR_ERR(chan);
 				irq_dispose_mapping(irq);
 				goto err_channel_add;
 			}
 
+			xordev->channels[i] = chan;
 			i++;
 		}
 	} else if (pdata && pdata->channels) {
 		for (i = 0; i < MV_XOR_MAX_CHANNELS; i++) {
 			struct mv_xor_channel_data *cd;
+			struct mv_xor_chan *chan;
 			int irq;
 
 			cd = &pdata->channels[i];
@@ -1222,13 +1223,14 @@ static int mv_xor_probe(struct platform_device *pdev)
 				goto err_channel_add;
 			}
 
-			xordev->channels[i] =
-				mv_xor_channel_add(xordev, pdev, i,
-						   cd->cap_mask, irq);
-			if (IS_ERR(xordev->channels[i])) {
-				ret = PTR_ERR(xordev->channels[i]);
+			chan = mv_xor_channel_add(xordev, pdev, i,
+						  cd->cap_mask, irq);
+			if (IS_ERR(chan)) {
+				ret = PTR_ERR(chan);
 				goto err_channel_add;
 			}
+
+			xordev->channels[i] = chan;
 		}
 	}