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>
Fri, 2 Dec 2022 16:41:04 +0000 (17:41 +0100)
commitf58df483ff37b1707eea56a93a025294c631a11a
tree5eef940c3e774aa0a594f701b548b0cf5d489bcf
parentda22d7410afd37a2cffe38b8c4d8efee50fad5c9
nfc/nci: fix race with opening and closing

[ Upstream commit 0ad6bded175e829c2ca261529c9dce39a32a042d ]

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: 48b71a9e66c2 ("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