🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10958

Re: [PATCH v6 bpf 1/3] xdp: introduce xdp_convert_skb_to_buff()

#10958
From: bot+bpf-ci
Date: Wed, 04 Nov 2026 12:53
111 lines
12486 bytes
--===============6622439773063420790==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

> xdp: introduce xdp_convert_skb_to_buff()

TL;DR:
- Persistent mem.type store in shared rxq may make BPF_PROG_TEST_RUN frag
  release hit page_pool path: WARN, leaked page
- Commit message nits: inaccurate "assigned to xdp_buff", stale "about to be
  integrated"

> diff --git a/include/net/xdp.h b/include/net/xdp.h
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h

[ ... ]

> +/**
> + * xdp_convert_skb_to_buff - build an xdp_buff on top of an skb
> + * @skb: skb to describe, packet data is taken from its MAC header onwards
> + * @xdp: xdp_buff to initialize
> + * @xdp_rxq: Rx queue info to attach to @xdp
> + *
> + * The memory type set on @xdp_rxq is only used to release fragments that
> + * the XDP program consumes; the head can not be freed from under the skb.
> + * A non-linear @skb is expected to have gone through skb_pp_cow_data(), so
> + * all of its fragments are page_pool backed.
> + */

[ ... ]

> +	DEBUG_NET_WARN_ON_ONCE(skb_is_nonlinear(skb) && !skb->pp_recycle);
> +	xdp->rxq->mem.type = MEM_TYPE_PAGE_POOL;
> +}

Can this store break other users of the same xdp_rxq_info?

bpf_prog_run_generic_xdp() passes &netif_get_rxqueue(skb)->xdp_rxq, which
is the device's long-lived dev->_rx[i].xdp_rxq.  The new mem.type is never
restored, so after the first generic XDP packet the queue stays
MEM_TYPE_PAGE_POOL.  Before this patch nothing wrote this field, and it
stayed at MEM_TYPE_PAGE_SHARED from xdp_rxq_info_reg().

bpf_prog_test_run_xdp() builds its xdp_buff on the same structure:

    rxqueue = __netif_get_rx_queue(current->nsproxy->net_ns->loopback_dev, 0);
    rxqueue->xdp_rxq.frag_size = PAGE_SIZE;
    xdp_init_buff(&xdp, rxqueue->xdp_rxq.frag_size, &rxqueue->xdp_rxq);

(or the rxq selected by ctx->ingress_ifindex in xdp_convert_md_to_buff()).
It allocates its frags with alloc_page(GFP_KERNEL) and relies on the
default MEM_TYPE_PAGE_SHARED.

If an xdp.frags program run through BPF_PROG_TEST_RUN then releases a whole
frag with bpf_xdp_adjust_tail() or bpf_xdp_pull_data():

bpf_xdp_shrink_data()
  __xdp_return(netmem, MEM_TYPE_PAGE_POOL, ...)
    page_pool_put_full_netmem(netmem_get_pp(netmem), ...)

this runs the page_pool path on an ordinary page.  pp_ref_count overlays
page->private, which is 0, so page_pool_unref_netmem() sees
atomic_long_sub_return() return -1 and hits WARN_ON(ret < 0).  The page is
not freed, and it has already been removed from sinfo->frags, so the
__free_page() loop at the end of bpf_prog_test_run_xdp() does not free it
either.

To reproduce, attach a generic XDP program to lo, pass one packet, then run
BPF_PROG_TEST_RUN on an xdp.frags program with data_size_in larger than one
page whose bpf_xdp_adjust_tail() shrinks by at least the last frag.  The
result is a WARN (a panic with panic_on_warn) and a leaked page per run.

The kdoc says "The memory type set on @xdp_rxq is only used to release
fragments that the XDP program consumes", and the commit message says "The
mem type is only consulted when the program releases fragments".  Both
describe only the generic XDP buffer, and neither mentions that the value
persists in shared rxq state.

Could mem.type be saved and restored around the program run, or could
bpf_prog_test_run_xdp() set the mem type it needs (or use its own
xdp_rxq_info)?  The later veth commits in this series only touch
drivers/net/veth.c and do not address this.

Also, the commit message says:

> Pull out the existing code from bpf_prog_run_generic_xdp() that
> init/prepares xdp_buff onto new helper xdp_convert_skb_to_buff() and
> embed there rxq's mem_type initialization that is assigned to xdp_buff.

Is "assigned to xdp_buff" accurate?  struct xdp_buff has no mem type field;
the helper writes xdp->rxq->mem.type, i.e. netdev_rx_queue::xdp_rxq.mem.type.

And the commit message also says:

> This problem was triggered by syzbot as well as AF_XDP test suite which
> is about to be integrated to BPF CI.

This isn't a bug, but is "about to be integrated" still accurate?
selftests/bpf test_xsk.c already appears to be integrated into test_progs
in this tree (d1aec26fce25), so the wording looks stale.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/41828746707
--===============6622439773063420790==--
Technical Details
Message-ID: <9b616d465e6f88aab813a79cc84c51ed358861e201bfb23921864e62fc9dc023@mail.kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356432-linux-kernel-netdev=dewy.ru
References: <20261104121316.1155680-2-sst@poczta.fm>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356432-linux-kernel-netdev=dewy.ru
From: bot+bpf-ci@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v6 bpf 1/3] xdp: introduce xdp_convert_skb_to_buff()
Date: Wed,  4 Nov 2026 12:53:35 +0000 (UTC)
Organization: Usenet Network
Message-ID: <9b616d465e6f88aab813a79cc84c51ed358861e201bfb23921864e62fc9dc023@mail.kernel.org>
References: <20261104121316.1155680-2-sst@poczta.fm>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============6622439773063420790=="
Injection-Info: usenet.network;
	logging-data="3391821"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:PY6DcRbv3JEJwZi+CO4MzI62ut8= sha256:2P+KgQ8fsXg/ac7Fb7fyby875Earg+KkL37auI5GyCU=
	sha1:+4cJPRCzjui5iT2oL/gh1WrQNFo= sha256:mekuD0p+IY51hOlAbxjGlkdUER6Gr9eWLTWjsPq7F1Y=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 8F6D9112BCC; Wed,  4 Nov 2026 15:55:59 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 8pGEyEOMs5yO;
	Wed,  4 Nov 2026 15:55:56 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-356432-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id BA7C0112BC2; Wed,  4 Nov 2026 15:55:47 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 1D2F230D52; Wed,  4 Nov 2026 12:53:41 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793796819;
	b=DO3uPZMT0N8GzhYwp6g1dOGQ6DgQUEZ5H24r/+iCr4hITg3vtN7lAJ+J3qNu9dY7rw9L
	 4ARSR2BlA0YKYI0tAXobWYqeO6ZOlXd0Mr5MX7CZq68C/dya9DngsaHqaqBWgmK1mvFEy
	 SVVSCCBDxPcxEGVrcke2pN8UlmZdQkfv7t7f2veWvfYgva73lYko5b0q/O8fdW2gIug+V
	 x8tKnPGovfZD2p2SfFPCFAgVyOsfbEW5w08ti0sfUExVt+wr1BycLsE/BLlY9mGw0TZhj
	 hs2Nkw9KVGl0gvb74qwfEJuXeosgg4EujtXsAx70eaVWGvFLQe/38RZe79FRuE6nmrw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793796819;
	h=X-Original-To:Received:Received:DKIM-Signature:Content-Type:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Message-Id:
	 In-Reply-To:References:Subject:From:To:Cc:Date;
	bh=N63fQTTLR34VDWJCWhrfa1n6ElIwxBuDp0fIP83L2jY=;
	b=37S5kbber3CMmdS8L51Pekba8bChFgNcAkah5crjrrKk4Jxm+kPtK6RjOHya+9Rq8B/F
	 fa9uAYQzHYXg93cwnDssSu/201yArseoD5ofpaSUGDFWzdM4ptwo3i6mhzuhdHJ7CRlz+
	 cGw9U181T/13mZAohMbQIYs4EmyqSKxWLi/J/Gj5B2EGswTubrGSrqHTQHPdaKKgpr8E1
	 twAMAMSZ0JO4m32bfomCXavDL39NNVpgt2/00RTeRDR62b7N7YdrkIljJtnKoJdimjGk8
	 cPZ3h5kniqVLe15XMrV23hcfDsuudw23OHZPnZKrLCE5MxsHBLJWbnGEJoi7BH0Qc5A==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GGO7lYRO;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id A090D606A338;
	Wed,  4 Nov 2026 12:53:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GGO7lYRO
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793796816;
	b=fX3cOLoHEDhHX7E6eWYqIhBdddkYh6JbU1Sls/UVCMyjQylgcc6PsDI88+Jc1rEk4JQG
	 pJBVfD/SgY/qXZRMPr8UMa9LpkZnl0u1VepJW+Hw5Vc3AnVXCd+o6yGTA4dyVm4eY0wDj
	 0iuYEi4xtSuSfQscv+NTxmD9O0XWaj0KlryIwumTOQz96WROCsVQkckmXZYvJ3QGVrbT+
	 1emrog9BcIT7Dp7pDCiBmfixa9KAh9bMZP4Ec98A3NuXTnDG4p4Hdz3MOJLX+Njk3bmag
	 W/rYeih2GNh/EIGZvsEJpyWiMAr2HL0xMNssoMnHawr/LaYbwUefNc1eUouHGvf0r8g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793796816;
	h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id:
	 In-Reply-To:References:Subject:From:To:Cc:Date;
	bh=N63fQTTLR34VDWJCWhrfa1n6ElIwxBuDp0fIP83L2jY=;
	b=u+SUoHQyXe5dtrQRe7T4uOy3glIQbLCqNA4Fucmn8qk1J5XWlKpn9YZaNFqcE4BcnXAa
	 tcEzO0S2qHdvGH2cSXWOOTKdW0uAbO8t1elpmlciRSmjAx13nViM53UjiCJQrH3T+GKPz
	 3IdbZCIz5EfqGEjWH03FsHtil+ve1PSVxmPT8RLeIe/AOFoSupx6kr0hR6ySoEMzZx9RO
	 kh9bIfq1npLWtDFDpCbElNT9o7+CCD1l6kzWO4EXxEAadCijHZbQppqNblGDDZKuxbWwn
	 6YvSmAYXvHCCM5BbQxEYqBaeQ+1pLxXMsPvT/5xhRNM4xCiEoEYtCWr0A0+xZHco+vg==
