From patchwork Tue May 11 06:36:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongseok Yi X-Patchwork-Id: 12249915 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7117C433ED for ; Tue, 11 May 2021 06:51:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8833E610FA for ; Tue, 11 May 2021 06:51:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbhEKGwH (ORCPT ); Tue, 11 May 2021 02:52:07 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:59571 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbhEKGwH (ORCPT ); Tue, 11 May 2021 02:52:07 -0400 Received: from epcas2p2.samsung.com (unknown [182.195.41.54]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20210511065059epoutp016fc31fadb469cf9a015e798bf61d17d1~98Hy9jdtN0716307163epoutp01W for ; Tue, 11 May 2021 06:50:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20210511065059epoutp016fc31fadb469cf9a015e798bf61d17d1~98Hy9jdtN0716307163epoutp01W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1620715859; bh=1ZZQwBOGeu8uekno2BLelsyca/RkRfVZ3WSZ6YzujrU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FYJbrrDwSm7hXgRCG/QXstKBSsaSp59HoLuhyCylpoGYoF29S9GsaCrBSRWK2Fffz b6hk4jm0gDDzrTDNRfXyTakLbDCbHeVxZbXhcpGPcWKYmlcUnpTiEUyMMzuArG+FzR cilrNRFZNIFxQRh4VH9Pc1UNrMQ9uuE1wnj6Z+3U= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20210511065058epcas2p1474564a69434b88d4767e643ad2e08b4~98HyNkJnm1838818388epcas2p1D; Tue, 11 May 2021 06:50:58 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.40.181]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4FfT8d4L6fz4x9Pq; Tue, 11 May 2021 06:50:57 +0000 (GMT) Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id 81.D1.09717.0592A906; Tue, 11 May 2021 15:50:57 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p1.samsung.com (KnoxPortal) with ESMTPA id 20210511065056epcas2p1788505019deb274f5c57650a2f5d7ef0~98HvxZexz1537715377epcas2p1V; Tue, 11 May 2021 06:50:56 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20210511065056epsmtrp1154f42734008e77b75124006a195c029~98HvvtR5r2914829148epsmtrp1b; Tue, 11 May 2021 06:50:56 +0000 (GMT) X-AuditID: b6c32a48-4e5ff700000025f5-6c-609a295067c4 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 3A.96.08637.F492A906; Tue, 11 May 2021 15:50:55 +0900 (KST) Received: from ubuntu.dsn.sec.samsung.com (unknown [12.36.155.120]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210511065055epsmtip23f9a9e7dd8a093cde3a8a426606b3c7f~98HvfyhHp0092600926epsmtip2E; Tue, 11 May 2021 06:50:55 +0000 (GMT) From: Dongseok Yi To: Willem de Bruijn Cc: Dongseok Yi , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf v2] bpf: check BPF_F_ADJ_ROOM_FIXED_GSO when upgrading mss in 6 to 4 Date: Tue, 11 May 2021 15:36:37 +0900 Message-Id: <1620714998-120657-1-git-send-email-dseok.yi@samsung.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1619690903-1138-1-git-send-email-dseok.yi@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplk+LIzCtJLcpLzFFi42LZdljTQjdQc1aCwYnfjBbff89mtvjy8za7 xecjx9ksFi/8xmwx53wLi8WVaX8YLZp2rGCyePHhCaPF8329TBYXtvWxWlzeNYfN4tgCMYuf h88wWyz+uQGoYskMRgd+jy0rbzJ5TGx+x+6xc9Zddo+uG5eYPTat6mTz6NuyitHj8ya5APao HJuM1MSU1CKF1Lzk/JTMvHRbJe/geOd4UzMDQ11DSwtzJYW8xNxUWyUXnwBdt8wcoLuVFMoS c0qBQgGJxcVK+nY2RfmlJakKGfnFJbZKqQUpOQWGhgV6xYm5xaV56XrJ+blWhgYGRqZAlQk5 GQsXLGMq+CRW0dC8nrGBcalQFyMnh4SAicSjJ0vZQWwhgR2MEr2rnLoYuYDsT0D226WMEM43 Ron29ReZYTomTz/FDJHYyygxY+IEqKofjBJ9jUdYQarYBDQk9r97AWaLCJhJbDxygwWkiF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BcjJ4eEgInE5OmnmEFsIYHdjBJHd7B2 MXIAxSUkdm12hSgRlrjfcgQozAVU8o1R4viGZ2D1bAIaEvvfvWAFsUUEzCQ2HrnBAlLELPCR WeLotbdMIAlhgQiJkx2zGEFsFgFViZZ9B8AaeAVcJaZtuMIEsUFO4ua5TrChnAIuEp9mfIA6 yFni3eFPLBMY+RYwMqxilEwtKM5Nzy02LDDMSy3XK07MLS7NS9dLzs/dxAgOay3NHYzbV33Q O8TIxMF4iFGCg1lJhFe0Y1qCEG9KYmVValF+fFFpTmrxIUZpDhYlcd4LXSfjhQTSE0tSs1NT C1KLYLJMHJxSDUyrGz/fDuk7b/SkfckdEfeeGefX58ytvZ9nZroxfaeMgrLJE6ZEGdM7t0qU N99deb/vyXvRlBzjOx2Ns573ZWk0/g6JcNw3i6n4uI/Fik/6l88kp1x7bnu4cMeJH7y2v6Zd 3Xq58kGselWJ5Gmup3cYL3Nc6NKVa7IKO2nOvYF19q2qLC+pcvP9e/9/+bQqmHHLDmkOldby Ns3XQrOPTLvEdVM2dtHFFIfHtXzRH+pXXr78cifrhZpK/nXrkpQDZ082j+yf845FJGvaEelL abc25LpNn71xWqA6z2NlP7n/1RxTjqwJWDjD8bPHBd0VTyM+XnHLdOFMWXhhluZV9wUBr6fM aKxqTcn13cV+++Q3JZbijERDLeai4kQAE3Jh69oCAAA= X-CMS-MailID: 20210511065056epcas2p1788505019deb274f5c57650a2f5d7ef0 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20210511065056epcas2p1788505019deb274f5c57650a2f5d7ef0 References: <1619690903-1138-1-git-send-email-dseok.yi@samsung.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net In the forwarding path GRO -> BPF 6 to 4 -> GSO for TCP traffic, the coalesced packet payload can be > MSS, but < MSS + 20. bpf_skb_proto_6_to_4 will increase the MSS and it can be > the payload length. After then tcp_gso_segment checks for the payload length if it is <= MSS. The condition is causing the packet to be dropped. tcp_gso_segment(): [...] mss = skb_shinfo(skb)->gso_size; if (unlikely(skb->len <= mss)) goto out; [...] Allow to increase MSS when BPF_F_ADJ_ROOM_FIXED_GSO is not set. Fixes: 6578171a7ff0 (bpf: add bpf_skb_change_proto helper) Signed-off-by: Dongseok Yi --- net/core/filter.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) v2: per Willem de Bruijn request, checked the flag instead of a generic approach. diff --git a/net/core/filter.c b/net/core/filter.c index cae56d0..a98b28d 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -3276,7 +3276,7 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb) return 0; } -static int bpf_skb_proto_6_to_4(struct sk_buff *skb) +static int bpf_skb_proto_6_to_4(struct sk_buff *skb, u64 flags) { const u32 len_diff = sizeof(struct ipv6hdr) - sizeof(struct iphdr); u32 off = skb_mac_header_len(skb); @@ -3305,7 +3305,8 @@ static int bpf_skb_proto_6_to_4(struct sk_buff *skb) } /* Due to IPv4 header, MSS can be upgraded. */ - skb_increase_gso_size(shinfo, len_diff); + if (!(flags & BPF_F_ADJ_ROOM_FIXED_GSO)) + skb_increase_gso_size(shinfo, len_diff); /* Header must be checked, and gso_segs recomputed. */ shinfo->gso_type |= SKB_GSO_DODGY; shinfo->gso_segs = 0; @@ -3317,7 +3318,7 @@ static int bpf_skb_proto_6_to_4(struct sk_buff *skb) return 0; } -static int bpf_skb_proto_xlat(struct sk_buff *skb, __be16 to_proto) +static int bpf_skb_proto_xlat(struct sk_buff *skb, __be16 to_proto, u64 flags) { __be16 from_proto = skb->protocol; @@ -3327,7 +3328,7 @@ static int bpf_skb_proto_xlat(struct sk_buff *skb, __be16 to_proto) if (from_proto == htons(ETH_P_IPV6) && to_proto == htons(ETH_P_IP)) - return bpf_skb_proto_6_to_4(skb); + return bpf_skb_proto_6_to_4(skb, flags); return -ENOTSUPP; } @@ -3337,7 +3338,7 @@ BPF_CALL_3(bpf_skb_change_proto, struct sk_buff *, skb, __be16, proto, { int ret; - if (unlikely(flags)) + if (unlikely(flags & ~(BPF_F_ADJ_ROOM_FIXED_GSO))) return -EINVAL; /* General idea is that this helper does the basic groundwork @@ -3357,7 +3358,7 @@ BPF_CALL_3(bpf_skb_change_proto, struct sk_buff *, skb, __be16, proto, * that. For offloads, we mark packet as dodgy, so that headers * need to be verified first. */ - ret = bpf_skb_proto_xlat(skb, proto); + ret = bpf_skb_proto_xlat(skb, proto, flags); bpf_compute_data_pointers(skb); return ret; }