diff --git a/net/core/filter.c b/net/core/filter.c index e713a8791815..cc4d660aafe1 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2360,7 +2360,10 @@ BPF_CALL_4(bpf_msg_pull_data, * had a single entry though we can just replace it and * be done. Otherwise walk the ring and shift the entries. */ - shift = last_sg - first_sg - 1; + WARN_ON_ONCE(last_sg == first_sg); + shift = last_sg > first_sg ? + last_sg - first_sg - 1 : + MAX_SKB_FRAGS - first_sg + last_sg - 1; if (!shift) goto out;