Re: [syzbot] [net?] [nfc?] WARNING: locking bug in nci_close_device (2)
From: Hillf Danton
Date: Thu Apr 04 2024 - 06:59:42 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,6 +560,10 @@ static int nci_close_device(struct nci_d
*/
mutex_lock(&ndev->req_lock);
+ if (test_and_set_bit(NCI_UNREG +1, &ndev->flags)) {
+ mutex_unlock(&ndev->req_lock);
+ return 0;
+ }
if (!test_and_clear_bit(NCI_UP, &ndev->flags)) {
/* Need to flush the cmd wq in case
* there is a queued/running cmd_work
@@ -601,6 +605,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);
--