Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3325785pxf; Mon, 5 Apr 2021 09:05:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu5CMAyHIJkOasLakZioF6+CG1gfMvq78rkMsJ+FftF/56m+mIr0NdKopQf2gBk/FGp/1T X-Received: by 2002:a17:906:8470:: with SMTP id hx16mr16498183ejc.153.1617638729266; Mon, 05 Apr 2021 09:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617638729; cv=none; d=google.com; s=arc-20160816; b=Y7vVI1TrDH3yw+gCBab0/bX418N0Q/2aVGGfU6KZQ/+j8H//pbebQtKHljUfECNoA/ R4iY5Uupqy0cVTupBF9sq9lIkd8EMoURfVEDU9y5EOcv4STNbFbfiH8GTejCvu21ScSr g+0d6VKkqcaKoDGdveRhGJsFvc9nk38geKvUo6ipoS6rFuRtFJTMLa422rD+VkOPDGAI lmmqgKBrIQu2gK7ORENo2cz0u8vIFwH5g1dOhiECgHwm4gJzEylE1B9tHp/HRQKb3HJu h/kUymzH8WccsFXoRoqSXQ8l7JhE2z0k/SlC4DicIvnn5qZIkA6x4rPAfl0XaD2BMV6u cI7g== 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=RoRuR3SDIeKUc9gxPSyFKfRqiNEd+CGsByE7lR0ELXI=; b=RYKDN1z7mxpYJm2+KOMIUoKPPgmx1AXug88/j3T+zal4BRmRR1EL7bmYJQ0ujGuhaB CuopuFFGJP0zf6H4Y2kBVeIBiXw6y3l7FOJgXSXbHylbaLZVWW8zbeZuBhZcflMaPjMN kgHiRhJw2wJvd2Nk8jcjBNj8bAv48DieKL1JQH30XDkb3TTFW2a6q7Xf9YUG/8FS4Lqz K0cZ46JPd/lYhKVpJM04f7UFruvkMCI0dKUc5eAdt+7UwULSx0/kP6XsSDk9RrvZC29+ ySJ/0plPd8eWX/ZDRCTtiwKkXQcLDKn1+Nz2rgtCWIZBOi9DOlPpKpNCOZAuTVJ+4gFK Batg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uPKDKqol; 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 v24si5119490ejo.143.2021.04.05.09.05.04; Mon, 05 Apr 2021 09:05:29 -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=uPKDKqol; 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 S239423AbhDEJKp (ORCPT + 99 others); Mon, 5 Apr 2021 05:10:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:53726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238554AbhDEJIN (ORCPT ); Mon, 5 Apr 2021 05:08:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B01F661399; Mon, 5 Apr 2021 09:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617613685; bh=S0Vfaw5rbZr012OmTUTy7ewL1yKR2z1XwDNrD6hVT/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uPKDKqolsG0mgFYwWNYRqG+sVNHli3tv4xC4/P3478v4nSgdxW5h2DpZrMn28ZVSM 7mNtjaMZvmyYOLf+Za6GvjBLlLYg798GDzNXaYQW7DMpLB5W7XtrXx0lH19GwlrxLW cddiL78AACVYRqtNedSOlVN7xmG1RVaaBQoN78Uo= 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.10 054/126] bpf: Remove MTU check in __bpf_skb_max_len Date: Mon, 5 Apr 2021 10:53:36 +0200 Message-Id: <20210405085032.816572861@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210405085031.040238881@linuxfoundation.org> References: <20210405085031.040238881@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 @@ -3552,11 +3552,7 @@ 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(sk_skb_adjust_room, struct sk_buff *, skb, s32, len_diff, u32, mode, u64, flags) @@ -3605,7 +3601,7 @@ BPF_CALL_4(bpf_skb_adjust_room, struct s { 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; @@ -3688,7 +3684,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; @@ -3764,7 +3760,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;