From: David Laight <david.laight.linux@gmail.com>
To: Runyu Xiao <runyu.xiao@seu.edu.cn>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
netdev@vger.kernel.org, Samuel Ortiz <sameo@linux.intel.com>,
Christophe Ricard <christophe.ricard@gmail.com>,
linux-kernel@vger.kernel.org, Jianhao Xu <jianhao.xu@seu.edu.cn>,
stable@vger.kernel.org
Subject: Re: [PATCH net] nfc: st-nci: use unaligned accessors for frame length
Date: Sat, 20 Jun 2026 10:29:18 +0100 [thread overview]
Message-ID: <20260620102918.7f3e0eb9@pumpkin> (raw)
In-Reply-To: <20260620090536.1701282-1-runyu.xiao@seu.edu.cn>
On Sat, 20 Jun 2026 17:05:36 +0800
Runyu Xiao <runyu.xiao@seu.edu.cn> wrote:
> The ST NCI I2C and SPI transports parse a frame length from bytes
> received from the controller. Both paths first read the frame header into
> a local u8 buffer and then cast buf + 2 to __be16 * before converting it
> from big endian.
Then align the local buffer.
David
>
> These are transport byte buffers, not __be16 objects. Use
> get_unaligned_be16() for the NCI frame length field in both the I2C and
> SPI transports.
>
> This issue was detected by our static analysis tool and confirmed by
> manual audit. A focused UBSAN alignment validation kept the original
> access shape, be16_to_cpu(*(__be16 *)(buf + 2)), and ran it on an NCI
> frame byte buffer with buf + 2 at an odd address. UBSAN reported a
> misaligned-access load of type '__be16', and the trace contained
> st_nci_i2c_read().
>
> The driver has the same source-level issue: the transport helpers fill
> u8 buffers, and the length checks only prove that the bytes are present.
> They do not establish a __be16 object at buf + 2 or a 2-byte alignment
> guarantee before the typed load.
>
> Fixes: ed06aeefdac3 ("nfc: st-nci: Rename st21nfcb to st-nci")
> Fixes: 2bc4d4f8c8f3 ("nfc: st-nci: Add spi phy support for st21nfcb")
> Cc: stable@vger.kernel.org
> Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
> ---
> drivers/nfc/st-nci/i2c.c | 3 ++-
> drivers/nfc/st-nci/spi.c | 3 ++-
> 2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
> index 9ae839a6f5cc..29fdb4ae56e0 100644
> --- a/drivers/nfc/st-nci/i2c.c
> +++ b/drivers/nfc/st-nci/i2c.c
> @@ -14,6 +14,7 @@
> #include <linux/delay.h>
> #include <linux/nfc.h>
> #include <linux/of.h>
> +#include <linux/unaligned.h>
>
> #include "st-nci.h"
>
> @@ -120,7 +121,7 @@ static int st_nci_i2c_read(struct st_nci_i2c_phy *phy,
> if (r != ST_NCI_I2C_MIN_SIZE)
> return -EREMOTEIO;
>
> - len = be16_to_cpu(*(__be16 *) (buf + 2));
> + len = get_unaligned_be16(buf + 2);
> if (len > ST_NCI_I2C_MAX_SIZE) {
> nfc_err(&client->dev, "invalid frame len\n");
> return -EBADMSG;
> diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
> index 169eacc0a32a..1326c20e43fc 100644
> --- a/drivers/nfc/st-nci/spi.c
> +++ b/drivers/nfc/st-nci/spi.c
> @@ -14,6 +14,7 @@
> #include <linux/delay.h>
> #include <linux/nfc.h>
> #include <linux/of.h>
> +#include <linux/unaligned.h>
> #include <net/nfc/nci.h>
>
> #include "st-nci.h"
> @@ -130,7 +131,7 @@ static int st_nci_spi_read(struct st_nci_spi_phy *phy,
> if (r < 0)
> return -EREMOTEIO;
>
> - len = be16_to_cpu(*(__be16 *) (buf + 2));
> + len = get_unaligned_be16(buf + 2);
> if (len > ST_NCI_SPI_MAX_SIZE) {
> nfc_err(&dev->dev, "invalid frame len\n");
> phy->ndlc->hard_fault = 1;
prev parent reply other threads:[~2026-06-20 9:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-20 9:05 [PATCH net] nfc: st-nci: use unaligned accessors for frame length Runyu Xiao
2026-06-20 9:29 ` David Laight [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=20260620102918.7f3e0eb9@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=christophe.ricard@gmail.com \
--cc=jianhao.xu@seu.edu.cn \
--cc=krzk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=runyu.xiao@seu.edu.cn \
--cc=sameo@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.