Commit 84d2db91 authored by Nguyen Dinh Phi's avatar Nguyen Dinh Phi Committed by David S. Miller

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.
Signed-off-by: default avatarNguyen Dinh Phi <phind.uet@gmail.com>
Reported-by: syzbot+6eb09d75211863f15e3e@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/lkml/00000000000075472b06007df4fb@google.com
Reviewed-by: Bongsu Jeon
Reviewed-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b6fe6f03
...@@ -26,10 +26,14 @@ struct virtual_nci_dev { ...@@ -26,10 +26,14 @@ struct virtual_nci_dev {
struct mutex mtx; struct mutex mtx;
struct sk_buff *send_buff; struct sk_buff *send_buff;
struct wait_queue_head wq; struct wait_queue_head wq;
bool running;
}; };
static int virtual_nci_open(struct nci_dev *ndev) static int virtual_nci_open(struct nci_dev *ndev)
{ {
struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
vdev->running = true;
return 0; return 0;
} }
...@@ -40,6 +44,7 @@ static int virtual_nci_close(struct nci_dev *ndev) ...@@ -40,6 +44,7 @@ static int virtual_nci_close(struct nci_dev *ndev)
mutex_lock(&vdev->mtx); mutex_lock(&vdev->mtx);
kfree_skb(vdev->send_buff); kfree_skb(vdev->send_buff);
vdev->send_buff = NULL; vdev->send_buff = NULL;
vdev->running = false;
mutex_unlock(&vdev->mtx); mutex_unlock(&vdev->mtx);
return 0; return 0;
...@@ -50,7 +55,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb) ...@@ -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); struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
mutex_lock(&vdev->mtx); mutex_lock(&vdev->mtx);
if (vdev->send_buff) { if (vdev->send_buff || !vdev->running) {
mutex_unlock(&vdev->mtx); mutex_unlock(&vdev->mtx);
kfree_skb(skb); kfree_skb(skb);
return -1; return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment