Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3245125imc; Wed, 13 Mar 2019 12:35:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDIx/DUdkLUk/rZ59rQU6/3g/tbfGgyUjcZID4izojyh+JB8FzF4rAEGKoz/EVCgXcSpYE X-Received: by 2002:a63:e14e:: with SMTP id h14mr40457614pgk.184.1552505733366; Wed, 13 Mar 2019 12:35:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552505733; cv=none; d=google.com; s=arc-20160816; b=GAnzmoUXqx2oemuH6fm5kyK4Q2jJKGH5jU73iQjVRXZlaaK8kKkNk6DvlEOkWCYtG3 J8XjYtbNMyrgXDmQsismI6Xpcu5TUG32sP/znz76cS3nwGwGDAcyzPlcLy/xdz4ZRbjD B/VV/s4XvRM+hHaU/nDZlXyqulsqSjaH9XTk2H6tzBvRzYpNB8E88s9uf04mWfmni9t4 QSjYytsiPyuMvLZ/Ia1EQI1ZIZ+ebiqq92utSoo6Wkqml2PyPUWStrnLgM8GsmGfJBj+ Z1FCgsJnq8nw7+hQ6k3GbyubeVeqG2feme4t6VibERhdrdSq1aZKgJBsbDEe8OfgVuPL AGkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RQkTsXQiGcY6hBjs9pKjV+WOUN9CWyzf669LLbgrFpA=; b=sqwTwVvMLGcflrAF5xLQWLtkhAkGkZ5oayGIHTI3zCR2bwoBzJTl4ArwBcadIXrd7N xUm7TRPe7kCVMERcPyeFL+WoSnSz0l1sPZdf65tRqAdzUVdyiEO+VpY9rpk3ougDKKcJ MgbdIwpOSH2O3zV0DGWZy2RArwx/kNmX5PTj6j4qlQHHbxft6ojOEJcBPQspkKJ3lLVV AEGBm3DjlznWWvmA3ZQE+v9HLNYO6MCwa896kWP2xUx+Fr2ThNs8rAQGbdxWscWuyQdJ n4LheA8CS6auH2fHr/PcFU4MVluUG3gdZERwPrnGRpgHpUsPqG3YzFMzVtVmh1R4yn5K chOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j+JcJ2jo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q130si11885100pfq.97.2019.03.13.12.35.17; Wed, 13 Mar 2019 12:35:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j+JcJ2jo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727779AbfCMTeO (ORCPT + 99 others); Wed, 13 Mar 2019 15:34:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:41196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727107AbfCMTKh (ORCPT ); Wed, 13 Mar 2019 15:10:37 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE08E2173C; Wed, 13 Mar 2019 19:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552504236; bh=ehcFTpKlVQO+i83WcJUFAB9EgudEjTrngKna63Oxums=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j+JcJ2jouQi8BHMQwpFivrsRk+qaKhB8Sk7W6bcr/sHyEgS+WtIPCz3WsXMHlgDht 8khvSjU57HNCF4pygii6BC8dkVK4daf1MWnMaEfgrmDwLIv/khsFIWPN+yEZhqM1Q7 60jip/fN3ZjyMQ/mfSVXQQyHzNlzUSShnoS+AGVg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Willem de Bruijn , Alexei Starovoitov , Sasha Levin Subject: [PATCH AUTOSEL 4.20 07/60] bpf: only adjust gso_size on bytestream protocols Date: Wed, 13 Mar 2019 15:09:28 -0400 Message-Id: <20190313191021.158171-7-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190313191021.158171-1-sashal@kernel.org> References: <20190313191021.158171-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Willem de Bruijn [ Upstream commit b90efd2258749e04e1b3f71ef0d716f2ac2337e0 ] bpf_skb_change_proto and bpf_skb_adjust_room change skb header length. For GSO packets they adjust gso_size to maintain the same MTU. The gso size can only be safely adjusted on bytestream protocols. Commit d02f51cbcf12 ("bpf: fix bpf_skb_adjust_net/bpf_skb_proto_xlat to deal with gso sctp skbs") excluded SKB_GSO_SCTP. Since then type SKB_GSO_UDP_L4 has been added, whose contents are one gso_size unit per datagram. Also exclude these. Move from a blacklist to a whitelist check to future proof against additional such new GSO types, e.g., for fraglist based GRO. Fixes: bec1f6f69736 ("udp: generate gso with UDP_SEGMENT") Signed-off-by: Willem de Bruijn Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- include/linux/skbuff.h | 6 ++++++ net/core/filter.c | 12 ++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 8e63c166765e..875f56cbb756 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -4118,6 +4118,12 @@ static inline bool skb_is_gso_sctp(const struct sk_buff *skb) return skb_shinfo(skb)->gso_type & SKB_GSO_SCTP; } +static inline bool skb_is_gso_tcp(const struct sk_buff *skb) +{ + return skb_is_gso(skb) && + skb_shinfo(skb)->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6); +} + static inline void skb_gso_reset(struct sk_buff *skb) { skb_shinfo(skb)->gso_size = 0; diff --git a/net/core/filter.c b/net/core/filter.c index 16350f8c8815..6e37c639519e 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2624,8 +2624,7 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb) u32 off = skb_mac_header_len(skb); int ret; - /* SCTP uses GSO_BY_FRAGS, thus cannot adjust it. */ - if (skb_is_gso(skb) && unlikely(skb_is_gso_sctp(skb))) + if (!skb_is_gso_tcp(skb)) return -ENOTSUPP; ret = skb_cow(skb, len_diff); @@ -2666,8 +2665,7 @@ static int bpf_skb_proto_6_to_4(struct sk_buff *skb) u32 off = skb_mac_header_len(skb); int ret; - /* SCTP uses GSO_BY_FRAGS, thus cannot adjust it. */ - if (skb_is_gso(skb) && unlikely(skb_is_gso_sctp(skb))) + if (!skb_is_gso_tcp(skb)) return -ENOTSUPP; ret = skb_unclone(skb, GFP_ATOMIC); @@ -2792,8 +2790,7 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 len_diff) u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb); int ret; - /* SCTP uses GSO_BY_FRAGS, thus cannot adjust it. */ - if (skb_is_gso(skb) && unlikely(skb_is_gso_sctp(skb))) + if (!skb_is_gso_tcp(skb)) return -ENOTSUPP; ret = skb_cow(skb, len_diff); @@ -2822,8 +2819,7 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 len_diff) u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb); int ret; - /* SCTP uses GSO_BY_FRAGS, thus cannot adjust it. */ - if (skb_is_gso(skb) && unlikely(skb_is_gso_sctp(skb))) + if (!skb_is_gso_tcp(skb)) return -ENOTSUPP; ret = skb_unclone(skb, GFP_ATOMIC); -- 2.19.1