X-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=GGO7lYRO;
	arc=none smtp.remote-ip=100.103.45.18
X-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 3FBDC606A329;
	Wed,  4 Nov 2026 12:53:35 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6475A1F000C1;
	Wed,  4 Nov 2026 12:53:35 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793796815;
	bh=N63fQTTLR34VDWJCWhrfa1n6ElIwxBuDp0fIP83L2jY=;
	h=In-Reply-To:References:Subject:From:To:Cc:Date;
	b=GGO7lYROT+GSqzD8kuSJi57ZWaQVxilB6wZYAcudClbYx2l/ZMnRAon5YHphb80iF
	 As+KCaS+AeYXL4Y7UETG+mP67e1NdtDfpcrvnDy6EgmG18rcW5v2jctKLNNufpD3Uu
	 E0cwPTE9mR1eXzhFo4qTpk/ynpEweD89sIAymr2ffcK+cF0qKIyxxCyWrm84yw4fV4
	 vfZqqSzzkx7FplQZeYvpXeRkEG/BuihtYOnU5y6G2fcC2CfULCfOkT73VunillDddN
	 fx2c8mcoT32uOf/ry19l6eHc8A+Tb/FsxowFco39yPRH88Z6RwaYSZzWkUaZdCf/tZ
	 HhZ8nWytzrQhA==
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261104121316.1155680-2-sst@poczta.fm>
X-Cc: netdev@vger.kernel.org,bpf@vger.kernel.org,magnus.karlsson@intel.com,aleksander.lobakin@intel.com,ilias.apalodimas@linaro.org,toke@redhat.com,lorenzo@kernel.org,ihor.solodrai@linux.dev,tavip@google.com,maciej.fijalkowski@intel.com,sst@poczta.fm,syzbot+ff145014d6b0ce64a173@syzkaller.appspotmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev