From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: ntb@lists.linux.dev
Subject: Re: [PATCH net-next v3 2/4] NTB: ntb_transport: Use little-endian shared fields
Date: Sat, 05 Sep 2026 05:22:01 +0000 [thread overview]
Message-ID: <20260905052201.8B54B1F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260904052134.2970111-3-den@valinux.co.jp>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Permanent RX queue stall on version mismatch error.
- [High] Missing bounds check against `rx_max_frame` allows an attacker-controlled peer to trigger an out-of-bounds read of kernel memory.
- [Medium] The queue size calculations do not guarantee that `rx_size` and `tx_size` are appropriately aligned, leading to unaligned MMIO writes and coherent memory accesses.
--
commit 8632f1194f420fac4999a48cdd0e2e9e59e54697
Author: Koichiro Den <den@valinux.co.jp>
NTB: ntb_transport: Use little-endian shared fields
ntb_transport writes payload headers and the RX ring tail with
iowrite32(), but reads peer-written copies from coherent memory as native
integers. The values are therefore byte-swapped when read on a big-endian
system.
Mark the shared fields as __le32 and convert coherent-memory accesses
accordingly. Read hdr->ver and hdr->len once so their checks and later
uses see the same values.
Link: https://lore.kernel.org/r/20260815032932.151F11F000E9@smtp.kernel.org/
Link: https://lore.kernel.org/r/20260818064951.7EA231F000E9@smtp.kernel.org/
> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index 74f4f8c1c7be8..3f497a62673fd 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
[ ... ]
> @@ -633,7 +634,7 @@ static int ntb_transport_setup_qp_mw(struct ntb_transport_ctx *nt,
> qp->rx_alloc_entry++;
> }
>
> - qp->remote_rx_info->entry = qp->rx_max_entry - 1;
> + qp->remote_rx_info->entry = cpu_to_le32(qp->rx_max_entry - 1);
[Severity: Medium]
This isn't a bug introduced by this patch, but the local receive buffer slice
size rx_size is calculated earlier in ntb_transport_setup_qp_mw() as:
rx_size = (unsigned int)mw->xlat_size / num_qps_mw;
If num_qps_mw does not cleanly divide the window size, the resulting rx_size
can be unaligned.
Does this misalign the qp->remote_rx_info pointer which resides at the end
of this buffer, as well as the frame boundaries qp->rx_max_frame? If so, on
strict architectures, could the unaligned READ_ONCE() and iowrite32()
accesses to the payload headers and shared fields trigger an alignment fault?
>
> /* setup the hdr offsets with 0's */
> for (i = 0; i < qp->rx_max_entry; i++) {
[ ... ]
> @@ -1623,21 +1626,23 @@ static int ntb_process_rxc(struct ntb_transport_qp *qp)
> }
>
> dma_rmb();
> + ver = le32_to_cpu(READ_ONCE(hdr->ver));
> + len = le32_to_cpu(READ_ONCE(hdr->len));
>
> dev_dbg(&qp->ndev->pdev->dev, "qp %d: RX ver %u len %d flags %x\n",
> - qp->qp_num, hdr->ver, hdr->len, flags);
> + qp->qp_num, ver, len, flags);
>
> if (flags & LINK_DOWN_FLAG) {
> dev_dbg(&qp->ndev->pdev->dev, "link down flag set\n");
> ntb_qp_link_down(qp);
> - hdr->flags = 0;
> + hdr->flags = cpu_to_le32(0);
> return -EAGAIN;
> }
>
> - if (hdr->ver != (u32)qp->rx_pkts) {
> + if (ver != (u32)qp->rx_pkts) {
> dev_dbg(&qp->ndev->pdev->dev,
> "version mismatch, expected %llu - got %u\n",
> - qp->rx_pkts, hdr->ver);
> + qp->rx_pkts, ver);
> qp->rx_err_ver++;
> return -EIO;
> }
[Severity: High]
This is a pre-existing issue, but if the received payload header version does
not match the expected qp->rx_pkts in ntb_process_rxc(), the function
increments the error counter and returns -EIO without clearing the
DESC_DONE_FLAG or advancing qp->rx_index.
Since the caller aborts processing upon the error, the next time the queue is
processed, it will attempt to process the same packet at the same index, fail
the version check again, and return -EIO.
Can this lead to a permanent stall of the RX queue until the link is
physically reset?
> @@ -1652,10 +1657,10 @@ static int ntb_process_rxc(struct ntb_transport_qp *qp)
> entry->rx_hdr = hdr;
> entry->rx_index = qp->rx_index;
>
> - if (hdr->len > entry->len) {
> + if (len > entry->len) {
[Severity: High]
This isn't a bug introduced by this patch, but this bounds check in
ntb_process_rxc() only validates that the received length len fits within the
client-provided buffer (entry->len).
Because entry->len is derived from the local memory window size
(tx_max_frame), it can be larger than the receive frame size (rx_max_frame)
negotiated by the peer.
If a malicious peer provides a large length that is greater than the
negotiated rx_max_frame but still less than entry->len, could this bypass the
check and cause ntb_memcpy_rx() or ntb_async_rx() below to copy memory
out-of-bounds from the qp->rx_buff DMA region, leaking adjacent kernel memory
to the network stack?
> dev_dbg(&qp->ndev->pdev->dev,
> "receive buffer overflow! Wanted %d got %d\n",
> - hdr->len, entry->len);
> + len, entry->len);
> qp->rx_err_oflow++;
>
> entry->len = -EIO;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904052134.2970111-1-den@valinux.co.jp?part=2
next prev parent reply other threads:[~2026-09-05 5:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 5:21 [PATCH net-next v3 0/4] net: ntb_netdev: Preserve checksum offload across NTB Koichiro Den
2026-09-04 5:21 ` [PATCH net-next v3 1/4] NTB: ntb_transport: Order RX descriptor reads after completion Koichiro Den
2026-09-05 5:22 ` sashiko-bot
2026-09-04 5:21 ` [PATCH net-next v3 2/4] NTB: ntb_transport: Use little-endian shared fields Koichiro Den
2026-09-05 5:22 ` sashiko-bot [this message]
2026-09-04 5:21 ` [PATCH net-next v3 3/4] NTB: ntb_transport: Add per-payload client metadata Koichiro Den
2026-09-05 5:22 ` sashiko-bot
2026-09-09 20:24 ` netdev-bot+sashiko
2026-09-11 0:18 ` Jakub Kicinski
2026-09-11 7:48 ` Koichiro Den
2026-09-04 5:21 ` [PATCH net-next v3 4/4] net: ntb_netdev: Preserve CHECKSUM_PARTIAL across NTB Koichiro Den
2026-09-09 20:24 ` netdev-bot+sashiko
2026-09-11 5:49 ` Koichiro Den
2026-09-11 0:20 ` Jakub Kicinski
2026-09-11 5:41 ` Koichiro Den
2026-09-11 9:47 ` Paolo Abeni
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=20260905052201.8B54B1F00A3E@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=den@valinux.co.jp \
--cc=ntb@lists.linux.dev \
--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.