From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796488103; b=N+GSsxxNThTEj2lwUu+3GsAyZM0t/U1y+D1a9q48HcdnxyRT9y5wNqAwJYaJkHzucECX Wn6p4Z39vL+JKVHR4fFNZeHypE5Ys+074szSRF34Pya0Nonsz2nxRdYpMD2Rse5LXTkxs hwaJXSBK+wfUL4SADC/KqetTJ2mVW3QKppXoqkhbvHtH4IhXT3Pse9c29jCnfD0rYte8g AkAHoZygGCKGNKKgtWa4mj6rc8vAVuPnZQCXdJsgUHdBSqJPD58qBPbzK/o7bXvX9IU6l nMWbYj1DH/unSi502TOmitkanxQBBNjZ1zjl6tbGz81tr2pg8rvMCH6nmO5gg9No+3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796488103; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=J4UWbAhkhwgdUZn0P36tAMr8QIYSzx5CEIIAWWuXtxM=; b=LDnA5gWMy6eLs19wrY5sRCeBOY/RiRnmk8FO2Y+kqgoqSBVVx7D9s5BsMAS/OEsNqbS+ vWTeJfWUg/DnkyczZ439b5Tdr5vrqQyltS03/XuWpt9unL2haz589JH4slfoY2ljzh7+J Yr/IZTjqlPhPTz2rg+SkkEFTyDn0A2Q2nMl7esUWx9UEcBrJrA0GgavgJa0+pTZhrg+gr BK8ZgWszHhIqUbF+glXSn6haEK/05uDXHcQVABojcaw4Rmf2ezw8K2NlplgyHVyLPJU0l f6oPFKrya7WZO4aXtmKRuaqtAwsubn9kFjtyf7zmZHeiqst1VYWUmY8othOT70dqmKQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mq6cPZHK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED6E9606A6BF for ; Sat, 5 Dec 2026 16:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mq6cPZHK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18FD41F00A15; Sat, 5 Dec 2026 16:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796488102; bh=J4UWbAhkhwgdUZn0P36tAMr8QIYSzx5CEIIAWWuXtxM=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=mq6cPZHKV4F9RS6RmxrAsx1JBhKP9vmVjocmmgUA2CWcmxb/Zp07JEgqCN0a7UKMk srJ7sRgAjNgNW4sDolWzeTcgGVEiC369Ifeduw/VFfKWvYBIh0gb5eTuLZJcmCfvt8 QnJcE3JT+WIY9vsj+knsr7+oXQVb+nmBGywi0BRhEqa7ky1LnxE5GQoH3D8GrVpYms rc9NEog1WMPLACELGeL8kmV/++lu1YzLeb+CZL7F19S9nM9zELPNnAkvndN42hO+NW N9N3gEQLQih+sJw4XiF0s+qyfVq7JVSKJb7FqG+wetn1geMvFiyxjmhWsmDWwOxadl NicFV6OOTmlbQ== Subject: Re: [PATCH net] xsk: don't call virt_to_netmem() on vmapped UMEM addresses 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 Date: Sat, 05 Dec 2026 16:28:21 +0000 Message-ID: <179648810161.3146.1743261122200853049@kernel.org> In-Reply-To: <20261204160411.1167875-1-maciej.fijalkowski@intel.com> References: <20261204160411.1167875-1-maciej.fijalkowski@intel.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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