Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3294574pxf; Mon, 5 Apr 2021 08:19:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVKsOf+W4oAVvJXxzRWUxyYKie/6zyboexlWSfythxYUROQQ/BnFkODgGDH0N/7d8uQF7J X-Received: by 2002:a5d:9659:: with SMTP id d25mr20758094ios.146.1617635966505; Mon, 05 Apr 2021 08:19:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617635966; cv=none; d=google.com; s=arc-20160816; b=M6aAk/GnZLuQbvFp+cZaEJFIlXYCVbpKVfHUl9M8r8IV9QW5nwpg7lmwNECX+83c5r 5JD1EgcrD9zluHjfpaFrJ07MKGQgr8mpiTjbMMpnrDRuohr9TMHFLkp1hgptjvrSHxVW 1HmyILGcTX5MeBQayhu75FWWxdaSjnQfsLRfzrc3Y+IpUVOOGCTVcIPmyXWCQuXgE3gW Ns4pZIov3LVhhAoQF+rnlXslUMTA1bZzBuTK6h4C1C+xPenQp4wx6NthtR8ORvzbRfaG OGDVPCazcFjiSCaJzbZ6z/gqMrh4M38FAe9qy11DsvTeBlKRA9KX7CBDqi/uNFkUSMiQ u1jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6QECNRTVpSbYl649vVDxj5PSat9g2DgsLZwWsgQwEOg=; b=TaPI7Ql9pRSe94/yT7FbEGT3XOG54BXPo6VtXH7BzPLR/PTN2LiKfLAgpEcP3vXWW6 o3ZczvElvW+iWSFkY+EwabEKoQDGzCjFT6pnMGQ2BSsVSvCEx67MOL1QndAvbXXe2czX 4oIOYR4/BBBO9yGXZhwouTJfa3ileZHWeLJRQEafW62jIFzSSvwgYW9E9jXZ6u3Tx9/t yF1QHeMiThCUVqFDh4fMWghnonZRyaTxgC024SeB38t/K9AXjl6W4MsVL/9uTHrLsLOI 2z9Oaa0ggiSHfIlki0kKWu/LwRl6SvILptZTmyD8MmxaKm3mlZ737yoIa8T0zQBFcx/8 x8rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rWikiPvH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si15658745ilb.14.2021.04.05.08.19.14; Mon, 05 Apr 2021 08:19:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rWikiPvH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238235AbhDEJHB (ORCPT + 99 others); Mon, 5 Apr 2021 05:07:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:47878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237992AbhDEJES (ORCPT ); Mon, 5 Apr 2021 05:04:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E635461002; Mon, 5 Apr 2021 09:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617613451; bh=8KeXSvtHgsaAt/26fIRSDfLM24pZXOV/U75wzXh7Vek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rWikiPvH+yg3OS46QmLS7A+n2jjwOlDEE5DvqKZWc0XSmNQyMa87s13LRZXbJ6QH6 6axGGmnYHJzC8/Lnu7s3GacRFfO4P9Iu8arDS2kU+bB/qTHH4kHBOMeZLlf/MtW+Of 4ll5Uffci3l7z+sV8zT5na7nl7Q8PIfZT45SySqc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jesper Dangaard Brouer , Daniel Borkmann , John Fastabend Subject: [PATCH 5.4 40/74] bpf: Remove MTU check in __bpf_skb_max_len Date: Mon, 5 Apr 2021 10:54:04 +0200 Message-Id: <20210405085026.037875868@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210405085024.703004126@linuxfoundation.org> References: <20210405085024.703004126@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jesper Dangaard Brouer commit 6306c1189e77a513bf02720450bb43bd4ba5d8ae 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 Signed-off-by: Daniel Borkmann Acked-by: John Fastabend Link: https://lore.kernel.org/bpf/161287788936.790810.2937823995775097177.stgit@firesoul Signed-off-by: Greg Kroah-Hartman --- net/core/filter.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3146,18 +3146,14 @@ static int bpf_skb_net_shrink(struct sk_ return 0; } -static u32 __bpf_skb_max_len(const struct sk_buff *skb) -{ - return skb->dev ? skb->dev->mtu + skb->dev->hard_header_len : - SKB_MAX_ALLOC; -} +#define BPF_SKB_MAX_LEN SKB_MAX_ALLOC BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *, skb, s32, len_diff, u32, mode, u64, flags) { u32 len_cur, len_diff_abs = abs(len_diff); u32 len_min = bpf_skb_net_base_len(skb); - u32 len_max = __bpf_skb_max_len(skb); + u32 len_max = BPF_SKB_MAX_LEN; __be16 proto = skb->protocol; bool shrink = len_diff < 0; u32 off; @@ -3237,7 +3233,7 @@ static int bpf_skb_trim_rcsum(struct sk_ static inline int __bpf_skb_change_tail(struct sk_buff *skb, u32 new_len, u64 flags) { - u32 max_len = __bpf_skb_max_len(skb); + u32 max_len = BPF_SKB_MAX_LEN; u32 min_len = __bpf_skb_min_len(skb); int ret; @@ -3313,7 +3309,7 @@ static const struct bpf_func_proto sk_sk static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room, u64 flags) { - u32 max_len = __bpf_skb_max_len(skb); + u32 max_len = BPF_SKB_MAX_LEN; u32 new_len = skb->len + head_room; int ret;