From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 EC3DB346A0D for ; Wed, 17 Dec 2025 08:11:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765959092; cv=none; b=UAgVwgvAKn1gVzwpOkWWEmN0/E+rRufAscDT/eoz7iUy/+MmS4WayRImCZHt+Tj12KqzkfY6PTkqOkEQCma30YtQwOIAgUQERxO4CD7ag/J2SgKCFeeAeXhs3evsgCsSWK9lEM9SXRxQONIZf+4yAf3Gs7bXHom1KIi1W5lrl7Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765959092; c=relaxed/simple; bh=VP4slbkuMNhOyt7ePv5O1rMZejitKV/WZW9BwIPLmig=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Yhpz4wsDsxuuhTgKFzLgK/TotwSFcc4B36fe0I4H3R6gmV+2Nw+mBwsh1zxPzEljbTrQibYT8va6sCBbAfUX8i+M5e4XJYZJYcElhWiOCfm213sMWAOn/ukYBrJpv5KQyuOUMAoqCb2Cas7CBBsRMwrJ2SPDyURuzSjA4+af2YU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=i7ccWfGx; arc=none smtp.client-ip=209.85.128.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i7ccWfGx" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-78c64370309so48355847b3.2 for ; Wed, 17 Dec 2025 00:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765959090; x=1766563890; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=se9qlqaNK4Zda1UW6fV88JOcpay1tuUGGKJbYPeSY4k=; b=i7ccWfGxlyRD8ejoTUws8FtWTYApuWenulgaMNrUAFo2VR5dJl7WhveRpslZhYmDOo mpWt/qd2GpsQn9JBilp3DWKJR/9Mo8BvtjT1937vpbaav+BBmcd5EW5RnkEvyHpUG/jK wX5VgKoqjfRjQ7CmC7PcxKzlRpktP98KKZZfjQCAlGzDFcqSPQUmDfYVAbxsAQ1mYo3w molzx0IS3WtLe1Xasa1DWb1cCfV5lz5D0ZB1TMRcgrVYfzxXd5C1hu1xCtEgwYuYbCAN zoMbVcnf/fwzbpL8Ymf7hJkzeBFCoHEnQ9OU/uoUBLdlYv9d19arimz28jOovUztm376 2xAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765959090; x=1766563890; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=se9qlqaNK4Zda1UW6fV88JOcpay1tuUGGKJbYPeSY4k=; b=cfWfuXakoOv6ZyrDSyIs/EyC/1PZOc9VjJZnehXJtZyyLlqlWIeaH99sdAF7RqEkY+ bqtNnNHlJnft+1qcbMx57RD+rRqYNvNJ8XfpBctrI/DoavfgAfbXxf7s0dD0A+rRGPfS qftEEm24aOKJuLTTePGD4U5e/FSORJvfVmgU3YfKQ7yChjxzkkGz8Oet5KuCtxn6ztu9 2P3LqYzK/2vGQJOPsb00hvmUpxc8kqtPMD5gJhkM60/FFdquUQQS6uDnQy1rSnmzaGJs uGyyF/tNUXjsA2tKbH7Xp6bY2Lxl3OdXENrcB1wUIH34kQy0Nc7gEeUjz3C1C9+3P3tb vOwg== X-Forwarded-Encrypted: i=1; AJvYcCVg6xT7skce4R54bfU+UEYr4Vo1gOqpI14NLFPwKt/FnqZniszu8rmnwhEKGHYURx0apA3QL1Fehivq8hg=@vger.kernel.org X-Gm-Message-State: AOJu0YxiUyzz3bqK8FBpz//OuSEr6NWrEScw+SWc5A1H6IKZqrqv45mF uLVjBXlTvOnloOx+5kyzEn+r4dEa56invKSsMBupujzKjoeAD8adgu69O96LP79x2TJsX0U0LNY T9DHcmm+KN2HF6Xkte/GGq1pjCGeW8xc= X-Gm-Gg: AY/fxX5zbL8FI5Nnkbb58R1kBSQ9dYqZsNEneeSF11gV0ZzqSSkGso1c15Cnx8TAJqP Wn2ZkkMSFa2/c0xUgxTBXlsgBhfyTy+U6B+0LJNUqrN2Uw2v3Fc3LQaBG5Ob1TqxJ3gSrYV6dvc eK0RTIpDIK15Vam6Aol4T9fcqWXE4y+y78jVDoI6fypoFRhJvHsgCiTAgWlJm+12K/Y4THg6lEa Lj4toH2NxZmwgf1lNjKv4H8xlKXnhO4D+NDjo3iBPp4ND67/4noxZum5k7XAE+nreOh6eQt8H9z sHh3AGv1R7CnDRAxiLL9HOUfhj21F6rGwV2lXsuz6eOdRbWYqMIZtmZ2B8Ea X-Google-Smtp-Source: AGHT+IHwFE8LQ70NmhySNinUszjIWXXVa0CUscfFXT8ZG0i+4lpei3MD7y7T54rfBzISK24Y6TP+EtGMOB8be1M0sF4= X-Received: by 2002:a05:690c:4b0e:b0:787:c9a1:13f0 with SMTP id 00721157ae682-78e66ce44demr144008317b3.8.1765959089932; Wed, 17 Dec 2025 00:11:29 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20251217054908.178907-1-kartikey406@gmail.com> In-Reply-To: From: Deepanshu Kartikey Date: Wed, 17 Dec 2025 13:41:18 +0530 X-Gm-Features: AQt7F2oPGgilSXG77WtNwldSwnm35r6WedpdHH_Og8vUH0XFja7XcEW0kty3y2k Message-ID: Subject: Re: [PATCH] net: nfc: fix deadlock between nfc_unregister_device and rfkill_fop_write To: Krzysztof Kozlowski Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+4ef89409a235d804c6c2@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Dec 17, 2025 at 1:01=E2=80=AFPM Krzysztof Kozlowski wrote: > > 1. So your code allows concurrent thread nfc_rfkill_set_block() to be > called at this spot > 2. Original thread of unregistering will shortly later call > device_del(), which goes through lock+kill+unlock, > 3. Then the concurrent thread proceeds to device_lock() and all other > things with freed device. > > You just replaced one issue with another issue, right? > Hi Krzysztof, Thanks for the review. Regarding the UAF concern: The callback nfc_rfkill_set_block() is invoked from rfkill_fop_write() which holds rfkill_global_mutex for the entire operation: rfkill_fop_write(): mutex_lock(&rfkill_global_mutex); list_for_each_entry(rfkill, &rfkill_list, node) { rfkill_set_block(rfkill, ev.soft); } mutex_unlock(&rfkill_global_mutex); rfkill_set_block() calls ops->set_block() (i.e., nfc_rfkill_set_block) without releasing rfkill_global_mutex. Since rfkill_unregister() also acquires rfkill_global_mutex: void rfkill_unregister(struct rfkill *rfkill) { ... mutex_lock(&rfkill_global_mutex); rfkill_send_events(rfkill, RFKILL_OP_DEL); list_del_init(&rfkill->node); ... mutex_unlock(&rfkill_global_mutex); } The unregister path cannot proceed past rfkill_unregister() until any ongoing callback completes. Since device_del() is called after rfkill_unregister() returns, no UAF should be possible. Additionally, if nfc_dev_down() runs after we set shutting_down =3D true, it will see the flag and bail out early with -ENODEV without accessing device internals. Regarding nfc_register_device(): The same lock ordering exists there (device_lock -> rfkill_global_mutex via rfkill_register), but during registration the device is not yet visible to other subsystems, so no concurrent rfkill operations can occur. The ABBA pattern there should not cause an actual deadlock. I will send a v2 addressing: - Adding Fixes and Cc: stable tags - Keeping the blank line after variable declaration Thanks, Deepanshu