]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/bpf-only-test-gso-type-on-gso-packets.patch
c69e60b7619322da9d8ef08aa4389a017b0fbe21
[thirdparty/kernel/stable-queue.git] / queue-4.19 / bpf-only-test-gso-type-on-gso-packets.patch
1 From f1fbe7fd6984e96f2a84bab9d47de7225db66581 Mon Sep 17 00:00:00 2001
2 From: Willem de Bruijn <willemb@google.com>
3 Date: Wed, 6 Mar 2019 14:35:15 -0500
4 Subject: bpf: only test gso type on gso packets
5
6 [ Upstream commit 4c3024debf62de4c6ac6d3cb4c0063be21d4f652 ]
7
8 BPF can adjust gso only for tcp bytestreams. Fail on other gso types.
9
10 But only on gso packets. It does not touch this field if !gso_size.
11
12 Fixes: b90efd225874 ("bpf: only adjust gso_size on bytestream protocols")
13 Signed-off-by: Willem de Bruijn <willemb@google.com>
14 Acked-by: Yonghong Song <yhs@fb.com>
15 Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
16 Signed-off-by: Sasha Levin <sashal@kernel.org>
17 ---
18 include/linux/skbuff.h | 4 ++--
19 net/core/filter.c | 8 ++++----
20 2 files changed, 6 insertions(+), 6 deletions(-)
21
22 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
23 index 3b0a25bb7c6f..820903ceac4f 100644
24 --- a/include/linux/skbuff.h
25 +++ b/include/linux/skbuff.h
26 @@ -4086,10 +4086,10 @@ static inline bool skb_is_gso_sctp(const struct sk_buff *skb)
27 return skb_shinfo(skb)->gso_type & SKB_GSO_SCTP;
28 }
29
30 +/* Note: Should be called only if skb_is_gso(skb) is true */
31 static inline bool skb_is_gso_tcp(const struct sk_buff *skb)
32 {
33 - return skb_is_gso(skb) &&
34 - skb_shinfo(skb)->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6);
35 + return skb_shinfo(skb)->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6);
36 }
37
38 static inline void skb_gso_reset(struct sk_buff *skb)
39 diff --git a/net/core/filter.c b/net/core/filter.c
40 index b1369edce113..eb81e9db4093 100644
41 --- a/net/core/filter.c
42 +++ b/net/core/filter.c
43 @@ -2614,7 +2614,7 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb)
44 u32 off = skb_mac_header_len(skb);
45 int ret;
46
47 - if (!skb_is_gso_tcp(skb))
48 + if (skb_is_gso(skb) && !skb_is_gso_tcp(skb))
49 return -ENOTSUPP;
50
51 ret = skb_cow(skb, len_diff);
52 @@ -2655,7 +2655,7 @@ static int bpf_skb_proto_6_to_4(struct sk_buff *skb)
53 u32 off = skb_mac_header_len(skb);
54 int ret;
55
56 - if (!skb_is_gso_tcp(skb))
57 + if (skb_is_gso(skb) && !skb_is_gso_tcp(skb))
58 return -ENOTSUPP;
59
60 ret = skb_unclone(skb, GFP_ATOMIC);
61 @@ -2780,7 +2780,7 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 len_diff)
62 u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb);
63 int ret;
64
65 - if (!skb_is_gso_tcp(skb))
66 + if (skb_is_gso(skb) && !skb_is_gso_tcp(skb))
67 return -ENOTSUPP;
68
69 ret = skb_cow(skb, len_diff);
70 @@ -2809,7 +2809,7 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 len_diff)
71 u32 off = skb_mac_header_len(skb) + bpf_skb_net_base_len(skb);
72 int ret;
73
74 - if (!skb_is_gso_tcp(skb))
75 + if (skb_is_gso(skb) && !skb_is_gso_tcp(skb))
76 return -ENOTSUPP;
77
78 ret = skb_unclone(skb, GFP_ATOMIC);
79 --
80 2.19.1
81