From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796026015; b=hZOr6eV2OXWpD4P/2XkBHBQ0HaGRB+q6nvQc07U5IcZHtJXnk37FBKewdTKUVQqqGsSt 6ZAxbwT2CH5WArw2OI7939BfMho8u1mf1FAau9FBVl7cYLMYxTYVwipUqd+nTReWLTa0t 86GymFNE432Jer0AByxVLCBuNtdYb1fXxgP2ROZ7fBMWf9ov/sAS7fHmGO+Y//KqMCrUI vltR/e1WC9MNc8cwlRaAJvzy+lLShHnxDxpRePRwqqCAShM65/8x0nQDu4Nu7rKtjkGxk Za2NEyAx/8xhHeqxdAyZfdx2+CxMlm060MXl5GW4AhxoVokTGkEJcSt9r+ZENLUqKWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796026015; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=zOg0HJHTGbgVRzzg7c+ml0u9dUwZ/X+8tgQScwPsd0A=; b=zX4qNvOxjZV3NmKSsZtouyBFP75sFnWEjBOj4HHwpyw2TTb1RPcegQRYjVzUqkmcUMX3 Q1IB50DIdoZ2hvnqGUKLU0y8H/skyR4UaJ6XimLhYTgmrHv0rP5Tw73C/PSfUryY29gdO I1dBNzeGkjGxhXzzsrkeuWS5vP9FPCmdC18AqgRp1GKhTBpI82+oGc7n7I0gOBBbveENG mp5/0oVFDnx69AyIhQh0tFZOJjc7vBZe2WbDuLoagshlycwrPNnb45nJyphZSmehnhyl3 rmlpIZecSVRmjNpGIV34c6Hw1EM8FSdDuBo5yH35P4/wgagxa07ZCHfvftuAuAQzv0A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=octane.security; spf=pass smtp.mailfrom=octane.security; dkim=pass header.d=octane.security header.i=@octane.security header.a=rsa-sha256 header.s=google header.b="P//d54/b"; arc=none smtp.remote-ip=74.125.82.45 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CD72606A325 for ; Mon, 30 Nov 2026 08:06:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9CD72606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=octane.security Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=octane.security Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=octane.security header.i=@octane.security header.a=rsa-sha256 header.s=google header.b=P//d54/b Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-1b3ada81853so10180896c88.0 for ; Mon, 30 Nov 2026 00:06:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=octane.security; s=google; t=1796026014; x=1796630814; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zOg0HJHTGbgVRzzg7c+ml0u9dUwZ/X+8tgQScwPsd0A=; b=P//d54/briGvD21obmHNBHHt9xvQnlfySJhWxMpugtLyVxr4R3aYiCD28VmK7Cia+y h4f7C02Ye5BH+i7viIeH83sdAPw3DovfT5IDylzF5hppVAov6774CVLwfgSlJYFj7N75 8zxlylFLvHhSNGqyU+F7E3bNCTsGFNDPJ7h51HbcrG29OWFVWnLBShr7sdo5gXk4hf0h DUfYW4FpsHLrtHc7OpS5tcvv/HFY9sEcx0q/hzR+7+ETqH1I1ThcprXe+rcTpAREBCu+ ExYEcCvmdnfOI+xScj/WyeV5fKtumbAL0qzqolu98oplI/HZW2GHapDjuqQVgwWU3z9E 70tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796026014; x=1796630814; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=zOg0HJHTGbgVRzzg7c+ml0u9dUwZ/X+8tgQScwPsd0A=; b=u11OEOO7YZyhP6ccjWoHdphgJKGVM8VSYkXu9uwPM9fZIQwESRirQ0qp+0v1YIHAd7 2mhX2Rwclo0WU5ttqHcJfd2Yson4snn1/2PHPrTecoQikUIyAJLnxBPtgy7oyU0cPiUJ z9i/IxYZEEeEbvgzEEzSe+H+hBGmYa/hO+pypysuHitzeW+P/3dICTqkXXgKeX9LjpCo lX8pcULE4nRqVCcGRHfoTJB0j6NvYnERMUCEszu1cMQDAivhVJICaGt6CRrZ6hINcSq9 y3afozQoV5zgmJVBNKw3G3IkHxmIp8+WIfDLseMsn9wXku6IDiV9Bu4Lsq3f06hyMU0D bkVA== X-Forwarded-Encrypted: i=1; AL+hErHqdci9AW1IDwmPh+DIbypdfFgEd9jbonWXbBK6pLTKihHxnmHEiEC4nYauwvJryF7Y1IvuNKYlx6AZAOI=@lists.linux.dev X-Gm-Message-State: APuU4Z917aL3VYizuZqwYf5NixHhFjIvcSCxNc75wvgIout5vVkIqSzN JpT6+m10kYl23PtSH/ROYu4FVMvdWdS+CggJKPwr+PEf4yBFrc3vtZzyzF/uOj8q/hU= X-Gm-Gg: AZFdTZdPW+HvACljBkzOSY9yJB619IUiNHOwkAKMQ5TnQf/rX6P9W9QyutivTH4a1Zo osqhvBhKvSTbzQ5OxbLUnWxu5QiVVMfvp1yFp2V1+vFq6uNBb23lqMNFWWo843lHLTEDw1T5J0l DRxuIhAEhoj3EbRBxjaiPBYhO7WaZSKyqw6S1io9ofL+CMVtp/AZKZgDgt61ti2r3dCFWGOipB9 BvbUrfQZhgzk+xfey4odrw5YJCpgQyLKrnSmKEo93LRnhzIqGigDOU4bAeckyPUls6HvDnu0DuJ G3Jt/Rv8NXThK4Txfe+/RckWbL6BKW+niV8I1CJa9E30DxpSHAffvGqjDftbncUeyx41XneyTMm 8XDmE1CY0TtufPtjLCj87L2fOqAkvnEluOvp7AnSRG87kH+i/BdtLuLRTfoLo/KooOb+tQsobEL RX0t4iacA1tPVpKATKHlMk4ndGrdxvoM2XdZvg6DD6pfv9QTNU4hCPSsD/oQgThlyNmC4B5PdhF dkCodnst32qGuvBDTDDij9FrYS3r9gObt+j43ikxyuP88ZErsLSYiCsXcDlWbCWnmDr/KZh73QZ L2URi3CHevI3GSOBtEuLI8b8VUgDg6aoh2cIF+DTW5aUOriOdOMuwt5JUG6Ci7TMycbt4IPVMh9 BkayPsIYJ4CC15pqDlToMGLVanm0fEj2v3QxsFGc2L044RsoZvqN1OQ3Sik3LXq01nSytug== X-Received: by 2002:a05:701a:ccda:10b0:1b5:7477:ff7d with SMTP id a92af1059eb24-1b574780064mr23174335c88.15.1796026013604; Mon, 30 Nov 2026 00:06:53 -0800 (PST) Received: from localhost.localdomain ([103.47.169.47]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b556829d31sm123533184c88.9.2026.11.30.00.06.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Nov 2026 00:06:53 -0800 (PST) From: Shubham Antil To: netdev@vger.kernel.org Cc: Simon Horman , gio@octane.security, David Heidelberg , oe-linux-nfc@lists.linux.dev, stable@vger.kernel.org Subject: [PATCH net v9 1/2] nfc: annotate firmware download state accesses Date: Mon, 30 Nov 2026 13:36:44 +0530 Message-ID: <20261130080645.60464-2-shubham@octane.security> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261130080645.60464-1-shubham@octane.security> References: <20261130080645.60464-1-shubham@octane.security> X-Mailing-List: oe-linux-nfc@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The firmware-download state is written from asynchronous completion and read from receive and transmit callbacks without a common lock. Mark every lockless access with READ_ONCE() or WRITE_ONCE() so the intended one-copy communication is explicit and data-race tooling does not treat the accesses as unrelated plain loads and stores. This is a preparatory change for rejecting overlapping firmware downloads; it does not change the state machine. Discovered during an AI-assisted source audit using OpenAI Codex, gpt-5.6-sol. The overlapping-download condition was reproduced at runtime by issuing two NFC_CMD_FW_DOWNLOAD requests to a pty-backed controller. No production incident or pre-fix kernel warning was observed. Patch development and test planning used the same assistant. Validated by inspecting every access to fw_download_in_progress and built with W=1 and sparse. The complete series was exercised with a pty-backed controller under KASAN, UBSAN, lockdep, and strict KCSAN. No physical NFC controller was available. Fixes: 9674da8759df ("NFC: Add firmware upload netlink command") Cc: stable@vger.kernel.org Assisted-by: LLM (OpenAI Codex, gpt-5.6-sol) Signed-off-by: Shubham Antil --- drivers/nfc/nfcmrvl/main.c | 2 +- drivers/nfc/nfcmrvl/uart.c | 4 ++-- net/nfc/core.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c index 6efa83219..b9b66127f 100644 --- a/drivers/nfc/nfcmrvl/main.c +++ b/drivers/nfc/nfcmrvl/main.c @@ -205,7 +205,7 @@ int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb) } } - if (priv->ndev->nfc_dev->fw_download_in_progress) { + if (READ_ONCE(priv->ndev->nfc_dev->fw_download_in_progress)) { nfcmrvl_fw_dnld_recv_frame(priv, skb); return 0; } diff --git a/drivers/nfc/nfcmrvl/uart.c b/drivers/nfc/nfcmrvl/uart.c index 9aedd1687..4b989fc4e 100644 --- a/drivers/nfc/nfcmrvl/uart.c +++ b/drivers/nfc/nfcmrvl/uart.c @@ -159,7 +159,7 @@ static void nfcmrvl_nci_uart_tx_start(struct nci_uart *nu) { struct nfcmrvl_private *priv = (struct nfcmrvl_private *)nu->drv_data; - if (priv->ndev->nfc_dev->fw_download_in_progress) + if (READ_ONCE(priv->ndev->nfc_dev->fw_download_in_progress)) return; /* Remove BREAK to wake up the NFCC */ @@ -173,7 +173,7 @@ static void nfcmrvl_nci_uart_tx_done(struct nci_uart *nu) { struct nfcmrvl_private *priv = (struct nfcmrvl_private *)nu->drv_data; - if (priv->ndev->nfc_dev->fw_download_in_progress) + if (READ_ONCE(priv->ndev->nfc_dev->fw_download_in_progress)) return; /* diff --git a/net/nfc/core.c b/net/nfc/core.c index f52166929..91b3274da 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c @@ -53,10 +53,10 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) goto error; } - dev->fw_download_in_progress = true; + WRITE_ONCE(dev->fw_download_in_progress, true); rc = dev->ops->fw_download(dev, firmware_name); if (rc) - dev->fw_download_in_progress = false; + WRITE_ONCE(dev->fw_download_in_progress, false); error: device_unlock(&dev->dev); @@ -73,7 +73,7 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) int nfc_fw_download_done(struct nfc_dev *dev, const char *firmware_name, u32 result) { - dev->fw_download_in_progress = false; + WRITE_ONCE(dev->fw_download_in_progress, false); return nfc_genl_fw_download_done(dev, firmware_name, result); } @@ -104,7 +104,7 @@ int nfc_dev_up(struct nfc_dev *dev) goto error; } - if (dev->fw_download_in_progress) { + if (READ_ONCE(dev->fw_download_in_progress)) { rc = -EBUSY; goto error; } base-commit: 30c71476d842b094651bd7712f6c8ee8716147d0 -- 2.54.0