From: Simon Horman <horms@kernel.org>
To: Yuchao Zhang <ndaugoing@gmail.com>
Cc: David Heidelberg <david@ixit.cz>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v3] nfc: nci: ignore unexpected CORE_RESET_NTF and CORE_RESET_RSP
Date: Thu, 1 Oct 2026 11:43:52 +0100 [thread overview]
Message-ID: <20261001104352.GZ13925@horms.kernel.org> (raw)
In-Reply-To: <20260927132914.24648-1-ndaugoing@gmail.com>
On Sun, Sep 27, 2026 at 09:29:14PM +0800, Yuchao Zhang wrote:
> Commit bcd684aace34 ("net/nfc/nci: Support NCI 2.x initial sequence")
> added handling of CORE_RESET_NTF in nci_core_reset_ntf_packet(). When
> received, it updates ndev->nci_ver, ndev->manufact_id, and
> ndev->manufact_specific_info, and calls nci_req_complete(ndev,
> NCI_STATUS_OK) to finish the pending reset request.
>
> However, unlike other notification handlers in ntf.c (which validate
> ndev->state before completing requests), nci_core_reset_ntf_packet()
> does not check whether a core reset request is actually pending.
> If an unsolicited or delayed CORE_RESET_NTF arrives (e.g. after a reset
> command times out or from a misbehaving NFCC), it unconditionally:
> 1. Completes whatever request is currently in-flight (such as CORE_INIT,
> RF_DISCOVER, or CONN_CREATE) with NCI_STATUS_OK, leading to kernel
> state desynchronization.
> 2. Overwrites ndev->nci_ver and manufacturer info. Because
> ndev->nci_ver is used as a selector for subsequent packet formats
> and parsers (e.g., in nci_open_device() and nci_core_init_rsp_packet()),
> unexpectedly modifying it can cause protocol format confusion.
>
> A similar issue exists in nci_core_reset_rsp_packet(): an unexpected or
> delayed response packet can prematurely complete an unrelated in-flight
> request.
>
> Fix this by ensuring CORE_RESET_NTF and CORE_RESET_RSP are only processed
> by the core layer when a reset command is actively awaiting them:
> - Set NCI_RESET_PENDING in nci_reset_req() when sending CORE_RESET_CMD.
> - In nci_core_reset_rsp_packet(), ignore the response if NCI_RESET_PENDING
> is not set. If set, atomically clear the flag and complete the request
> on failure or for NCI 1.x (checking skb->len >= sizeof(*rsp)).
> - In __nci_request(), ensure NCI_RESET_PENDING is cleared upon request
> completion, cancellation, or timeout.
> - In nci_core_reset_ntf_packet(), fail any in-flight reset request if the
> controller reports an unrecoverable error (0x00), and only process
> command-triggered notifications (0x02). Non-command triggers (e.g.
> power-on 0x01 or proprietary triggers) and unexpected notifications
> return 0 without modifying core state, ensuring driver-specific
> notification handlers (such as fdp firmware patch handling) still
> receive them.
> - In nci_core_reset_ntf_packet(), support notifications shorter than 9
> bytes (e.g. NCI 2.0 frames with manufacturer_specific_len == 0),
> validating the fixed header length and safely bounding
> manufact_specific_info reads.
>
> Fixes: bcd684aace34 ("net/nfc/nci: Support NCI 2.x initial sequence")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yuchao Zhang <ndaugoing@gmail.com>
> ---
> v3:
> - In nci_core_reset_ntf_packet(), do not reject notifications shorter than
> 9 bytes with -EINVAL; instead allow valid short frames (e.g. 2-byte NCI 1.x
> or 5-byte NCI 2.0 with manufacturer_specific_len == 0), safely cap field
> reads, and return 0 so driver-registered hooks (such as fdp firmware
> patching) are not skipped (per Sashiko AI).
> - Fix trigger semantics: in NCI, CORE_RESET_CMD trigger is 0x02
> (NCI_RESET_TRIGGER_RESET_CMD). If controller reports an unrecoverable error
> (0x00, NCI_RESET_TRIGGER_ERROR) while reset is pending, fail the request
> instead of completing with OK; ignore power-on (0x01) and proprietary
> triggers at core layer (per Sashiko AI).
> - In nci_core_reset_rsp_packet(), use test_and_clear_bit(NCI_RESET_PENDING)
> upon completing the request to consume the flag atomically (per Sashiko AI).
> - Link to v2: https://lore.kernel.org/netdev/20260922102144.39689-1-ndaugoing@gmail.com/
>
> v2:
> - Do not abort the notification pipeline on unexpected CORE_RESET_NTF (return 0
> instead of -EINVAL), preserving driver-level hooks (e.g. fdp firmware
> patching) per Simon Horman.
> - Skip power-on notifications (trigger 0x01, identical in NCI 1.0 and 2.0)
> while gating both NCI 1.0 (0x00) and NCI 2.0 (0x02) command-triggered resets
> on NCI_RESET_PENDING alone.
> - Check NCI_RESET_PENDING in nci_core_reset_rsp_packet() to avoid completing
> unrelated requests on unexpected responses.
> - Explicitly check skb->len >= sizeof(*rsp) in nci_core_reset_rsp_packet()
> for NCI 1.x handling.
> - Link to v1: https://lore.kernel.org/netdev/20260918013337.82214-1-ndaugoing@gmail.com/
Reviewed-by: Simon Horman <horms@kernel.org>
prev parent reply other threads:[~2026-10-01 10:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-27 13:29 Yuchao Zhang
2026-10-01 10:43 ` Simon Horman [this message]
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=20261001104352.GZ13925@horms.kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=david@ixit.cz \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ndaugoing@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®