Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: maciej.fijalkowski@intel.com
Cc: netdev@vger.kernel.org, magnus.karlsson@intel.com,
	stfomichev@gmail.com, kuba@kernel.org, pabeni@redhat.com,
	willemb@google.com, matttbe@kernel.org, bjorn@kernel.org
Subject: Re: [PATCH net] xsk: don't call virt_to_netmem() on vmapped UMEM addresses
Date: Sat, 05 Dec 2026 16:28:21 +0000	[thread overview]
Message-ID: <179648810161.3146.1743261122200853049@kernel.org> (raw)
In-Reply-To: <20261204160411.1167875-1-maciej.fijalkowski@intel.com>

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

Critical: 0 · High: 1 · Medium: 2 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix's correctness argument, 'page_address() of the real page
  points into the linear map', is false on 32-bit CONFIG_HIGHMEM kernels.
- [Medium] xp_check_dma_contiguity() (net/xdp/xsk_buff_pool.c:462-478)
  now sets XSK_NEXT_PG_CONTIG_MASK only when consecutive UMEM pages are…
- [Medium] xsk: PFN check in xp_check_dma_contiguity() ignores KASAN page
  tags
- [Low] The commit message understates the impact of the pre-patch bug on
  architectures other than x86-64.

--

xsk: don't call virt_to_netmem() on vmapped UMEM addresses

In xsk_buff_add_frag(), this patch drops virt_to_netmem() on the vmapped
UMEM address. The frag page is now taken from umem->pgs[], indexed by the
offset into the vmap() area. It also changes xp_check_dma_contiguity() so
that XSK_NEXT_PG_CONTIG_MASK is only set when consecutive pages are
contiguous in both DMA address and PFN.

> Without DEBUG_VIRTUAL nothing checks the translation. The frag ends up
> with a struct page that does not back the buffer, but on x86-64
> page_address() of it yields the original address again, so this went
> unnoticed.

[Severity: Low]

Does this hold on architectures other than x86-64? On arm64 without
CONFIG_DEBUG_VIRTUAL, virt_to_page() and page_to_virt() are exact
arithmetic inverses, so arm64 gets the same address back too.

On riscv64 that doesn't seem to happen. A vmalloc address is below
PAGE_OFFSET, so is_linear_mapping() is false and __va_to_pa_nodebug()
applies the kernel image offset:

arch/riscv/include/asm/page.h:
	is_linear_mapping(_x) ?
	linear_mapping_va_to_pa(_x) : kernel_mapping_va_to_pa(_x);

page_to_virt() then translates back through the linear map __va(). The
frag therefore points at an unrelated or unmapped kernel address. On
32-bit x86, __pa() of a vmalloc address lands in the highmem or
out-of-range PFN area.

On those kernels, XDP_PASS of a multi-buffer ZC frame goes through
xdp_build_skb_from_zc()->xdp_copy_frags_from_zc(), which does:

	memcpy(page_address(page) + offset, skb_frag_address(frag),
	       LARGEST_ALIGN(len));

That would either oops or copy unrelated kernel memory into an skb, and
remote traffic drives it. The frag paths of bpf_xdp_load_bytes() and
bpf_xdp_store_bytes() have the same exposure.

Could the commit message mention this? Without it, stable and CVE triage,
including the separate pre-v6.14 ice/i40e backports mentioned here, may
rate the bug lower than it is.

> diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h
> index a40ad3f90f13c..0e1b9bb72b8c9 100644
> --- a/include/net/xdp_sock_drv.h
> +++ b/include/net/xdp_sock_drv.h
> @@ -162,18 +162,22 @@ static inline bool xsk_buff_add_frag(struct xdp_buff *head,
>  				     struct xdp_buff *xdp)
>  {
>  	struct xdp_buff_xsk *frag = container_of(xdp, struct xdp_buff_xsk, xdp);
> +	struct xsk_buff_pool *pool = frag->pool;
>  	const void *data = xdp->data;
> +	struct page *page;
>  
>  	/* Duplicate fill ring entries map to the same xskb in aligned mode */
>  	if (unlikely(xdp == head || !list_empty(&frag->list_node)))
>  		return false;
>  
> -	if (!__xdp_buff_add_frag(head, virt_to_netmem(data),
> +	/* data points into the vmap() of the UMEM, not the linear map */
> +	page = pool->umem->pgs[(data - pool->addrs) >> PAGE_SHIFT];
> +	if (!__xdp_buff_add_frag(head, page_to_netmem(page),

[Severity: High]

The commit message says "page_address() of the real page points into the
linear map". Is that true on 32-bit CONFIG_HIGHMEM kernels?

umem->pgs[] is filled by xdp_umem_pin_pages():

	npgs = pin_user_pages(address, umem->npgs,
			      gup_flags | FOLL_LONGTERM, &umem->pgs[0]);

These are user pages, so they can come from ZONE_HIGHMEM. ZONE_HIGHMEM
pages are long-term pinnable, so FOLL_LONGTERM does not migrate them. The
UMEM is only ever vmap()ed, never kmap()ed.

For a highmem page that is not kmapped, page_address() in mm/highmem.c
returns NULL. skb_frag_address(frag) then becomes NULL + offset, and the
frag consumers dereference it in NAPI context. Examples are the memcpy()
in xdp_copy_frags_from_zc(), the frag paths of bpf_xdp_load_bytes() and
bpf_xdp_store_bytes(), and the memset in bpf_xdp_frags_increase_tail().

I40E depends only on PCI, and ICE and IDPF only on PCI_MSI, so 32-bit
HIGHMEM builds of all three drivers are possible.

The old virt_to_page() on the vmalloc address was broken in this
configuration too. Still, the crash class this patch targets, a CPU
access to a ZC RX frag through an invalid kernel address, looks reachable
here. The new PFN check in xp_check_dma_contiguity() makes the same
lowmem-only assumption.

Would it make sense to avoid page_address() for UMEM frags, or to refuse
ZC multi-buffer when the UMEM contains highmem pages?

>  				 offset_in_page(data), xdp->data_end - data,
>  				 xdp->frame_sz, false))
>  		return false;

[ ... ]

> diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
> index 5ec092f7cb6f7..5891ac6b1f011 100644
> --- a/net/xdp/xsk_buff_pool.c
> +++ b/net/xdp/xsk_buff_pool.c
> @@ -459,15 +459,21 @@ void xp_dma_unmap(struct xsk_buff_pool *pool, unsigned long attrs)
>  }
>  EXPORT_SYMBOL(xp_dma_unmap);
>  
> -static void xp_check_dma_contiguity(struct xsk_dma_map *dma_map)
> +static void xp_check_dma_contiguity(struct xsk_dma_map *dma_map,
> +				    struct page **pages)
>  {
> +	dma_addr_t *dma = dma_map->dma_pages;
>  	u32 i;
>  
> +	/* The CPU reaches RX frags through page_address(), so pages also
> +	 * need to be physically contiguous when an IOMMU translates.
> +	 */
>  	for (i = 0; i < dma_map->dma_pages_cnt - 1; i++) {
> -		if (dma_map->dma_pages[i] + PAGE_SIZE == dma_map->dma_pages[i + 1])
> -			dma_map->dma_pages[i] |= XSK_NEXT_PG_CONTIG_MASK;
> +		if (dma[i] + PAGE_SIZE == dma[i + 1] &&
> +		    page_to_pfn(pages[i]) + 1 == page_to_pfn(pages[i + 1]))
> +			dma[i] |= XSK_NEXT_PG_CONTIG_MASK;

[Severity: Medium]
On arm64 with CONFIG_KASAN_SW_TAGS or CONFIG_KASAN_HW_TAGS, is PFN
adjacency enough for the CPU to run from pages[i] into pages[i + 1]
through page_address(pages[i])?

page_to_virt() on arm64 puts page_kasan_tag(page) in the top byte of
the linear-map pointer. __kasan_unpoison_pages(), called from
post_alloc_hook(), gives each separately allocated order-0 page its own
random tag.

With SW_TAGS, should_skip_kasan_unpoison() never skips this, even for
GFP_HIGHUSER_MOVABLE user pages. With HW_TAGS, the pages that
FOLL_LONGTERM migrates in xdp_umem_pin_pages() are allocated by
migrate_longterm_unpinnable_folios() with GFP_USER | __GFP_NOWARN. That
mask has no __GFP_SKIP_KASAN, so those pages get independent tags too.

Two umem->pgs[] entries can therefore have consecutive PFNs and
consecutive DMA addresses, get XSK_NEXT_PG_CONTIG_MASK here, and still
carry different tags. This needs an unaligned multi-buffer UMEM
(XDP_UMEM_UNALIGNED_CHUNK_FLAG with XDP_USE_SG).

xsk_buff_add_frag() stores an RX frag that starts in pages[i] and runs
into pages[i + 1] as pages[i] with offset + size > PAGE_SIZE. Every
consumer of skb_frag_address() then touches the second page with the
first page's tag. Examples are the memcpy() in xdp_copy_frags_from_zc(),
xsk_copy_xdp(), bpf_xdp_copy_buf() and bpf_xdp_pointer().

Under SW_TAGS, kasan_check_range() reports a tag mismatch and the copy
is not performed. Under HW_TAGS in sync mode, it is a tag check fault
in NAPI context.

Would it work to compare linear-map addresses instead of PFNs? That
would mean requiring page_address(pages[i]) to be non-NULL and
page_address(pages[i]) + PAGE_SIZE to equal page_address(pages[i + 1]).
This checks physical contiguity and tag equality together. It still
allows crossings inside a compound folio, whose subpages share one tag,
and it would not mark highmem pages as contiguous.

[Severity: Medium]

The PFN requirement exists only for CPU access to RX frags through
page_address(). XSK_NEXT_PG_CONTIG_MASK has a single reader,
xp_desc_crosses_non_contig_pg():

	return pool->dma_pages &&
	       !(pool->dma_pages[addr >> PAGE_SHIFT] & XSK_NEXT_PG_CONTIG_MASK);

Two paths use that reader, and both only need DMA contiguity.

xp_unaligned_validate_desc() checks TX descriptors with it. ZC TX gives
the device the IOVA, and the CPU-side TX helpers go through the vmap() in
pool->addrs.

xp_check_unaligned()->xp_addr_crosses_non_contig_pg() checks every fill
ring address, including pools that never build multi-buffer frags. There
the device writes through the IOVA and the CPU reads through xdp->data,
which is also the vmap().

With a translating IOMMU, or with swiotlb-xen where DMA addresses are
machine addresses, consecutive mappings can be IOVA-contiguous while the
pinned pages are not PFN-contiguous. For example, the IOVA rcache
magazines are LIFO, so re-mapping after an earlier unmap can return
ascending IOVAs.

In that case, are page-crossing TX descriptors and fill entries that the
hardware handled correctly before now rejected? TX descriptors would be
dropped and counted in tx_invalid_descs without a completion. Fill
entries would be dropped and counted in the fq invalid_descs. Sockets
without XDP_USE_SG would be affected as well.

>  		else
> -			dma_map->dma_pages[i] &= ~XSK_NEXT_PG_CONTIG_MASK;
> +			dma[i] &= ~XSK_NEXT_PG_CONTIG_MASK;
>  	}
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204160411.1167875-1-maciej.fijalkowski%40intel.com

      parent reply	other threads:[~2026-12-05 16:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 16:04 [PATCH net] xsk: don't call virt_to_netmem() on vmapped UMEM addresses Maciej Fijalkowski
2026-12-04 18:13 ` Björn Töpel
2026-12-05 16:28 ` netdev-bot+sashiko [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=179648810161.3146.1743261122200853049@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=kuba@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=matttbe@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stfomichev@gmail.com \
    --cc=willemb@google.com \
    /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