bpf: free page_pool frags via the page_pool path in bpf_xdp_shrink_data - #13321
bpf: free page_pool frags via the page_pool path in bpf_xdp_shrink_data#13321kernel-patches-daemon-bpf[bot] wants to merge 1 commit into
Conversation
|
Upstream branch: a13307e |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 5305619814 via email |
3083173 to
6d6454e
Compare
|
Upstream branch: a13307e |
syzbot reported a "Bad page state ... page_pool leak" when a generic XDP program shrinks an skb into its frags on the tun write() path: page_frag_free __xdp_return bpf_xdp_shrink_data bpf_xdp_frags_shrink_tail bpf_xdp_adjust_tail When a program shrinks a whole frag, bpf_xdp_shrink_data() frees it via __xdp_return() using xdp->rxq->mem.type. For skb-backed XDP the skb is first rebuilt into page_pool memory (skb_cow_data_for_xdp() for generic XDP, skb_pp_cow_data() for veth), so the frag is a page_pool page. But the rxq was registered as MEM_TYPE_PAGE_SHARED, so __xdp_return() calls page_frag_free() on a page_pool page: its base refcount drops to 0 and the page is freed to the buddy allocator with pp_magic still set. The rxq mem model cannot be relied on here because the rxq is shared and does not describe the frag's real memory. The netdev generic rxq is used both by generic XDP (page_pool frags) and by bpf_prog_test_run_xdp(), which borrows the loopback rxq for plain alloc_page() frags; veth uses one rxq for cow'd (page_pool) skbs and for redirected frames of any memory type. A single rxq->mem.type can be wrong in either direction. The memory type is really a property of the page. Check the frag itself with netmem_is_pp() and return page_pool frags to their pool, keeping the rxq mem type only for non page_pool pages. The page_pool is taken from the page (netmem_get_pp()), so no rxq registration is involved. Fixes: e6d5dbd ("xdp: add multi-buff support for xdp running in generic mode") Fixes: 0ebab78 ("net: veth: add page_pool for page recycling") Reported-by: syzbot+237bbeed8dfe0699b7f5@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=237bbeed8dfe0699b7f5 Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
bed4b6e to
0d2956e
Compare
Pull request for series with
subject: bpf: free page_pool frags via the page_pool path in bpf_xdp_shrink_data
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1146649