net: nfc: llcp: Add lock when modifying device list
authorJeremy Cline <jeremy@jcline.org>
Fri, 8 Sep 2023 23:58:53 +0000 (19:58 -0400)
committerJakub Kicinski <kuba@kernel.org>
Tue, 3 Oct 2023 14:39:31 +0000 (07:39 -0700)
The device list needs its associated lock held when modifying it, or the
list could become corrupted, as syzbot discovered.

Reported-and-tested-by: syzbot+c1d0a03d305972dbbe14@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c1d0a03d305972dbbe14
Signed-off-by: Jeremy Cline <jeremy@jcline.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Fixes: 6709d4b7bc2e ("net: nfc: Fix use-after-free caused by nfc_llcp_find_local")
Link: https://lore.kernel.org/r/20230908235853.1319596-1-jeremy@jcline.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/nfc/llcp_core.c

index f60e424e060764916b6bd37e117c22ddea1b00ea..6705bb895e23930fad97715214d7b6e56c8c2829 100644 (file)
@@ -1636,7 +1636,9 @@ int nfc_llcp_register_device(struct nfc_dev *ndev)
        timer_setup(&local->sdreq_timer, nfc_llcp_sdreq_timer, 0);
        INIT_WORK(&local->sdreq_timeout_work, nfc_llcp_sdreq_timeout_work);
 
+       spin_lock(&llcp_devices_lock);
        list_add(&local->list, &llcp_devices);
+       spin_unlock(&llcp_devices_lock);
 
        return 0;
 }