All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] nfc: virtual_ncidev: Add variable to check if ndev is running
@ 2023-11-21  7:53 Nguyen Dinh Phi
       [not found] ` <CGME20231121075419epcas2p280fa7111de7f37b46f460b6c61ff7175@epcms2p2>
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nguyen Dinh Phi @ 2023-11-21  7:53 UTC (permalink / raw)
  To: Bongsu Jeon, Krzysztof Kozlowski
  Cc: Nguyen Dinh Phi, syzbot+6eb09d75211863f15e3e, netdev, linux-kernel

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.

Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
Reported-by: syzbot+6eb09d75211863f15e3e@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/lkml/00000000000075472b06007df4fb@google.com
---
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(-)

diff --git a/drivers/nfc/virtual_ncidev.c b/drivers/nfc/virtual_ncidev.c
index b027be0b0b6f..590b038e449e 100644
--- a/drivers/nfc/virtual_ncidev.c
+++ b/drivers/nfc/virtual_ncidev.c
@@ -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;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] nfc: virtual_ncidev: Add variable to check if ndev is running
       [not found] ` <CGME20231121075419epcas2p280fa7111de7f37b46f460b6c61ff7175@epcms2p2>
@ 2023-11-21  8:17   ` Bongsu Jeon
  0 siblings, 0 replies; 4+ messages in thread
From: Bongsu Jeon @ 2023-11-21  8:17 UTC (permalink / raw)
  To: Nguyen Dinh Phi, Bongsu Jeon, Krzysztof Kozlowski
  Cc: syzbot+6eb09d75211863f15e3e, netdev, linux-kernel

On 21/11/2023 16:54, Nguyen Dinh Phi 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.
> 
> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
> Reported-by: syzbot+6eb09d75211863f15e3e@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/lkml/00000000000075472b06007df4fb@google.com
> ---
> 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(-)
> 
> diff --git a/drivers/nfc/virtual_ncidev.c b/drivers/nfc/virtual_ncidev.c
> index b027be0b0b6f..590b038e449e 100644
> --- a/drivers/nfc/virtual_ncidev.c
> +++ b/drivers/nfc/virtual_ncidev.c
> @@ -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;
> -- 
> 2.39.2


Reviewed-by: Bongsu Jeon

Best regards,
Bongsu

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] nfc: virtual_ncidev: Add variable to check if ndev is running
  2023-11-21  7:53 [PATCH v2] nfc: virtual_ncidev: Add variable to check if ndev is running Nguyen Dinh Phi
       [not found] ` <CGME20231121075419epcas2p280fa7111de7f37b46f460b6c61ff7175@epcms2p2>
@ 2023-11-21  9:00 ` Krzysztof Kozlowski
  2023-11-22 11:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-21  9:00 UTC (permalink / raw)
  To: Nguyen Dinh Phi, Bongsu Jeon
  Cc: syzbot+6eb09d75211863f15e3e, netdev, linux-kernel

On 21/11/2023 08:53, Nguyen Dinh Phi 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.
> 
> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
> Reported-by: syzbot+6eb09d75211863f15e3e@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/lkml/00000000000075472b06007df4fb@google.com
> ---
> V2:
>     - Remove unused macro.


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] nfc: virtual_ncidev: Add variable to check if ndev is running
  2023-11-21  7:53 [PATCH v2] nfc: virtual_ncidev: Add variable to check if ndev is running Nguyen Dinh Phi
       [not found] ` <CGME20231121075419epcas2p280fa7111de7f37b46f460b6c61ff7175@epcms2p2>
  2023-11-21  9:00 ` Krzysztof Kozlowski
@ 2023-11-22 11:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-11-22 11:00 UTC (permalink / raw)
  To: Nguyen Dinh Phi
  Cc: bongsu.jeon, krzysztof.kozlowski, syzbot+6eb09d75211863f15e3e,
	netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

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.
> 
> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com>
> Reported-by: syzbot+6eb09d75211863f15e3e@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/lkml/00000000000075472b06007df4fb@google.com
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-22 11:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21  7:53 [PATCH v2] nfc: virtual_ncidev: Add variable to check if ndev is running Nguyen Dinh Phi
     [not found] ` <CGME20231121075419epcas2p280fa7111de7f37b46f460b6c61ff7175@epcms2p2>
2023-11-21  8:17   ` Bongsu Jeon
2023-11-21  9:00 ` Krzysztof Kozlowski
2023-11-22 11:00 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.