From: sashiko-bot@kernel.org
To: "Kuniyuki Iwashima" <kuniyu@google.com>
Cc: intel-wired-lan@lists.osuosl.org
Subject: Re: [PATCH v2 iwl-next 5/5] idpf: Unmap Rx payload pages above mapped threshold under DMA-FQ IOMMU.
Date: Sat, 05 Dec 2026 13:16:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-251556@kernel.org> (raw)
In-Reply-To: <20261205125237.2290932-6-kuniyu@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] idpf: use-after-free iterating adapter->vports in
idpf_rx_bufs_init()
- [Medium] idpf: early DMA unmap before sync in idpf_rx_splitq_clean()
--
commit 7eb204337944ee9347e5afd898d0150f3523d291
Author: Kuniyuki Iwashima <kuniyu@google.com>
idpf: Unmap Rx payload pages above mapped threshold under DMA-FQ IOMMU.
This commit adds threshold-based early DMA unmapping for splitq Rx payload
pages in idpf when XDP is disabled on DMA-coherent devices under an
IOMMU_DOMAIN_DMA_FQ domain. It tracks active descriptor references per page
in a per-bufq ring and calls page_pool_dma_unmap_netmem() once all
descriptors referencing a tracked page complete.
> diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> index fb6a2ea25dc5d..a21f21cf66ec7 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
[ ... ]
> @@ -869,6 +997,59 @@ static int idpf_rx_bufs_init(struct idpf_buf_queue *bufq,
> if (ret)
> return ret;
>
> + if (PP_DMA_INDEX_BITS && !fq.xdp &&
> + !dma_dev_need_sync(&vport->adapter->pdev->dev)) {
> + struct iommu_domain *domain;
> +
> + domain = iommu_get_domain_for_dev(&vport->adapter->pdev->dev);
> + if (domain && domain->type == IOMMU_DOMAIN_DMA_FQ) {
[ ... ]
> + idpf_for_each_vport(vport->adapter, v)
> + num_bufqs +=
> + v->dflt_qv_rsrc.num_rxq_grp *
> + v->dflt_qv_rsrc.num_bufqs_per_qgrp;
> + num_bufqs = max_t(u32, 1, num_bufqs);
[Severity: Medium]
Can iterating adapter->vports here race with vport teardown on a multi-vport
adapter and trigger a use-after-free?
idpf_open() reaches idpf_rx_bufs_init() holding rtnl_lock and
adapter->vport_ctrl_lock. On device removal, idpf_remove() ->
idpf_vc_core_deinit() -> idpf_deinit_task() tears down vports sequentially
via idpf_vport_dealloc() without holding either lock across vport
destruction, while sibling netdevs are still registered.
In idpf_vport_dealloc(), idpf_vport_rel() calls kfree(vport) before
adapter->vports[i] is cleared to NULL:
CPU0 CPU1
idpf_remove()
idpf_vc_core_deinit()
idpf_deinit_task()
idpf_vport_dealloc(...)
idpf_vport_rel(vports[0])
kfree(vports[0])
idpf_open(netdevs[1])
...
idpf_rx_bufs_init()
v->dflt_qv_rsrc...
<-- use-after-free
adapter->vports[0] = NULL
Dereferencing v->dflt_qv_rsrc on the freed sibling vport causes a slab
use-after-free read.
[ ... ]
> @@ -3948,6 +4129,7 @@ static int idpf_rx_splitq_clean(struct idpf_rx_queue *rxq, int budget)
> buf_id = le16_to_cpu(rx_desc->buf_id);
>
> rx_buf = &rx_bufq->buf[buf_id];
> + idpf_rx_buf_dma_unmap(rx_bufq, buf_id);
>
> if (!coherent_hdr && !rx_bufq->hdr_pp)
> goto payload;
[Severity: Medium]
Should idpf_rx_buf_dma_unmap() run after libeth_rx_sync_for_cpu() instead of
before it?
When entry->refs reaches 0, page_pool_dma_unmap_netmem() unmaps the page and
clears netmem->dma_addr to 0. On an untrusted DMA-coherent PCIe device
switched to IOMMU_DOMAIN_DMA_FQ via sysfs, dma_dev_need_sync() starts false
and flips to true on the first unaligned streaming mapping that uses
swiotlb:
CPU0 CPU1
idpf_rx_splitq_clean()
idpf_rx_buf_dma_unmap()
page_pool_dma_unmap_netmem()
dma_dev_need_sync() == false
dma_addr = 0
idpf_tx_splitq_map()
dma_map_single()
swiotlb_tbl_map_single()
dma_reset_need_sync(dev)
idpf_rx_splitq_clean_skb()
libeth_rx_sync_for_cpu()
iommu_dma_sync_single_for_cpu(0 + offset)
swiotlb_bounce() <-- corrupts unrelated memory
When host PAGE_SIZE exceeds the IOMMU granule (for example, 64K pages with a
4K granule), sub-page offsets >= 4K land in allocatable IOVA PFNs rather
than the reserved PFN 0. If that PFN holds an active swiotlb bounce buffer,
swiotlb_bounce() overwrites unrelated kernel memory.
Moving idpf_rx_buf_dma_unmap() after libeth_rx_sync_for_cpu() and before
rx_buf->netmem is cleared avoids syncing a cleared DMA address.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205125237.2290932-1-kuniyu@google.com?part=5
prev parent reply other threads:[~2026-12-05 13:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 12:52 [PATCH v2 iwl-next 0/5] idpf: Avoid IOVA exhaustion under DMA-FQ IOMMU Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 1/5] idpf: Reuse idpf_rx_update_bufq_desc() in idpf_rx_post_buf_desc() Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 2/5] idpf: Use coherent DMA buffer for Rx header split without XDP Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 3/5] netmem: Annotate data-races around pp_magic Kuniyuki Iwashima
2026-12-05 12:52 ` [PATCH v2 iwl-next 4/5] page_pool: Allow drivers to unmap DMA before returning pages Kuniyuki Iwashima
2026-12-05 13:15 ` sashiko-bot
2026-12-05 12:52 ` [PATCH v2 iwl-next 5/5] idpf: Unmap Rx payload pages above mapped threshold under DMA-FQ IOMMU Kuniyuki Iwashima
2026-12-05 13:16 ` sashiko-bot [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=sashiko-outbox-251556@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kuniyu@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox