All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Selvamani Rajagopal via B4 Relay"
	<devnull+Selvamani.Rajagopal.onsemi.com@kernel.org>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH net v4 2/4] net: ethernet: oa_tc6: No return on rx buffer overflow error
Date: Wed, 10 Jun 2026 19:50:49 +0000	[thread overview]
Message-ID: <20260610195049.8983C1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609-level-trigger-v4-2-6f389abdd192@onsemi.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [High] The newly added check for `-EAGAIN` in the threaded IRQ loop is dead code for its intended purpose (RX overflow recovery) and introduces a dangerous tight busy-loop if the underlying SPI driver fails.

Pre-existing issues:
- [Critical] Missing tailroom check before calling `skb_put()` on the receive path allows a malformed or malicious MAC-PHY stream to cause an `skb_over_panic()`.
- [Critical] Out-of-bounds memory access due to unvalidated hardware inputs for TX credits and RX chunks.
- [High] The device IRQ is not disabled before freeing SKB pointers in `oa_tc6_exit()`, leading to a race condition and use-after-free.
--

commit bd14c34a7b1c3dad290ba34e28faf15014377d8e
Author: Selvamani Rajagopal <Selvamani.Rajagopal@onsemi.com>

net: ethernet: oa_tc6: No return on rx buffer overflow error

This patch modifies the threaded IRQ handler to retry the SPI transfer if
oa_tc6_try_spi_transfer() returns -EAGAIN. This is intended to gracefully
recover from RX buffer overflow errors by discarding bad data chunks.

> diff --git a/drivers/net/ethernet/oa_tc6.c b/drivers/net/ethernet/oa_tc6.c
> --- a/drivers/net/ethernet/oa_tc6.c
> +++ b/drivers/net/ethernet/oa_tc6.c
> @@ -1111,6 +1111,8 @@ static irqreturn_t oa_tc6_macphy_threaded_irq(int irq, void *data)
>  
>  	while (tc6->int_flag || (tc6->waiting_tx_skb && tc6->tx_credits)) {
>  		ret = oa_tc6_try_spi_transfer(tc6);
> +		if (ret == -EAGAIN)
> +			continue;

[Severity: High]
Can oa_tc6_try_spi_transfer() actually return -EAGAIN for an RX overflow
condition here?

Looking at oa_tc6_try_spi_transfer(), it catches the -EAGAIN internally:

static int oa_tc6_try_spi_transfer(struct oa_tc6 *tc6)
{
        ...
        ret = oa_tc6_process_spi_data_rx_buf(tc6, spi_len);
        if (ret) {
                if (ret == -EAGAIN)
                        continue;
        ...
}

Since it loops internally, it seems it won't return -EAGAIN to the IRQ
handler for an RX overflow.

The only way oa_tc6_try_spi_transfer() returns -EAGAIN to the caller
is if the underlying SPI transfer fails with -EAGAIN.

If that happens, wouldn't this new continue statement create a tight infinite
busy-loop in the threaded IRQ handler context without sleeping?

>  		if (ret)
>  			break;
>  	}

[Severity: Critical]
This is a pre-existing issue, but does oa_tc6_update_rx_skb() verify that
the skb has sufficient tailroom before calling skb_put()?

In the receive path, data is copied into the skb:

static void oa_tc6_update_rx_skb(struct oa_tc6 *tc6, u8 *payload, u16 length)
{
        ...
        memcpy(skb_put(tc6->rx_skb, length), payload, length);
}

This is called repeatedly for ongoing frames by oa_tc6_prcs_ongoing_rx_frame()
which appends 64-byte payload chunks to the skb.

If a faulty MAC-PHY or bit-flip streams chunks without setting the end_valid
bit, could the unconditional calls to skb_put() overrun the SKB's tailroom
and trigger a kernel panic via skb_over_panic()?

[Severity: High]
This is a pre-existing issue, but is the device IRQ properly disabled
before oa_tc6_exit() frees the SKB pointers?

oa_tc6_exit() does the following:

static void oa_tc6_exit(struct oa_tc6 *tc6)
{
        ...
        dev_kfree_skb_any(tc6->ongoing_tx_skb);
        dev_kfree_skb_any(tc6->waiting_tx_skb);
        dev_kfree_skb_any(tc6->rx_skb);
        ...
}

Since the driver uses devm_request_threaded_irq(), the IRQ remains active
until the driver unbinds, which happens after oa_tc6_exit() returns.

If an interrupt fires concurrently while oa_tc6_exit() calls
dev_kfree_skb_any(), could the still-active oa_tc6_macphy_threaded_irq()
handler attempt to access these freed pointers?

[Severity: Critical]
This is a pre-existing issue, but do we validate the chunk counts read
from the hardware?

The driver updates the chunk counts from hardware registers:

static void oa_tc6_update_buffer_status_from_register(struct oa_tc6 *tc6,
                                                      u32 value)
{
        tc6->rx_chunks_available = FIELD_GET(BUFFER_STATUS_RX_CHUNKS_AVAILABLE,
                                             value);
        ...
}

These bitfields are 8 bits wide, allowing values up to 255. However, the
SPI data buffers are statically sized to handle a maximum of
OA_TC6_MAX_TX_CHUNKS (48).

If the hardware reports a value larger than 48, could loops like
oa_tc6_add_empty_chunks_to_spi_buf() write past the bounds of
spi_data_tx_buf and cause memory corruption during the SPI transfer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260609-level-trigger-v4-0-6f389abdd192@onsemi.com?part=2

  reply	other threads:[~2026-06-10 19:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 19:50 [PATCH net v4 0/4] MAC-PHY interrupt changed to level triggered interrupt Selvamani Rajagopal via B4 Relay
2026-06-09 19:50 ` Selvamani Rajagopal
2026-06-09 19:50 ` [PATCH net v4 1/4] net: ethernet: oa_tc6: Interrupt is active low, level triggered Selvamani Rajagopal via B4 Relay
2026-06-09 19:50   ` Selvamani Rajagopal
2026-06-10 19:50   ` sashiko-bot
2026-06-09 19:50 ` [PATCH net v4 2/4] net: ethernet: oa_tc6: No return on rx buffer overflow error Selvamani Rajagopal via B4 Relay
2026-06-09 19:50   ` Selvamani Rajagopal
2026-06-10 19:50   ` sashiko-bot [this message]
2026-06-09 19:50 ` [PATCH net v4 3/4] net: ethernet: oa_tc6: mdiobus->parent initialized with NULL Selvamani Rajagopal via B4 Relay
2026-06-09 19:50   ` Selvamani Rajagopal
2026-06-10 19:50   ` sashiko-bot
2026-06-09 19:50 ` [PATCH net v4 4/4] dt-bindings: net: updated interrupt type to be active low, level triggered Selvamani Rajagopal via B4 Relay
2026-06-09 19:50   ` Selvamani Rajagopal
2026-06-10  7:22   ` Krzysztof Kozlowski
2026-06-10 15:09     ` Selvamani Rajagopal

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=20260610195049.8983C1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=devnull+Selvamani.Rajagopal.onsemi.com@kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@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 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.