From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.74.67.75 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795516835; b=dbgLnTPnv6YLune547bav9ewKbPb+kgkKh/yEgQlEcbU8Oj1aTWLnE1kpjMRHN5KvWRa Z+CZy/uW4NxYi1zXu41Z8XBwpbJ1z6s+57zhG5Y/MZfXxWsULRBI1n9gKiMJQ9w4pfZpC 4CQgpbAHzoOzOiCD/LGU7sN/fbXGngxMqGG6qcDrG6oSmgTHZfQ9QBXg/x+vTjGBJjcMr YzQYExlDoGgGhdXGVQ2N4+vyVrYhTbsTiOmuFDSfHW6H472QHW3uOL92zOpOfthvAqDv4 ouizI0v2qMHYnJY0rUGFUR2yLyWK9NUMJOyan/dNePsBUneDNCDaleEMWbrw5bi6n5A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795516835; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: DKIM-Signature; bh=/6dSyAvYrkzZrB+rNJ+F7xck+uglAdRkmahkz9MM2p4=; b=0tTrVY8zGvv0/WMVHYcnBofbzahS+nvrbADgh5B3O0lO6BGvi93qNHeFE+gZcKUc0l/K cu8S09f7dObDjxO3LeOega5Jb/NemmX3Y43uYb0GEH7dMxLJIbbhXPgOruVLsJEiZDFhS 7f/h/3XWpQsygad/MMym6Saak6btkAVMD9e1gkfOJDGnLcVFnj3Z9tfML6OxBpM4DvyQq dbNtBiPElPHHzLKE91zJAyJ6GUgk5GN4Hqad/ZU6DM8PY7Cso5zlP4twifLwMZyCkpORg hCCeZqVlHO7dpya4F7b9z/mtIXAFLVM1+24rZHMG1QcXrug9gFEBFvZMXtPGmfsFFbA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=poczta.fm; spf=pass smtp.mailfrom=poczta.fm; dkim=pass header.d=poczta.fm header.i=@poczta.fm header.a=rsa-sha256 header.s=dk header.b=DaxkLhMM; arc=none smtp.remote-ip=217.74.67.75 Received: from smtpo75.interia.pl (smtpo75.interia.pl [217.74.67.75]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 387F2606A6A0 for ; Tue, 24 Nov 2026 10:40:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 387F2606A6A0 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=poczta.fm Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=poczta.fm Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=poczta.fm header.i=@poczta.fm header.a=rsa-sha256 header.s=dk header.b=DaxkLhMM Received: from localhost (unknown [80.68.231.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by poczta.interia.pl (INTERIA.PL) with ESMTPSA; Tue, 24 Nov 2026 11:40:24 +0100 (CET) From: Slawomir Stepien To: Alexei Starovoitov , Daniel Borkmann , "David S . Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Maciej Fijalkowski , Tianyi Gao , Octavian Purdila , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Alexander Lobakin , Ilias Apalodimas , Lorenzo Bianconi , Lorenzo Bianconi , Magnus Karlsson , Ihor Solodrai , Eric Dumazet , Paolo Abeni , Andrew Lunn , Simon Horman , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , Jiri Olsa , Kumar Kartikeya Dwivedi , Emil Tsalapatis , Shuah Khan , linux-kselftest@vger.kernel.org, Slawomir Stepien , stable@vger.kernel.org Subject: [PATCH v8 bpf 1/7] bpf: test_run: Use a private rxq info for XDP test runs Date: Tue, 24 Nov 2026 11:40:10 +0100 Message-ID: <20261124104016.532341-2-sst@poczta.fm> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261124104016.532341-1-sst@poczta.fm> References: <20261124104016.532341-1-sst@poczta.fm> 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 Content-Transfer-Encoding: 8bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poczta.fm; s=dk; t=1795516828; bh=/6dSyAvYrkzZrB+rNJ+F7xck+uglAdRkmahkz9MM2p4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=DaxkLhMMN05JVK8MD95W1fNKay9sozcTpyFGOjZpb0bAMnWvjGGkicMZVulCO5QSg bDuOIyYYREKzX325Vf3v7wqH88YVhNi5/jVAiV9SnoC7WyTFRAvXy1HG4aQ0K+xWCu 8K2EHCx8r8E82J3c1yuHR4BQgqLf2nmkTmE8N3Ws= bpf_prog_test_run_xdp() runs the program with xdp->rxq pointing to the xdp_rxq_info of a real device queue: queue 0 of the loopback device, or the queue given by ingress_ifindex and rx_queue_index in the context. The frags of a multi-buffer test packet come from alloc_page(), and when the program releases one with bpf_xdp_adjust_tail() or bpf_xdp_pull_data(), __xdp_return() frees it according to xdp->rxq->mem.type. This only works as long as nobody else changes the mem type of that shared queue. A later patch in this series adds xdp_convert_skb_to_buff(), which makes generic XDP set the mem type of the queue it runs on to MEM_TYPE_PAGE_POOL, since frags it hands to the program come from skb_pp_cow_data(). After any packet went through generic XDP on lo, a later test run would free its alloc_page() frags as page_pool pages: WARNING: include/net/page_pool/helpers.h:305 at __xdp_return+0x828/0x9c0 Call Trace: bpf_xdp_adjust_tail+0x8a0/0xd10 bpf_prog_..._xdp_adjust_tail_shrink+0xe1/0x101 bpf_test_run+0x31a/0xc30 bpf_prog_test_run_xdp+0x948/0x1740 and leak the page. Restoring the mem type after generic XDP would not be enough, as generic XDP may run on the same queue on another CPU at the same time. Run the program on a private copy of the rxq info instead, with MEM_TYPE_PAGE_SHARED, which describes the memory test_run allocates. devmap and cpumap already do the same for the programs they run. The device and queue index stay the same, so the program sees the same ingress_ifindex and rx_queue_index, and xdp_convert_buff_to_md() still drops the device reference. Live frames mode does not allow frags and uses its own rxq info for the page_pool frames, so it is unaffected. No Fixes: tag, as nothing is broken until xdp_convert_skb_to_buff() changes the mem type; this goes to stable together with that patch. The problem was found by Sashiko AI review and BPF CI in the review of v6 of this series. Link: https://lore.kernel.org/all/sashiko-outbox-197255@kernel.org/ Cc: # 6.4.x Signed-off-by: Slawomir Stepien --- net/bpf/test_run.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index d6c9dc62182e..9bbd83ece67b 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -1348,6 +1348,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr, u32 repeat = kattr->test.repeat; struct netdev_rx_queue *rxqueue; struct skb_shared_info *sinfo; + struct xdp_rxq_info rxq; struct xdp_buff xdp = {}; int i, ret = -EINVAL; struct xdp_md *ctx; @@ -1426,6 +1427,15 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr, if (ret) goto free_data; + /* + * xdp.rxq points to the rxq info of a real device queue, which + * generic XDP updates for every packet it runs on. Use a private + * copy with the mem type of the frags allocated below. + */ + rxq = *xdp.rxq; + rxq.mem = (struct xdp_mem_info){ .type = MEM_TYPE_PAGE_SHARED }; + xdp.rxq = &rxq; + size = linear_sz; if (unlikely(kattr->test.data_size_in > size)) { void __user *data_in = u64_to_user_ptr(kattr->test.data_in); -- 2.56.0