Skip to content

Commit 07a4c11

Browse files
zzhan461gregkh
authored andcommitted
bpf: Reject fragmented frames in devmap
commit aa49672 upstream. Devmap broadcast redirects clone the packet for all but the last destination. For native XDP, that clone path copies only the linear xdp_frame data, while fragmented frames keep skb_shared_info in tailroom outside the linear area. Cloning such a frame leaves XDP_FLAGS_HAS_FRAGS set but without valid frag metadata, and the later free path can interpret uninitialized tail data as skb_shared_info, leading to an out-of-bounds access during frame return. Reject fragmented native XDP frames in dev_map_enqueue_clone(). Add the same restriction to the generic XDP clone path in dev_map_redirect_clone(). Generic XDP represents fragmented packets as nonlinear skbs, and rejecting them here keeps clone-based broadcast support aligned between native and generic XDP. Fixes: e624d4e ("xdp: Extend xdp_redirect_map with broadcast support") Cc: stable@kernel.org Reported-by: Yuan Tan <yuantan098@gmail.com> Reported-by: Zhengchuan Liang <zcliangcn@gmail.com> Reported-by: Xin Liu <bird@lzu.edu.cn> Assisted-by: Codex:GPT-5.4 Signed-off-by: Zhao Zhang <zzhan461@ucr.edu> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com> Link: https://lore.kernel.org/r/21c2d153dd25603d359069a02bf06779b51f6423.1780385378.git.zzhan461@ucr.edu Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent faeeb28 commit 07a4c11

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

kernel/bpf/devmap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ static int dev_map_enqueue_clone(struct bpf_dtab_netdev *obj,
552552
{
553553
struct xdp_frame *nxdpf;
554554

555+
/* Frags live outside the linear frame and cannot be cloned safely. */
556+
if (unlikely(xdp_frame_has_frags(xdpf)))
557+
return -EOPNOTSUPP;
558+
555559
nxdpf = xdpf_clone(xdpf);
556560
if (!nxdpf)
557561
return -ENOMEM;
@@ -697,6 +701,9 @@ static int dev_map_redirect_clone(struct bpf_dtab_netdev *dst,
697701
struct sk_buff *nskb;
698702
int err;
699703

704+
if (unlikely(skb_is_nonlinear(skb)))
705+
return -EOPNOTSUPP;
706+
700707
nskb = skb_clone(skb, GFP_ATOMIC);
701708
if (!nskb)
702709
return -ENOMEM;

0 commit comments

Comments
 (0)