Skip to content

Commit

Permalink
nfc: virtual_ncidev: Add variable to check if ndev is running
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reported-by: [email protected]
Closes: https://lore.kernel.org/lkml/[email protected]
Reviewed-by: Bongsu Jeon
Reviewed-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ita93 authored and davem330 committed Nov 22, 2023
1 parent b6fe6f0 commit 84d2db9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/nfc/virtual_ncidev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 84d2db9

Please sign in to comment.