Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp943576pxy; Wed, 5 May 2021 18:48:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6Q4+EnGYsaNyHLYzkJIl+779HkUBiFyL9QQsXpFz9HdRlld09wFK0XB4IaPly0uvtLYiO X-Received: by 2002:a63:38d:: with SMTP id 135mr1747450pgd.285.1620265699435; Wed, 05 May 2021 18:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620265699; cv=none; d=google.com; s=arc-20160816; b=f45L4fgqAjP9hGGyWpWqW3kbPyOu3Gzs4knXdRzwFlr/+Qw7nT4UYAqR1E9Xkg6kA0 yrQb3HGE5xHXkGcIjSNkt4JC/ILLMtZ3u1WFbyrXL0hVt3IoAUvWTo44XinR9VXHqpLS +SddlXRZ68Dkmous6gpxahCVK9+F2U7PyJxLqxCr1zSgh4L3nPlH/QL23fBwHGAiRX4T vOGkNktovHOAGxR5wSSntROwI9V0sSpZ0UjIKJBotIIP6luA2k4kvPt7fOru+Mcljox5 krrVYl+hAaA6YKyv+g1ENXY74rgo9NeAEMuIyoxFI/3WPlbIWea/vWOV1BRVmRQT0LyE lOVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nCC16UrPwBZC9MtXIyH48K544cIIxJ7XOCk2iyqAPAU=; b=uFuRKBfngumSMCGKlThEOG/WqHN7FaLgBoSOXREZ9ewn0s5LZvneObdRQpWUz/2I/v 4l8YEAg7soxJQHkRFerrFfmDW25GY+3wk4uryoezluXwi/yImuQwtBf4UMCmTDFdsO99 9UzAB53bZmCte/pRiihUxIw+Y3yQZsoZJcWljyYRAzbEti6dvhiR+8l5tWYGEXzkKb0s u2qO+qPDrFOUkzF6A6M7yCHGgLusdEvdBuH/0AdjtVgfkBrpNdF34lzLjtm+6XjfmdOm EMeKsoR6RGueHnCNRZKTOHaobgU1/WHXizaO5lbikllVybNffnffvx9kmW73L3PRYL+H 5P4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kvpJcDlK; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si1073878pgp.275.2021.05.05.18.48.06; Wed, 05 May 2021 18:48:19 -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=@gmail.com header.s=20161025 header.b=kvpJcDlK; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbhEFBrQ (ORCPT + 99 others); Wed, 5 May 2021 21:47:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229465AbhEFBrP (ORCPT ); Wed, 5 May 2021 21:47:15 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF1D7C061574 for ; Wed, 5 May 2021 18:46:17 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id c22so4245863edn.7 for ; Wed, 05 May 2021 18:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nCC16UrPwBZC9MtXIyH48K544cIIxJ7XOCk2iyqAPAU=; b=kvpJcDlKuHWZKjh/pMLbOz5mUlvlY2NX2nLGoZ6/j23WB+Ciwj4pZUTcrP0NPTZQzY 8tPdr7CIjcchyXRZW5J3zErd/t42e7ZDJ9hBPqKN8zW9WPNUj9gm72vvKB1mTYPtW2pL Mcl2euv0lAKI01w6MfQTEZGp3GTSf6U4NFi7/1P2ymsYxVZEoDaOjQX4rphTn6ewgLIU KhLQPVpuCbxGK/ZzgOC9viM8aDQR7cpZ1V7Q75zhs2ziNMK1KSZYIUpd/N4R8FgCaiSR chWH12Gt5P3M112HYlA1p23ilvc1GsrD0yhOm9vM0m/OpPpWpTY0ccgwCVVGfBV2hcBV uN6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nCC16UrPwBZC9MtXIyH48K544cIIxJ7XOCk2iyqAPAU=; b=XHUKpNPnPrINQ9RrBQhkTYuSNpDmEvX0P/rC4DCIi1WaWu/djQIBRQ2wjCqIJE0uL/ y9yaRQ9OaY0Ckp2jLdDwKkC1Bwb+tSq9zJMogQxFZL6UlZpFjJ6rF3AbIqS2Np29wesV XgU7HfANwKxts70cxiUUXN2+m4MhcMUuncwbnjphfGCx04I0Ad64XiwLM12lMkDGKKVD GCwEwCfDQV0FiqWOU1h+yXkrpAH49zZFu3yO8EnkcLVlrL6LizH6GWktEUPZ09Yh3eKk Oy6168wynbAYf1snO9TbliVdwujMEwbzKI7s/vl3UihDQtuFIOsn6FCSJKAnJ2Lj3OMg ACSg== X-Gm-Message-State: AOAM532KuhsM1/rpHXR4G5YpfQg1V53RUsUV6j//QKSlMDu/pk+4Khhw z1lcZTbpexQwoPM9vzYw+3wNiDHh9OTNnQ== X-Received: by 2002:aa7:d382:: with SMTP id x2mr2055249edq.60.1620265576623; Wed, 05 May 2021 18:46:16 -0700 (PDT) Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com. [209.85.221.52]) by smtp.gmail.com with ESMTPSA id u25sm483055ejb.12.2021.05.05.18.46.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 May 2021 18:46:16 -0700 (PDT) Received: by mail-wr1-f52.google.com with SMTP id l2so3813880wrm.9 for ; Wed, 05 May 2021 18:46:16 -0700 (PDT) X-Received: by 2002:adf:aa9a:: with SMTP id h26mr1848982wrc.419.1620265575663; Wed, 05 May 2021 18:46:15 -0700 (PDT) MIME-Version: 1.0 References: <1619690903-1138-1-git-send-email-dseok.yi@samsung.com> <8c2ea41a-3fc5-d560-16e5-bf706949d857@iogearbox.net> <02bf01d74211$0ff4aed0$2fde0c70$@samsung.com> In-Reply-To: <02bf01d74211$0ff4aed0$2fde0c70$@samsung.com> From: Willem de Bruijn Date: Wed, 5 May 2021 21:45:37 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf] bpf: check for data_len before upgrading mss when 6 to 4 To: Dongseok Yi Cc: Daniel Borkmann , bpf , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski , Network Development , linux-kernel , Willem de Bruijn Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 5, 2021 at 8:45 PM Dongseok Yi wrote: > > On Wed, May 05, 2021 at 10:55:10PM +0200, Daniel Borkmann wrote: > > On 4/29/21 12:08 PM, Dongseok Yi wrote: > > > tcp_gso_segment check for the size of GROed payload if it is bigger > > > than the mss. bpf_skb_proto_6_to_4 increases mss, but the mss can be > > > bigger than the size of GROed payload unexpectedly if data_len is not > > > big enough. > > > > > > Assume that skb gso_size = 1372 and data_len = 8. bpf_skb_proto_6_to_4 Is this a typo and is this intended to read skb->data_len = 1380? The issue is that payload length (1380) is greater than mss with ipv6 (1372), but less than mss with ipv4 (1392). I don't understand data_len = 8 or why the patch compares skb->data_len to len_diff (20). One simple solution if this packet no longer needs to be segmented might be to reset the gso_type completely. In general, I would advocate using BPF_F_ADJ_ROOM_FIXED_GSO. When converting from IPv6 to IPv4, fixed gso will end up building packets that are slightly below the MTU. That opportunity cost is negligible (especially with TSO). Unfortunately, I see that that flag is available for bpf_skb_adjust_room but not for bpf_skb_proto_6_to_4. > > > would increse the gso_size to 1392. tcp_gso_segment will get an error > > > with 1380 <= 1392. > > > > > > Check for the size of GROed payload if it is really bigger than target > > > mss when increase mss. > > > > > > Fixes: 6578171a7ff0 (bpf: add bpf_skb_change_proto helper) > > > Signed-off-by: Dongseok Yi > > > --- > > > net/core/filter.c | 4 +++- > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > diff --git a/net/core/filter.c b/net/core/filter.c > > > index 9323d34..3f79e3c 100644 > > > --- a/net/core/filter.c > > > +++ b/net/core/filter.c > > > @@ -3308,7 +3308,9 @@ 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 (skb->data_len > len_diff) > > > > Could you elaborate some more on what this has to do with data_len specifically > > here? I'm not sure I follow exactly your above commit description. Are you saying > > that you're hitting in tcp_gso_segment(): > > > > [...] > > mss = skb_shinfo(skb)->gso_size; > > if (unlikely(skb->len <= mss)) > > goto out; > > [...] > > Yes, right > > > > > Please provide more context on the bug, thanks! > > tcp_gso_segment(): > [...] > __skb_pull(skb, thlen); > > mss = skb_shinfo(skb)->gso_size; > if (unlikely(skb->len <= mss)) > [...] > > skb->len will have total GROed TCP payload size after __skb_pull. > skb->len <= mss will not be happened in a normal GROed situation. But > bpf_skb_proto_6_to_4 would upgrade MSS by increasing gso_size, it can > hit an error condition. > > We should ensure the following condition. > total GROed TCP payload > the original mss + (IPv6 size - IPv4 size) > > Due to > total GROed TCP payload = the original mss + skb->data_len > IPv6 size - IPv4 size = len_diff > > Finally, we can get the condition. > skb->data_len > len_diff > > > > > > + 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; > > > > >