From nobody Thu Dec 18 23:40:13 2025 Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 954311C695 for ; Wed, 17 Dec 2025 05:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765948630; cv=none; b=F+1CboTUJU31dB/cefXZk8eeIjplrm44xivdelmK+f0s4bgAkIEsbemQSqj1thOr32cAu+HSlwVN/zt11zxeaVEz2b8KT4hdlerCSm0sIq6+6ugIlnDTkuMfIQrjbHpsWkEedm5QcUUqIVy8iVnR27U02KR1fAAP70H6RAIs2Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765948630; c=relaxed/simple; bh=fRsNYsGgcG4LKdvOhmTbp9mmgNCiL17PyYp90xZc114=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=f9nzNEjIXudeBRfFcnSfxkBjD7qW9BJvlw1rRTpiVVYWXuENlCt7aI9jCe5DE4y21+hVvd66emQtXtheMFWe67EFAEGNVpqUMlPXIb4YxwtKoP0S57WKvUWkwGtuEuOtsWQdRDCxwkqQMk2qpMREFaVkvKWvIokwdhlU1BCc8TM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.210.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-7c702347c6eso6594209a34.1 for ; Tue, 16 Dec 2025 21:17:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765948627; x=1766553427; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=79uSc8uAqujx0FHxlvBHK7tV+Eu5RlS6apJqdSKNADQ=; b=vQLGr56CaUPJOBnLWLAqbcdHRFqWGmE8FwmfrdwEpsSFXPzdxPVoXnMwZ145UDcMa6 YDXTVqv8yPAXm1hgWe7VjoDrZin/drF8O5CeFC9cI34FMDgBGjII6c6PpagGk9J6N8xu NKYjrp2efKPnnxzHTbh9hd7i0lUgfWhVzeTQkqNVzP82RI2slg1h0NjI7HeFWTlXuMfT f5NBr3kPJS2MOVcKOSOe57WsuCu+PLKfKNtRC6jc0vMw8hxyXg2S7xvLh+JDJIRPReRd Uz+nIHK8QMq/13EpC06r0DhJ4DVA+Y0e+3m2UdmGcNybcfaHiOLo+wOafMnH23GhmPAl MzPQ== X-Gm-Message-State: AOJu0YxN9YRNpg7wzj+hKTa7cwbrN0KPV31lDgEmKwVmWA48YxiVwCjG P5JUDNkZM8qq2KWPr8sRovEJmt/npRycgvqP8ARtC9RRIWznvltg8XDcijQlGgKbIPKOLEJNhc6 Dqp4xWPnIwZ4mv6r14ksQ0FYifIaYEkAXkV3SswKc+TCAkfRHw+mhytHzD10= X-Google-Smtp-Source: AGHT+IG6rTTaLSNT8rW7/C5s20ANKE0gF1X0F/raDpiK+1+tnXpudwa4N4nWGJOQC4z4UqStc8gTfikXgbohrAnpeQrcMe2pP5dM Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:609:b0:659:9a49:8e49 with SMTP id 006d021491bc7-65b451b0365mr6775150eaf.25.1765948627409; Tue, 16 Dec 2025 21:17:07 -0800 (PST) Date: Tue, 16 Dec 2025 21:17:07 -0800 In-Reply-To: <694001b8.a70a0220.33cd7b.00fe.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69423cd3.a70a0220.207337.0032.GAE@google.com> Subject: Forwarded: [PATCH] net: nfc: fix deadlock between nfc_unregister_device and rfkill_fop_write From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] net: nfc: fix deadlock between nfc_unregister_device and r= fkill_fop_write Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git= master A deadlock can occur between nfc_unregister_device() and rfkill_fop_write() due to lock ordering inversion between device_lock and rfkill_global_mutex. The problematic lock order is: Thread A (rfkill_fop_write): rfkill_fop_write() mutex_lock(&rfkill_global_mutex) rfkill_set_block() nfc_rfkill_set_block() nfc_dev_down() device_lock(&dev->dev) <- waits for device_lock Thread B (nfc_unregister_device): nfc_unregister_device() device_lock(&dev->dev) rfkill_unregister() mutex_lock(&rfkill_global_mutex) <- waits for rfkill_global_mutex This creates a classic ABBA deadlock scenario. Fix this by moving rfkill_unregister() and rfkill_destroy() outside the device_lock critical section. To ensure safety, set shutting_down flag first and store rfkill pointer in a local variable before releasing the lock. The shutting_down flag ensures that nfc_dev_down() and nfc_dev_up() will bail out early if called during device unregistration. Reported-by: syzbot+4ef89409a235d804c6c2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D4ef89409a235d804c6c2 Signed-off-by: Deepanshu Kartikey --- net/nfc/core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/nfc/core.c b/net/nfc/core.c index ae1c842f9c64..201d2b95432b 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c @@ -1154,7 +1154,7 @@ EXPORT_SYMBOL(nfc_register_device); void nfc_unregister_device(struct nfc_dev *dev) { int rc; - + struct rfkill *rfk =3D NULL; pr_debug("dev_name=3D%s\n", dev_name(&dev->dev)); =20 rc =3D nfc_genl_device_removed(dev); @@ -1164,13 +1164,17 @@ void nfc_unregister_device(struct nfc_dev *dev) =20 device_lock(&dev->dev); if (dev->rfkill) { - rfkill_unregister(dev->rfkill); - rfkill_destroy(dev->rfkill); + rfk =3D dev->rfkill; dev->rfkill =3D NULL; } dev->shutting_down =3D true; device_unlock(&dev->dev); =20 + if (rfk) { + rfkill_unregister(rfk); + rfkill_destroy(rfk); + } + if (dev->ops->check_presence) { timer_delete_sync(&dev->check_pres_timer); cancel_work_sync(&dev->check_pres_work); --=20 2.43.0