Netdev List
 help / color / mirror / Atom feed
From: Shubham Antil <shubham@octane.security>
To: netdev@vger.kernel.org
Cc: Simon Horman <horms@kernel.org>,
	gio@octane.security, David Heidelberg <david@ixit.cz>,
	oe-linux-nfc@lists.linux.dev
Subject: [PATCH net v9 1/4] nfc: keep devices shut down until registration completes
Date: Mon, 30 Nov 2026 14:44:53 +0530	[thread overview]
Message-ID: <20261130091456.62379-2-shubham@octane.security> (raw)
In-Reply-To: <20261130091456.62379-1-shubham@octane.security>

nfc_allocate_device() leaves shutting_down clear until unregister begins.
A driver which publishes transport callbacks during registration can
therefore receive an early request before registration has completed.

Initialize the device in the shutting-down state, use one-copy stores
when registration opens and closes admission, and only admit requests
after the device has been fully registered.

Discovered during an AI-assisted source audit using OpenAI Codex,
gpt-5.6-sol. The early-publication condition was reproduced by racing
NFC_CMD_DEV_UP with NCIUARTSETDRIVER on a pty-backed transport. An earlier
high-concurrency pre-fix run also hit a general-protection fault in
nfcmrvl_nci_uart_tx_start() with nu->drv_data still NULL. Patch development
and test planning used the same assistant.
Confirmed with repeated pty-backed NCI UART registration, open, reset, and
hangup cycles. No physical NFC controller was available.

Fixes: 9674da8759df ("NFC: Add firmware upload netlink command")
Assisted-by: LLM (OpenAI Codex, gpt-5.6-sol)
Signed-off-by: Shubham Antil <shubham@octane.security>
---
 net/nfc/core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/nfc/core.c b/net/nfc/core.c
index f52166929..685d1727d 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -1065,6 +1065,9 @@ struct nfc_dev *nfc_allocate_device(const struct nfc_ops *ops,
 	if (!dev)
 		return NULL;
 
+	/* Reject requests until registration has finished. */
+	dev->shutting_down = true;
+
 	rc = ida_alloc(&nfc_index_ida, GFP_KERNEL);
 	if (rc < 0)
 		goto err_free_dev;
@@ -1133,7 +1136,7 @@ int nfc_register_device(struct nfc_dev *dev)
 			dev->rfkill = NULL;
 		}
 	}
-	dev->shutting_down = false;
+	WRITE_ONCE(dev->shutting_down, false);
 	device_unlock(&dev->dev);
 
 	rc = nfc_genl_device_added(dev);
@@ -1167,7 +1170,7 @@ void nfc_unregister_rfkill(struct nfc_dev *dev)
 		rfk = dev->rfkill;
 		dev->rfkill = NULL;
 	}
-	dev->shutting_down = true;
+	WRITE_ONCE(dev->shutting_down, true);
 	device_unlock(&dev->dev);
 
 	if (rfk) {

base-commit: 30c71476d842b094651bd7712f6c8ee8716147d0
prerequisite-patch-id: da5eea669279340f2925f9be0d203fd3bc407cc5
prerequisite-patch-id: 109c531926f84389d8f1d2030160f6113a749142
-- 
2.54.0


  reply	other threads:[~2026-11-30  9:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  9:14 [PATCH net v9 0/4] nfc: nci: uart: split lifecycle teardown fixes Shubham Antil
2026-11-30  9:14 ` Shubham Antil [this message]
2026-11-30  9:14 ` [PATCH net v9 2/4] nfc: nci: coordinate transport shutdown in the core Shubham Antil
2026-11-30  9:14 ` [PATCH net v9 3/4] nfc: nci: uart: quiesce callbacks during teardown Shubham Antil
2026-11-30  9:14 ` [PATCH net v9 4/4] nfc: nfcmrvl: adopt the NCI UART lifecycle helpers Shubham Antil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130091456.62379-2-shubham@octane.security \
    --to=shubham@octane.security \
    --cc=david@ixit.cz \
    --cc=gio@octane.security \
    --cc=horms@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oe-linux-nfc@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox