[PATCH 6/6] net: filter: refuse to change gso_size of SCTP packets
From: Daniel Axtens <hidden>
Date: 2018-02-27 13:08:40
Subsystem:
bpf [general] (safe dynamic programs and tools), bpf [networking] (tcx & tc bpf, sock_addr), networking [general], the rest · Maintainers:
Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
An eBPF tc action on a veth pair can be passed an SCTP GSO skb, which
has gso_size of GSO_BY_FRAGS.
If that action calls bpf_skb_change_proto(), bpf_skb_net_grow()
or bpf_skb_net_shrink(), the code will unconditionally attempt to
increment or decrement the gso_size to some nonsense value.
It's not clear how this could be done correctly, so simply refuse
to operate on SCTP GSO skbs.
Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Daniel Axtens <redacted>
---
Marcelo - I am not an SCTP expert by any means, so if this code should
be doing something else, please let me know.
---
net/core/filter.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/net/core/filter.c b/net/core/filter.c
index d9684d8a3ac7..f189c988962e 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2096,6 +2096,10 @@ static int bpf_skb_proto_4_to_6(struct sk_buff *skb)
return ret;
if (skb_is_gso(skb)) {
+ /* SCTP uses GSO_BY_FRAGS, cannot adjust */
+ if (unlikely(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP))
+ return -ENOTSUPP;
+
/* SKB_GSO_TCPV4 needs to be changed into
* SKB_GSO_TCPV6.
*/@@ -2132,6 +2136,10 @@ static int bpf_skb_proto_6_to_4(struct sk_buff *skb)
return ret;
if (skb_is_gso(skb)) {
+ /* SCTP uses GSO_BY_FRAGS, cannot adjust */
+ if (unlikely(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP))
+ return -ENOTSUPP;
+
/* SKB_GSO_TCPV6 needs to be changed into
* SKB_GSO_TCPV4.
*/@@ -2252,6 +2260,10 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 len_diff)
return ret;
if (skb_is_gso(skb)) {
+ /* SCTP uses GSO_BY_FRAGS, cannot adjust */
+ if (unlikely(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP))
+ return -ENOTSUPP;
+
/* Due to header grow, MSS needs to be downgraded. */
skb_decrease_gso_size(skb, len_diff);
/* Header must be checked, and gso_segs recomputed. */@@ -2276,6 +2288,10 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 len_diff)
return ret;
if (skb_is_gso(skb)) {
+ /* SCTP uses GSO_BY_FRAGS, cannot adjust */
+ if (unlikely(skb_shinfo(skb)->gso_type & SKB_GSO_SCTP))
+ return -ENOTSUPP;
+
/* Due to header shrink, MSS can be upgraded. */
skb_increase_gso_size(skb, len_diff);
/* Header must be checked, and gso_segs recomputed. */--
2.14.1