Skip to contentSkip to conversation

nfc: virtual_ncidev: Add variable to check if ndev is running

PATCH Applied Nguyen Dinh Phi 4 participants 4 messages Nov 21, 2023 – Nov 22, 2023

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

PATCH v2 1/1 nfc: virtual_ncidev: Add variable to check if ndev is running

syzbot reported an memory leak that happens when an skb is add to send_buff after virtual nci closed.
This patch adds a variable to track if the ndev is running before handling new skb in send function.

---
V2:
- Remove unused macro.
- Re-adding a line that was removed wrongly.

 drivers/nfc/virtual_ncidev.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/nfc/virtual_ncidev.c +6 -1
index b027be0b0b6f..590b038e449e 100644
@@ -26,10 +26,14 @@ struct virtual_nci_dev {
 	struct mutex mtx;
 	struct sk_buff *send_buff;
 	struct wait_queue_head wq;
+	bool running;
 };
 
 static int virtual_nci_open(struct nci_dev *ndev)
 {
+	struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
+
+	vdev->running = true;
 	return 0;
 }
 
@@ -40,6 +44,7 @@ static int virtual_nci_close(struct nci_dev *ndev)
 	mutex_lock(&vdev->mtx);
 	kfree_skb(vdev->send_buff);
 	vdev->send_buff = NULL;
+	vdev->running = false;
 	mutex_unlock(&vdev->mtx);
 
 	return 0;
@@ -50,7 +55,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
 	struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
 
 	mutex_lock(&vdev->mtx);
-	if (vdev->send_buff) {
+	if (vdev->send_buff || !vdev->running) {
 		mutex_unlock(&vdev->mtx);
 		kfree_skb(skb);
 		return -1;
Signature · 1 line
2.39.2
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 53 lines · Nguyen Dinh Phi

syzbot reported an memory leak that happens when an skb is add to send_buff after virtual nci closed.
This patch adds a variable to track if the ndev is running before handling new skb in send function.

---
V2:
- Remove unused macro.
- Re-adding a line that was removed wrongly.

 drivers/nfc/virtual_ncidev.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/nfc/virtual_ncidev.c +6 -1
index b027be0b0b6f..590b038e449e 100644
@@ -26,10 +26,14 @@ struct virtual_nci_dev {
 	struct mutex mtx;
 	struct sk_buff *send_buff;
 	struct wait_queue_head wq;
+	bool running;
 };
 
 static int virtual_nci_open(struct nci_dev *ndev)
 {
+	struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
+
+	vdev->running = true;
 	return 0;
 }
 
@@ -40,6 +44,7 @@ static int virtual_nci_close(struct nci_dev *ndev)
 	mutex_lock(&vdev->mtx);
 	kfree_skb(vdev->send_buff);
 	vdev->send_buff = NULL;
+	vdev->running = false;
 	mutex_unlock(&vdev->mtx);
 
 	return 0;
@@ -50,7 +55,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
 	struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
 
 	mutex_lock(&vdev->mtx);
-	if (vdev->send_buff) {
+	if (vdev->send_buff || !vdev->running) {
 		mutex_unlock(&vdev->mtx);
 		kfree_skb(skb);
 		return -1;
Signature · 1 line
2.39.2
Reviewed-by Bongsu Jeon

Best regards,
Bongsu

Reviewed-by on v2 1/1
#2 lore raw
In reply to Nguyen Dinh Phi
Quoted 11 lines · Nguyen Dinh Phi

syzbot reported an memory leak that happens when an skb is add to send_buff after virtual nci closed.
This patch adds a variable to track if the ndev is running before handling new skb in send function.

---
V2:
- Remove unused macro.

Best regards,
Krzysztof

#3 lore raw
In reply to Nguyen Dinh Phi
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

Quoted 10 lines · On Tue, 21 Nov 2023 15:53:57 +0800 you wrote:

syzbot reported an memory leak that happens when an skb is add to send_buff after virtual nci closed.
This patch adds a variable to track if the ndev is running before handling new skb in send function.

[...]

Here is the summary with links:
- [v2] nfc: virtual_ncidev: Add variable to check if ndev is running

    https://git.kernel.org/netdev/net/c/84d2db91f14a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html