mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Heidelberg <david@ixit.cz>
To: Tianchu Chen <tianchu.chen@linux.dev>,
	sameo@linux.intel.com, shikha.singh@st.com
Cc: oe-linux-nfc@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nfc: st95hf: validate device-reported response length before reading
Date: Mon, 21 Sep 2026 01:02:29 +0200	[thread overview]
Message-ID: <e026f741-3c19-47b2-b731-f257361e471c@ixit.cz> (raw)
In-Reply-To: <91f49a98dd42655829b7206f0d64cc31ef9c0e95@linux.dev>

On 19/08/2026 16:55, Tianchu Chen wrote:
> From: Tianchu Chen <flynnnchen@tencent.com>
> 
> st95hf_spi_recv_response() reads a 2-byte header from the device,
> derives the total response length from it (up to 1025 bytes via the
> long-frame encoding) and then blindly reads len - 2 more bytes into
> the caller's buffer, whose size it knows nothing about.
> 
> Call sites can be overflowed by a device reporting a large length,
> for example, st95hf_irq_thread_handler() passes the data area of a
> 280-byte skb.
> 
> ST95HF datasheet states "In Reader mode it is possible to receive up to
> 528 bytes of frame data from VICC and TypeB cards", so technically a bogus
> NFC tag may trigger the OOB-write if the card-reader's firmware allows
> large packets.
> 
> Add a buff_len parameter and reject a device-reported length that does
> not fit into the caller's buffer before issuing the second SPI
> transfer. Also modify callers to pass their real buffer sizes.
> 
> Discovered by Atuin - Automated Vulnerability Discovery Engine.
> 
> Fixes: cab47333f0f75 ("NFC: Add STMicroelectronics ST95HF driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Tianchu Chen <flynnnchen@tencent.com>
> ---
>   drivers/nfc/st95hf/core.c | 6 ++++--
>   drivers/nfc/st95hf/spi.c  | 7 ++++++-
>   drivers/nfc/st95hf/spi.h  | 2 +-
>   3 files changed, 11 insertions(+), 4 deletions(-)
> 

Hello Tianchu,

please check and address the Sashiko output.

Thank you
David


[ ... ]
 > @@ -106,6 +106,11 @@ int st95hf_spi_recv_response(struct st95hf_spi_context 
*spicontext,
 >  	else
 >  		len += receivebuff[1];
 >
 > +	if (len > buff_len) {
 > +		mutex_unlock(&spicontext->spi_lock);
 > +		return -E2BIG;
 > +	}
 > +

Does this early return path leave the spi chip select (CS) permanently
asserted?

The first spi transfer uses .cs_change = 1 to keep the chip select active.
Skipping the second transfer would prevent the chip select from being
deasserted, potentially deadlocking the device.

 >  	/* Now make a transfer to read only relevant bytes */
 >  	tx_takedata.rx_buf = &receivebuff[2];
 >  	tx_takedata.len = len - 2;

  reply	other threads:[~2026-09-20 23:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 14:55 Tianchu Chen
2026-09-20 23:02 ` David Heidelberg [this message]
2026-09-23  8:20   ` Tianchu Chen
2026-09-23  8:18 ` [PATCH v2] " Tianchu Chen
2026-09-23  9:56   ` David Heidelberg

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=e026f741-3c19-47b2-b731-f257361e471c@ixit.cz \
    --to=david@ixit.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oe-linux-nfc@lists.linux.dev \
    --cc=sameo@linux.intel.com \
    --cc=shikha.singh@st.com \
    --cc=tianchu.chen@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

all inboxes | Powered by JetHome®