Skip to content

Commit 84d2db9

Browse files
ita93davem330
authored andcommitted
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: 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]>
1 parent b6fe6f0 commit 84d2db9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/nfc/virtual_ncidev.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ struct virtual_nci_dev {
2626
struct mutex mtx;
2727
struct sk_buff *send_buff;
2828
struct wait_queue_head wq;
29+
bool running;
2930
};
3031

3132
static int virtual_nci_open(struct nci_dev *ndev)
3233
{
34+
struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
35+
36+
vdev->running = true;
3337
return 0;
3438
}
3539

@@ -40,6 +44,7 @@ static int virtual_nci_close(struct nci_dev *ndev)
4044
mutex_lock(&vdev->mtx);
4145
kfree_skb(vdev->send_buff);
4246
vdev->send_buff = NULL;
47+
vdev->running = false;
4348
mutex_unlock(&vdev->mtx);
4449

4550
return 0;
@@ -50,7 +55,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
5055
struct virtual_nci_dev *vdev = nci_get_drvdata(ndev);
5156

5257
mutex_lock(&vdev->mtx);
53-
if (vdev->send_buff) {
58+
if (vdev->send_buff || !vdev->running) {
5459
mutex_unlock(&vdev->mtx);
5560
kfree_skb(skb);
5661
return -1;

0 commit comments

Comments
 (0)