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,
Shubham Antil <shubham@octane.security>
Subject: [PATCH net v9 2/2] nfc: nci: uart: serialize driver selection
Date: Mon, 30 Nov 2026 09:30:45 +0530 [thread overview]
Message-ID: <20261130040045.41928-3-shubham@octane.security> (raw)
In-Reply-To: <20261130040045.41928-1-shubham@octane.security>
NCIUARTSETDRIVER assumes that tty->disc_data remains NULL until a
transport has been selected. Two concurrent callers can therefore both
allocate and register an NCI device for the same line discipline.
Serialize the allocate, open, and publish sequence with a sleepable mutex.
Recheck tty->disc_data while holding the mutex and keep publication after
transport open succeeds, so a failed selection remains retryable without
exposing a partially initialized context.
Discovered during an AI-assisted source audit using OpenAI Codex,
gpt-5.6-sol. Patch development and test planning used the same assistant.
Confirmed with a pty-backed user-space NCI controller and concurrent
NCIUARTSETDRIVER ioctls.
Fixes: 9961127d4bce ("NFC: nci: add generic uart support")
Assisted-by: LLM (OpenAI Codex, gpt-5.6-sol)
Signed-off-by: Shubham Antil <shubham@octane.security>
---
net/nfc/nci/uart.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c
index ee3d26ee6..bc2016e62 100644
--- a/net/nfc/nci/uart.c
+++ b/net/nfc/nci/uart.c
@@ -37,6 +37,7 @@
static struct nci_uart *nci_uart_drivers[NCI_UART_DRIVER_MAX];
static DEFINE_MUTEX(nci_uart_drivers_lock);
+static DEFINE_MUTEX(nci_uart_selection_lock);
static inline struct sk_buff *nci_uart_dequeue(struct nci_uart *nu)
{
@@ -331,16 +332,17 @@ static void nci_uart_tty_receive(struct tty_struct *tty, const u8 *data,
static int nci_uart_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
unsigned long arg)
{
- struct nci_uart *nu = tty->disc_data;
int err = 0;
switch (cmd) {
case NCIUARTSETDRIVER:
- if (!nu)
- return nci_uart_set_driver(tty, (unsigned int)arg);
+ mutex_lock(&nci_uart_selection_lock);
+ if (tty->disc_data)
+ err = -EBUSY;
else
- return -EBUSY;
- break;
+ err = nci_uart_set_driver(tty, (unsigned int)arg);
+ mutex_unlock(&nci_uart_selection_lock);
+ return err;
default:
err = n_tty_ioctl_helper(tty, cmd, arg);
break;
--
2.54.0
next prev parent reply other threads:[~2026-11-30 4:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 4:00 [PATCH net v9 0/2] nfc: nci: uart: split driver selection fixes Shubham Antil
2026-11-30 4:00 ` [PATCH net v9 1/2] nfc: nci: uart: protect the driver registry Shubham Antil
2026-11-30 4:00 ` Shubham Antil [this message]
2026-11-30 4:03 ` [PATCH net v9 0/2] nfc: nci: uart: split driver selection fixes netdev-bot+sinfo
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=20261130040045.41928-3-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