]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nfc/nci: fix race with opening and closing
authorLin Ma <linma@zju.edu.cn>
Wed, 16 Nov 2022 13:02:49 +0000 (21:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Dec 2022 10:22:58 +0000 (11:22 +0100)
[ Upstream commit 4481d3ffe831194b39c032b02b4286042651a591 ]

Previously we leverage NCI_UNREG and the lock inside nci_close_device to
prevent the race condition between opening a device and closing a
device. However, it still has problem because a failed opening command
will erase the NCI_UNREG flag and allow another opening command to
bypass the status checking.

This fix corrects that by making sure the NCI_UNREG is held.

Reported-by: syzbot+43475bf3cfbd6e41f5b7@syzkaller.appspotmail.com
Fixes: 5437906a10e9 ("NFC: add NCI_UNREG flag to eliminate the race")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/nfc/nci/core.c

index b2e922fcc70da9eb80fea9ca7b9f97e9f4e695af..57849baf9294d633d8e6a028225e58d8c1204d30 100644 (file)
@@ -530,7 +530,7 @@ static int nci_open_device(struct nci_dev *ndev)
                skb_queue_purge(&ndev->tx_q);
 
                ndev->ops->close(ndev);
-               ndev->flags = 0;
+               ndev->flags &= BIT(NCI_UNREG);
        }
 
 done: