Skip to contentSkip to conversation

libertas: Fix a double free in if_spi_c2h_data()

PATCH In review Dan Carpenter 3 participants 8 messages Jun 26, 2019 – Aug 6, 2019

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

PATCH 1/1 libertas: Fix a double free in if_spi_c2h_data()

The lbs_process_rxed_packet() frees the skb. It didn't originally, but we fixed it in commit f54930f36311 ("libertas: don't leak skb on receive error").

---
 drivers/net/wireless/marvell/libertas/if_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/marvell/libertas/if_spi.c +1 -1
index 27067e79e83f..e38f02d1f2e4 100644
@@ -772,7 +772,7 @@ static int if_spi_c2h_data(struct if_spi_card *card)
 	/* pass the SKB to libertas */
 	err = lbs_process_rxed_packet(card->priv, skb);
 	if (err)
-		goto free_skb;
+		goto out;  /* lbs_process_rxed_packet() frees skb */
 
 	/* success */
 	goto out;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 25 lines · Dan Carpenter

The lbs_process_rxed_packet() frees the skb. It didn't originally, but
we fixed it in commit f54930f36311 ("libertas: don't leak skb on receive
error").

---
 drivers/net/wireless/marvell/libertas/if_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/marvell/libertas/if_spi.c +1 -1
index 27067e79e83f..e38f02d1f2e4 100644
@@ -772,7 +772,7 @@ static int if_spi_c2h_data(struct if_spi_card
 *card)
 	/* pass the SKB to libertas */
 	err = lbs_process_rxed_packet(card->priv, skb);
 	if (err)
-		goto free_skb;
+		goto out;  /* lbs_process_rxed_packet() frees skb */
 
 	/* success */
Quoted 1 line

goto out;

It can be further simplified (not compile tested yet):

drivers/net/wireless/marvell/libertas/if_spi.c +5 -9
index 27067e79e83fe..072da89c4986f 100644
@@ -766,19 +766,15 @@ static int if_spi_c2h_data(struct if_spi_card *card)
 
 	/* Read the data from the WLAN module into our skb... */
 	err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, 4));
-	if (err)
-		goto free_skb;
+	if (err) {
+		dev_kfree_skb(skb);
+		goto out
+	}
 
 	/* pass the SKB to libertas */
 	err = lbs_process_rxed_packet(card->priv, skb);
-	if (err)
-		goto free_skb;
+	/* lbs_process_rxed_packet() consumes the skb */
 
-	/* success */
-	goto out;
-
-free_skb:
-	dev_kfree_skb(skb);
 out:
 	if (err)
 		netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
#2 lore raw

Yeah. That looks nicer. Could you send it as a proper patch and give me Reported-by credit?

regards,
dan carpenter

#3 lore raw
Quoted 3 lines · Dan Carpenter

Yeah. That looks nicer. Could you send it as a proper patch and give
me Reported-by credit?

Will do.

Dan

#4 lore raw

PATCH v2 1/1 libertas: Fix a double free in if_spi_c2h_data()

The lbs_process_rxed_packet() frees the skb. It didn't originally, but we fixed it in commit f54930f36311 ("libertas: don't leak skb on receive error").

---
 drivers/net/wireless/marvell/libertas/if_spi.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/net/wireless/marvell/libertas/if_spi.c +5 -9
index 27067e79e83fe..072da89c4986f 100644
@@ -766,19 +766,15 @@ static int if_spi_c2h_data(struct if_spi_card *card)
 
 	/* Read the data from the WLAN module into our skb... */
 	err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, 4));
-	if (err)
-		goto free_skb;
+	if (err) {
+		dev_kfree_skb(skb);
+		goto out
+	}
 
 	/* pass the SKB to libertas */
 	err = lbs_process_rxed_packet(card->priv, skb);
-	if (err)
-		goto free_skb;
+	/* lbs_process_rxed_packet() consumes the skb */
 
-	/* success */
-	goto out;
-
-free_skb:
-	dev_kfree_skb(skb);
 out:
 	if (err)
 		netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
Signature · 1 line
2.20.1
#5 lore raw
Quoted 6 lines · Dan Williams

The lbs_process_rxed_packet() frees the skb. It didn't originally, but we fixed it in commit f54930f36311 ("libertas: don't leak skb on receive error").

Failed to compile:

drivers/net/wireless/marvell/libertas/if_spi.c: In function 'if_spi_c2h_data':
drivers/net/wireless/marvell/libertas/if_spi.c:771:11: error: expected ';' before '}' token
goto out

           ^
           ;

}
~
make[5]: *** [drivers/net/wireless/marvell/libertas/if_spi.o] Error 1 make[4]: *** [drivers/net/wireless/marvell/libertas] Error 2 make[3]: *** [drivers/net/wireless/marvell] Error 2 make[3]: *** Waiting for unfinished jobs....
make[2]: *** [drivers/net/wireless] Error 2
make[1]: *** [drivers/net] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [drivers] Error 2

Patch set to Changes Requested.

Signature · 3 lines
https://patchwork.kernel.org/patch/11033059/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#6 lore raw

PATCH v3 1/1 libertas: Fix a double free in if_spi_c2h_data()

In reply to Dan Williams

The lbs_process_rxed_packet() frees the skb. It didn't originally, but we fixed it in commit f54930f36311 ("libertas: don't leak skb on receive error").

---

Kalle: sorry about the build error; previous version of the patch before I fixed it. Here's the correct one.

 drivers/net/wireless/marvell/libertas/if_spi.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/net/wireless/marvell/libertas/if_spi.c +5 -9
index 27067e79e83fe..d07fe82c557e8 100644
@@ -766,19 +766,15 @@ static int if_spi_c2h_data(struct if_spi_card *card)
 
 	/* Read the data from the WLAN module into our skb... */
 	err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, 4));
-	if (err)
-		goto free_skb;
+	if (err) {
+		dev_kfree_skb(skb);
+		goto out;
+	}
 
 	/* pass the SKB to libertas */
 	err = lbs_process_rxed_packet(card->priv, skb);
-	if (err)
-		goto free_skb;
+	/* lbs_process_rxed_packet() consumes the skb */
 
-	/* success */
-	goto out;
-
-free_skb:
-	dev_kfree_skb(skb);
 out:
 	if (err)
 		netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
Signature · 1 line
2.20.1
#7 lore raw
Quoted 6 lines · Dan Williams

The lbs_process_rxed_packet() frees the skb. It didn't originally, but we fixed it in commit f54930f36311 ("libertas: don't leak skb on receive error").

Patch applied to wireless-drivers-next.git, thanks.

3915a252ce71 libertas: Fix a double free in if_spi_c2h_data()

Signature · 3 lines
https://patchwork.kernel.org/patch/11057049/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches