Re: [syzbot] [net?] [nfc?] WARNING: locking bug in nci_close_device (2)

From: Hillf Danton
Date: Wed Apr 03 2024 - 20:01:20 EST


On Wed, 03 Apr 2024 12:49:25 -0700
> syzbot has found a reproducer for the following issue on:
>
> HEAD commit: fe46a7dd189e Merge tag 'sound-6.9-rc1' of git://git.kernel..
> git tree: upstream
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1201b6d3180000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git fe46a7dd189e

--- x/net/nfc/nci/core.c
+++ y/net/nfc/nci/core.c
@@ -560,7 +560,8 @@ static int nci_close_device(struct nci_d
*/
mutex_lock(&ndev->req_lock);

- if (!test_and_clear_bit(NCI_UP, &ndev->flags)) {
+ if (!test_and_clear_bit(NCI_UP, &ndev->flags) &&
+ !test_bit(NCI_UNREG +1, &ndev->flags)) {
/* Need to flush the cmd wq in case
* there is a queued/running cmd_work
*/
@@ -601,6 +602,7 @@ static int nci_close_device(struct nci_d

/* Clear flags except NCI_UNREG */
ndev->flags &= BIT(NCI_UNREG);
+ set_bit(NCI_UNREG +1, &ndev->flags);

mutex_unlock(&ndev->req_lock);

--