From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.74.67.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795773712; b=OgmTF5C98lCt3UwjhBJ/1+4sKpg/KTYOcTFgteBOCnZ8VDjJtBAjlljfhvQnGzpf+NHo RTHHzT8zz2oDvTx/iBrD25FbHAxpSDMRae5G5yUT4m8kT2DC7iwXbo/lU847mytbq6woJ xjb0tlRbtp2nY+hoWT/deZkQR8kCdv+fAFOeyyhFA3miRCwOmnm2gzwipOd1Z48Z+RDor kiGOlZX7d0Tj4nK04duZQJGt9oxa7XyQ3efuO0z+0xv5RN2MGPVzQSVjsMLE/HMqmtr3F FRcuDiblo9kANkai/g3XHsys1X6BlmV6Vc6UI7+DCJp2hzT/FDKYq7UTSnDL1/Onc7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795773712; 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=nMKkdiZF64BDuzBUvIlqX1y3Kl82ia4qMvsdvn6S/iU=; b=0zjX/5IFW9yW/cLRRGNjBFJPhRL7ZfxBckLvyeEae20WpDnd6/4cJ4MaYuUbkCxaHOvQ V4eOk1wTumuMSq5KKfc9YrEFgqROij7GZ3WaqUisl6kw6v0sOluEZH+w1YbDWK+KfucfA YSbl8NDh2+lJCa+ThOTPZdzwAW6ejhh1u5YlT4oPNTku+uYAZhxVsTP7aLhEKmBMi4RBG ssqgI898H0fBJ+7snyk4xL11fSJmQvIsFHtnswaggEFHbykP05UOeNWl5XnRjvFYu82xH mi6+q2jL8ZNQpV142ceMg9S6hk4/XTbI0RqiXbbIxEdhiJ3TXLXSxWBRkUf98ohBrig== 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="v/8AbKVN"; arc=none smtp.remote-ip=217.74.67.49 Received: from smtpo49.interia.pl (smtpo49.interia.pl [217.74.67.49]) (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 56F46606A32F for ; Fri, 27 Nov 2026 10:01:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 56F46606A32F 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=v/8AbKVN 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; Fri, 27 Nov 2026 11:01:40 +0100 (CET) From: Slawomir Stepien To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, Jiayuan Chen , Dudu Lu , Maciej Fijalkowski , Tianyi Gao , Octavian Purdila , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Alexander Lobakin , Lorenzo Bianconi , Lorenzo Bianconi , Ihor Solodrai , Andrew Lunn , Willem de Bruijn , 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 , syzbot+ff145014d6b0ce64a173@syzkaller.appspotmail.com, syzbot+237bbeed8dfe0699b7f5@syzkaller.appspotmail.com, stable@vger.kernel.org Subject: [PATCH net v9 1/6] xdp: run generic XDP on frags with a copy of the rxq info Date: Fri, 27 Nov 2026 11:01:27 +0100 Message-ID: <20261127100132.1977890-2-sst@poczta.fm> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261127100132.1977890-1-sst@poczta.fm> References: <20261127100132.1977890-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=1795773704; bh=nMKkdiZF64BDuzBUvIlqX1y3Kl82ia4qMvsdvn6S/iU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=v/8AbKVNkjyXEj5WFPskbma/LS0YcpIOfpaO3dvr3GtIH8fG5OIgcJ0r7PihLrf2r PjMbZwxgsJJ2DTw2gsdEWlmaT99z6pp3CkgnOplNAOre555XCacHSsLQNBoQdSfR2M KxEz4oquPC4X+8PyR84MkdYCW6RpQY+AoqU8KXIc= Since commit e6d5dbdd20aa ("xdp: add multi-buff support for xdp running in generic mode") generic XDP copies a non-linear skb into page_pool memory with skb_pp_cow_data() and gives the program its frags. The program still runs with the rxq info of the device queue, dev->_rx[i].xdp_rxq, which never has a memory model, so its mem type is MEM_TYPE_PAGE_SHARED. When the program shrinks a frag away with bpf_xdp_adjust_tail(), bpf_xdp_shrink_data() frees the page_pool page with page_frag_free(): BUG: Bad page state in process ping pfn:1f3ae page dumped because: page_pool leak and a later free of the same page can hit VM_BUG_ON_PAGE() in page_frag_free(). The mem type cannot be set in dev->_rx[i].xdp_rxq: it is shared by all CPUs that receive on that queue and by BPF_PROG_TEST_RUN, which borrows the rxq info of lo's queue 0. For a non-linear skb, run the program with a copy of the rxq info on the stack that says MEM_TYPE_PAGE_POOL. The frags of such an skb always come from skb_pp_cow_data(): when the copy is not possible, the skb is linearized instead. The program cannot free the head, so its memory does not matter here. The copy goes out of scope when the function returns, so point xdp->rxq back to the device rxq info after the program ran. Fixes: e6d5dbdd20aa ("xdp: add multi-buff support for xdp running in generic mode") Reported-by: syzbot+ff145014d6b0ce64a173@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=ff145014d6b0ce64a173 Reported-by: syzbot+237bbeed8dfe0699b7f5@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=237bbeed8dfe0699b7f5 Suggested-by: Alexei Starovoitov Link: https://lore.kernel.org/all/DN3QVHST3PUQ.3NINFUW0FL9IW@gmail.com/ Cc: Signed-off-by: Slawomir Stepien --- net/core/dev.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index cd0796a1dbfd..8f2e8c90951b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5686,6 +5686,7 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, void *orig_data, *orig_data_end, *hard_start; struct netdev_rx_queue *rxqueue; bool orig_bcast, orig_host; + struct xdp_rxq_info rxq; u32 mac_len, frame_sz; __be16 orig_eth_type; struct ethhdr *eth; @@ -5709,6 +5710,13 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, if (skb_is_nonlinear(skb)) { skb_shinfo(skb)->xdp_frags_size = skb->data_len; xdp_buff_set_frags_flag(xdp); + /* + * The frags came from skb_pp_cow_data(). xdp_rxq is shared + * with other CPUs and with BPF_PROG_TEST_RUN, so use a copy. + */ + rxq = rxqueue->xdp_rxq; + rxq.mem.type = MEM_TYPE_PAGE_POOL; + xdp->rxq = &rxq; } else { xdp_buff_clear_frags_flag(xdp); } @@ -5721,6 +5729,7 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, orig_eth_type = eth->h_proto; act = bpf_prog_run_xdp(xdp_prog, xdp); + xdp->rxq = &rxqueue->xdp_rxq; /* check if bpf_xdp_adjust_head was used */ off = xdp->data - orig_data; base-commit: e9e45fcb6d39bee9325e6a7dca72bd14e82760f3 -- 2.56.0