bpf: devmap: reject cloning fragmented xdp frames
Subsystems (4)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 bpf: devmap: reject cloning fragmented xdp frames
From: Zhao Zhang <[email protected]>
Devmap broadcast redirects clone xdp_frame instances for all but the last destination. That clone path only copies the linear frame data, while fragmented XDP frames store skb_shared_info in tailroom outside the linear area.
As a result, broadcasting a fragmented xdp_frame leaves the clone with XDP_FLAGS_HAS_FRAGS set but without valid frag metadata. The later free path then treats uninitialized tail data as skb_shared_info, leading to an out-of-bounds access during frame return.
Reject fragmented frames in dev_map_enqueue_clone(). Devmap already uses -EOPNOTSUPP for unsupported XDP frag forwarding cases, and the current xdp_frame clone model cannot safely represent a cloned fragmented frame.
--- kernel/bpf/devmap.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/bpf/devmap.c +4 -0
@@ -581,6 +581,10 @@ static int dev_map_enqueue_clone(struct bpf_dtab_netdev *obj, {struct xdp_frame *nxdpf; +/* Frags live outside the linear frame and cannot be cloned safely. */ +if (unlikely (xdp_frame_has_frags (xdpf))) +return -EOPNOTSUPP ; + nxdpf =xdpf_clone (xdpf);if (!nxdpf)return -ENOMEM ;
Signature · 1 line
2.47.3
Quoted 34 lines · Ren Wei
From: Zhao Zhang <[email protected]>
Devmap broadcast redirects clone
xdp_frameinstances for all but the last destination. That clone path only copies the linear frame data, while fragmented XDP frames storeskb_shared_infoin tailroom outside the linear area.As a result, broadcasting a fragmented
xdp_frameleaves the clone withXDP_FLAGS_HAS_FRAGSset but without valid frag metadata. The later free path then treats uninitialized tail data asskb_shared_info, leading to an out-of-bounds access during frame return.Reject fragmented frames in
dev_map_enqueue_clone(). Devmap already uses-EOPNOTSUPPfor unsupported XDP frag forwarding cases, and the currentxdp_frameclone model cannot safely represent a cloned fragmented frame.Fixes e624d4ed4aa8 ("xdp: Extend xdp_redirect_map with broadcast support")Reported-by Yuan Tan <[email protected]>Reported-by Zhengchuan Liang <[email protected]>Reported-by Xin Liu <[email protected]>Assisted-by Codex:GPT-5.4Signed-off-by Zhao Zhang <[email protected]>Signed-off-by Ren Wei <[email protected]>--- kernel/bpf/devmap.c | 4 ++++ 1 file changed, 4 insertions(+)kernel/bpf/devmap.c +0
-0
kernel/bpf/devmap.c static int dev_map_enqueue_clone(struct bpf_dtab_netdev *obj, · line 587
Quoted 7 lines
kernel/bpf/devmap.c +4
-0@@ -581,6 +581,10 @@ static int dev_map_enqueue_clone(struct bpf_dtab_netdev *obj, {struct xdp_frame *nxdpf; +/* Frags live outside the linear frame and cannot be cloned safely. */ +if (unlikely (xdp_frame_has_frags (xdpf))) +return -EOPNOTSUPP ; +
I am OK with restricting this (the support can be restored when/if someone has a need for it), but we should add the same restriction to generic XDP (i.e., in dev_map_redirect_clone()), so the feature set doesn't diverge.
-Toke