From: sashiko-bot@kernel.org
To: "Daniel Zahka" <daniel.zahka@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v2 4/8] eth: mpnic: implement Tx queue allocation and cleanup
Date: Sat, 26 Sep 2026 00:36:01 +0000 [thread overview]
Message-ID: <20260926003601.C37A21F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260924-linux-mpnic-v2-4-4badc9b58b9e@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] net: mpnic: trusting DMA parameters from device-accessible ring
- [High] net: mpnic: missing bounds check on hardware completion head causes NULL deref
- [High] net: mpnic: integer underflow in desc_cnt causes massive out-of-bounds unmaps
- [High] net: mpnic: missing memory barrier before completion queue doorbell
--
commit 92d64496d6b2ec052301fad8882b705af9c36a85
Author: Daniel Zahka <daniel.zahka@gmail.com>
eth: mpnic: implement Tx queue allocation and cleanup
This commit introduces the allocation and cleanup of the Tx queues for the mpnic driver. It sets up triads of work and completion queues per NAPI vector, along with their descriptor memory, interrupts, and completion processing.
> diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
> index 0000000000000..853976e11b032
> --- /dev/null
> +++ b/drivers/net/ethernet/meta/mpnic/mpnic_txrx.c
[ ... ]
> +static void mpnic_unmap_single_twd(struct device *dev, __le64 *twd)
> +{
> + u64 raw_twd = le64_to_cpu(*twd);
> +
> + dma_unmap_single(dev, FIELD_GET(MPNIC_TWD_ADDR, raw_twd),
> + FIELD_GET(MPNIC_TWD_LEN, raw_twd), DMA_TO_DEVICE);
> +}
[Severity: Critical]
Does this code rely on untrusted DMA parameters?
The descriptor ring memory is device-accessible. If a malicious or buggy
PCIe device overwrites the address and length fields after submission, it
could trick the host into unmapping arbitrary kernel or IOMMU memory. Should
the driver store DMA mapping state in host-only software memory instead?
> +
> +static void mpnic_unmap_page_twd(struct device *dev, __le64 *twd)
> +{
> + u64 raw_twd = le64_to_cpu(*twd);
> +
> + dma_unmap_page(dev, FIELD_GET(MPNIC_TWD_ADDR, raw_twd),
> + FIELD_GET(MPNIC_TWD_LEN, raw_twd), DMA_TO_DEVICE);
> +}
[Severity: Critical]
Similar to mpnic_unmap_single_twd(), does this code safely handle potentially
spoofed DMA parameters from the hardware ring?
> +
> +static void mpnic_clean_twq0(struct mpnic_napi_vector *nv, int napi_budget,
> + struct mpnic_ring *ring, bool discard,
> + unsigned int hw_head)
> +{
> + u64 total_bytes = 0, total_packets = 0;
> + unsigned int head = ring->head;
> + struct netdev_queue *txq;
> + unsigned int clean_desc;
> +
> + clean_desc = (hw_head - head) & ring->size_mask;
> +
> + while (clean_desc) {
> + struct sk_buff *skb = ring->tx_buf[head];
> + unsigned int desc_cnt;
> +
> + desc_cnt = MPNIC_XMIT_CB(skb)->desc_count;
[Severity: High]
Is it possible for hw_head to be spoofed by the device, causing an
out-of-bounds access?
If the completion queue reports an out-of-bounds hw_head, clean_desc might
cover unpopulated slots in the ring buffer. This would result in accessing
ring->tx_buf[head] which is NULL, leading to a NULL pointer dereference when
accessing MPNIC_XMIT_CB(skb)->desc_count. Should the number of completed
descriptors be validated against the number of pending descriptors?
> + if (desc_cnt > clean_desc)
> + break;
> +
> + ring->tx_buf[head] = NULL;
> +
> + clean_desc -= desc_cnt;
> +
> + /* Step over the metadata descriptor */
> + head++;
> + head &= ring->size_mask;
> + desc_cnt--;
> +
> + mpnic_unmap_single_twd(nv->dev, &ring->desc[head]);
> + head++;
> + head &= ring->size_mask;
> + desc_cnt--;
> +
> + while (desc_cnt--) {
[Severity: High]
Can desc_cnt underflow here if desc_cnt is less than 2?
If the completion head is advanced by a malicious device to cover a packet
currently being built (where desc_cnt might be 0), the unconditional double
decrement will underflow desc_cnt to a massive unsigned value. This would
cause the subsequent loop to execute millions of times with out-of-bounds
ring indices and out-of-bounds DMA unmaps.
> + mpnic_unmap_page_twd(nv->dev, &ring->desc[head]);
> + head++;
> + head &= ring->size_mask;
> + }
> +
> + total_bytes += MPNIC_XMIT_CB(skb)->bytecount;
> + total_packets++;
> +
> + napi_consume_skb(skb, napi_budget);
> + }
[ ... ]
> +static void mpnic_commit_cq_head(struct mpnic_ring *cmpl)
> +{
> + u32 head = cmpl->head;
> +
> + /* The tail shadows the last value written to the doorbell, so a
> + * completion queue which has not moved costs no MMIO write.
> + */
> + if (cmpl->tail != head) {
> + cmpl->tail = head;
> + writeq(head & cmpl->size_mask, cmpl->doorbell);
> + }
> +}
[Severity: High]
Does this MMIO write to the doorbell require a memory barrier to guarantee
prior descriptor reads are complete?
On weakly ordered architectures like ARM64, writeq() only provides a
Store-Store barrier (wmb()). Without a read-store barrier (like rmb() or
dma_rmb()), prior memory loads could be reordered after the doorbell write,
potentially allowing the hardware to overwrite descriptors while the CPU is
still reading them.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924-linux-mpnic-v2-0-4badc9b58b9e@gmail.com?part=4
next prev parent reply other threads:[~2026-09-26 0:36 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 0:35 [PATCH net-next v2 0/8] eth: mpnic: initial support for Meta Platforms NIC Daniel Zahka
2026-09-25 0:35 ` [PATCH net-next v2 1/8] eth: mpnic: add scaffolding " Daniel Zahka
2026-09-26 0:36 ` sashiko-bot
2026-09-28 0:01 ` netdev-bot+sashiko
2026-09-28 12:13 ` Daniel Zahka
2026-09-25 0:35 ` [PATCH net-next v2 2/8] eth: mpnic: add register init for the device Daniel Zahka
2026-09-28 0:01 ` netdev-bot+sashiko
2026-09-28 12:14 ` Daniel Zahka
2026-09-25 0:35 ` [PATCH net-next v2 3/8] eth: mpnic: allocate MSI-X vectors Daniel Zahka
2026-09-28 0:01 ` netdev-bot+sashiko
2026-09-28 16:01 ` Daniel Zahka
2026-09-25 0:35 ` [PATCH net-next v2 4/8] eth: mpnic: implement Tx queue allocation and cleanup Daniel Zahka
2026-09-26 0:36 ` sashiko-bot [this message]
2026-09-28 0:01 ` netdev-bot+sashiko
2026-09-28 14:46 ` Daniel Zahka
2026-09-25 0:35 ` [PATCH net-next v2 5/8] eth: mpnic: start and stop the Tx HW queues Daniel Zahka
2026-09-26 0:36 ` sashiko-bot
2026-09-28 0:01 ` netdev-bot+sashiko
2026-09-28 15:00 ` Daniel Zahka
2026-09-25 0:35 ` [PATCH net-next v2 6/8] eth: mpnic: add a netdevice and basic Tx handling Daniel Zahka
2026-09-28 0:01 ` netdev-bot+sashiko
2026-09-28 15:10 ` Daniel Zahka
2026-09-25 0:35 ` [PATCH net-next v2 7/8] eth: mpnic: implement Rx queue allocation and cleanup Daniel Zahka
2026-09-28 0:01 ` netdev-bot+sashiko
2026-09-28 15:11 ` Daniel Zahka
2026-09-25 0:35 ` [PATCH net-next v2 8/8] eth: mpnic: add basic Rx handling Daniel Zahka
2026-09-26 0:36 ` sashiko-bot
2026-09-28 0:01 ` netdev-bot+sashiko
2026-09-28 15:17 ` Daniel Zahka
2026-09-29 2:03 ` Jakub Kicinski
2026-09-28 18:16 ` [PATCH net-next v2 0/8] eth: mpnic: initial support for Meta Platforms NIC Daniel Zahka
2026-09-29 8:50 ` patchwork-bot+netdevbpf
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=20260926003601.C37A21F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel.zahka@gmail.com \
--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.