Skip to content

Commit fd38d4e

Browse files
netoptimizergregkh
authored andcommitted
bpf: Remove MTU check in __bpf_skb_max_len
commit 6306c11 upstream. Multiple BPF-helpers that can manipulate/increase the size of the SKB uses __bpf_skb_max_len() as the max-length. This function limit size against the current net_device MTU (skb->dev->mtu). When a BPF-prog grow the packet size, then it should not be limited to the MTU. The MTU is a transmit limitation, and software receiving this packet should be allowed to increase the size. Further more, current MTU check in __bpf_skb_max_len uses the MTU from ingress/current net_device, which in case of redirects uses the wrong net_device. This patch keeps a sanity max limit of SKB_MAX_ALLOC (16KiB). The real limit is elsewhere in the system. Jesper's testing[1] showed it was not possible to exceed 8KiB when expanding the SKB size via BPF-helper. The limiting factor is the define KMALLOC_MAX_CACHE_SIZE which is 8192 for SLUB-allocator (CONFIG_SLUB) in-case PAGE_SIZE is 4096. This define is in-effect due to this being called from softirq context see code __gfp_pfmemalloc_flags() and __do_kmalloc_node(). Jakub's testing showed that frames above 16KiB can cause NICs to reset (but not crash). Keep this sanity limit at this level as memory layer can differ based on kernel config. [1] https://github.com/xdp-project/bpf-examples/tree/master/MTU-tests Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/161287788936.790810.2937823995775097177.stgit@firesoul Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ff64f33 commit fd38d4e

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

‎net/core/filter.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,11 +3552,7 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff,
35523552
return 0;
35533553
}
35543554

3555-
static u32 __bpf_skb_max_len(const struct sk_buff *skb)
3556-
{
3557-
return skb->dev ? skb->dev->mtu + skb->dev->hard_header_len :
3558-
SKB_MAX_ALLOC;
3559-
}
3555+
#define BPF_SKB_MAX_LEN SKB_MAX_ALLOC
35603556

35613557
BPF_CALL_4(sk_skb_adjust_room, struct sk_buff *, skb, s32, len_diff,
35623558
u32, mode, u64, flags)
@@ -3605,7 +3601,7 @@ BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *, skb, s32, len_diff,
36053601
{
36063602
u32 len_cur, len_diff_abs = abs(len_diff);
36073603
u32 len_min = bpf_skb_net_base_len(skb);
3608-
u32 len_max = __bpf_skb_max_len(skb);
3604+
u32 len_max = BPF_SKB_MAX_LEN;
36093605
__be16 proto = skb->protocol;
36103606
bool shrink = len_diff < 0;
36113607
u32 off;
@@ -3688,7 +3684,7 @@ static int bpf_skb_trim_rcsum(struct sk_buff *skb, unsigned int new_len)
36883684
static inline int __bpf_skb_change_tail(struct sk_buff *skb, u32 new_len,
36893685
u64 flags)
36903686
{
3691-
u32 max_len = __bpf_skb_max_len(skb);
3687+
u32 max_len = BPF_SKB_MAX_LEN;
36923688
u32 min_len = __bpf_skb_min_len(skb);
36933689
int ret;
36943690

@@ -3764,7 +3760,7 @@ static const struct bpf_func_proto sk_skb_change_tail_proto = {
37643760
static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,
37653761
u64 flags)
37663762
{
3767-
u32 max_len = __bpf_skb_max_len(skb);
3763+
u32 max_len = BPF_SKB_MAX_LEN;
37683764
u32 new_len = skb->len + head_room;
37693765
int ret;
37703766

0 commit comments

Comments
 (0)