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=1796385120; b=BBozOvEds8dab7HBQXFAAZRIuSssmdj++PhsMyDuz2oCR3/0M641AA9JGhWpr/9DcL0h +zlmmlzcy8aX+X09XVaHDQ5ZFvqWhOAP4miXsnoCN+7apijo1Umvp3xvS8b+Sryx4Hv9k LIESX55sUOJ7LUm7PIDLXm+FGFb2J7vKYOLwkZhJavyUrS8LZGmJfXIcuykf5IraEid0l d1olISK7iG2I4KmkYk19HJz4+iSq1i2TblYzKKNZ7L5sLSeXp7Fy+Ii8JBBKUcEKXe4s/ mZYmUpbqkhTBbdK288AQpYFgQFQiH/TkG5CROb67kl+MaBgoxDV3wWGCYshNrz8hutw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385120; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=C1M2+UO/jPbeTWr9ZhzPAuT5Yw5uXStEN0MyNc7d2T4=; b=EJcMrVczEZapAuY9N2m4Uq2psThSItYLt/9aUxOR2CGeSp7cxgrXcDaWiGfNk7sn4x+p cd/RfX0uZgkAXOT0n2ACjLu6X65yDc3haExzMgJ3BrosBrF2pSSlBpYfOtaZxbvZiznYY hDM9T13Hq/ZVwDRMh/6uyWeCEXqwq9n9Llyu1kuCKyjiR270yPebs/I0XLzNYf+LM4LQ7 tKAR7eRL4SLEd8vnx7VCc4LkDGypY6JMjxj/Ufg57yBjWi+cq0/giPw0BecKK/tdklKvx aY0Ji7bBVI4CbzzfJdU79iYZJY2FVW79LCtwo6acEYReZRURnCKbcVwqJwATYl/peDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ePc2Xp1S; 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 EE6BC606A330; Fri, 4 Dec 2026 11:51:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ePc2Xp1S Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F38F1F00935; Fri, 4 Dec 2026 11:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385119; bh=C1M2+UO/jPbeTWr9ZhzPAuT5Yw5uXStEN0MyNc7d2T4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ePc2Xp1S6DYXqdRzmXVRHBh5XO5sX95VEUq49tOIPnVwYY3Is2cw0AMM1S4/F8mEE 5x/EhuzGyW1Ga7ORez4T4s4YbrgK3Dbt64WYJh1TpvfIx1k7kAyY57i8zpa63R8q8H 4rva7dfnhS/Ck11GCR9q0vJCvH+l/GBYic/hYg8U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.6 0427/1167] bpf: Use the frame mem type in devmap egress XDP Date: Fri, 4 Dec 2026 18:57:34 +0900 Message-ID: <20261204100713.141617662@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit b3ca872947ef322c475ceaa7a76a9ebb3356152e ] A devmap egress program that removes a whole fragment of a redirected xdp_frame with bpf_xdp_adjust_tail() or bpf_xdp_pull_data() frees it with page_frag_free() whatever the frame's memory type is. For a MEM_TYPE_PAGE_POOL frame from a page_pool based driver this drops the page reference owned by the pool while the pool still accounts the fragment ("page_pool leak" bad page, leaked pp reference). kernel/bpf/devmap.c:dev_map_bpf_prog_run() points xdp.rxq at an on-stack struct xdp_rxq_info rxq = { .dev = rx_dev }; whose mem.type is 0, i.e. MEM_TYPE_PAGE_SHARED, and net/core/filter.c:bpf_xdp_shrink_data() releases frags according to rxq->mem.type. cpumap, which runs programs on xdp_frames the same way, already copies xdpf->mem_type into its private rxq for each frame. With 9000 byte frames from virtio_net and an egress program that cuts the fragments off: BUG: Bad page state in process swapper/3 pfn:10660b page dumped because: page_pool leak bad_page+0xbd/0x190 __free_frozen_pages+0x5c7/0x900 bpf_xdp_adjust_tail+0x3be/0x480 bpf_prog_dad43f894a3faff7_egress+0x15c/0x1cd dev_map_bpf_prog_run+0x288/0x610 The pool waits for these pages for ever when its device is gone. That is the harmless case. A page of the pool can hold more than one fragment while its refcount is 1: the first page_frag_free() frees it under the fragment which is still in use, and the second one runs into page dumped because: VM_BUG_ON_PAGE(page_ref_count(page) == 0) kernel BUG at include/linux/mm.h:1846! veth is not affected. It takes references of its own on the pages and redirects the frame as MEM_TYPE_PAGE_SHARED. Fix by setting rxq.mem.type from each frame before running the devmap program, as cpu_map_bpf_prog_run_xdp() does. Fixes: ca9984c5f0ab ("bpf: devmap: provide rxq after redirect") Signed-off-by: Josef Bacik Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261017163745.3341787-2-alexei.starovoitov@gmail.com [ sashal: Changed rxq.mem.type = xdpf->mem_type to rxq.mem = xdpf->mem, since this tree's xdp_frame has no mem_type field and keeps the whole xdp_mem_info struct. ] Signed-off-by: Sasha Levin --- kernel/bpf/devmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index 8ce3b152dcd5b..f4cc948a7b86f 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c @@ -337,6 +337,7 @@ static int dev_map_bpf_prog_run(struct bpf_prog *xdp_prog, xdp_convert_frame_to_buff(xdpf, &xdp); xdp.txq = &txq; + rxq.mem = xdpf->mem; xdp.rxq = &rxq; act = bpf_prog_run_xdp(xdp_prog, &xdp); -- 2.53.0