flow_dissector: Flow dissector fixes
Subsystems (2)
v2 cover flow_dissector: Flow dissector fixes
This patch set fixes some basic issues with __skb_flow_dissect function.
Items addressed:
- Cleanup control flow in the function; in particular eliminate a bunch of goto's and implement a simplified control flow model
- Add limits for number of encapsulations and headers that can be dissected
v2:
- Simplify the logic for limits on flow dissection. Just set the limit based on the number of headers the flow dissector can processes. The accounted headers includes encapsulation headers, extension headers, or other shim headers.
Tested:
Ran normal traffic, GUE, and VXLAN traffic.
*** BLURB HERE ***
Tom Herbert (2):
flow_dissector: Cleanup control flow
flow_dissector: Add limit for number of headers to dissect
include/net/flow_dissector.h | 8 ++ net/core/flow_dissector.c | 242 +++++++++++++++++++++++++++++-------------- 2 files changed, 172 insertions(+), 78 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 1/2 flow_dissector: Cleanup control flow
__skb_flow_dissect is riddled with gotos that make discerning the flow, debugging, and extending the capability difficult. This patch reorganizes things so that we only perform goto's after the two main switch statements (no gotos within the cases now). It also eliminates several goto labels so that there are only two labels that can be target for goto.
--- include/net/flow_dissector.h | 8 ++ net/core/flow_dissector.c | 223 ++++++++++++++++++++++++++++--------------- 2 files changed, 153 insertions(+), 78 deletions(-)
include/net/flow_dissector.h +8 -0
@@ -19,6 +19,14 @@ struct flow_dissector_key_control {#define FLOW_DIS_FIRST_FRAG BIT(1)#define FLOW_DIS_ENCAPSULATION BIT(2) +enum flow_dissect_ret { +FLOW_DISSECT_RET_OUT_GOOD , +FLOW_DISSECT_RET_OUT_BAD , +FLOW_DISSECT_RET_PROTO_AGAIN , +FLOW_DISSECT_RET_IPPROTO_AGAIN , +FLOW_DISSECT_RET_CONTINUE , +}; +/** * struct flow_dissector_key_basic: * @thoff: Transport header offset
net/core/flow_dissector.c +145 -78
390 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v2 2/2 flow_dissector: Add limit for number of headers to dissect
In reply to Tom HerbertIn flow dissector there are no limits to the number of nested encapsulations or headers that might be dissected which makes for a nice DOS attack. This patch sets a limit of the number of headers that flow dissector will parse.
Headers includes network layer headers, transport layer headers, shim headers for encapsulation, IPv6 extension headers, etc. The limit for maximum number of headers to parse has be set to fifteen to account for a reasonable number of encapsulations, extension headers, VLAN, in a packet. Note that this limit does not supercede the STOP_AT_* flags which may stop processing before the headers limit is reached.
--- net/core/flow_dissector.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
net/core/flow_dissector.c +22 -3
@@ -396,6 +396,18 @@ __skb_flow_dissect_ipv6(const struct sk_buff *skb, key_ip->ttl = iph->hop_limit; } +/* Maximum number of protocol headers that can be parsed in +* __skb_flow_dissect +*/ +#define MAX_FLOW_DISSECT_HDRS 15 + +static bool skb_flow_dissect_allowed (int *num_hdrs) +{ + ++*num_hdrs; + +return (*num_hdrs <=MAX_FLOW_DISSECT_HDRS ); +} +/** * __skb_flow_dissect - extract the flow_keys struct and return it * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified
@@ -427,6 +439,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,struct flow_dissector_key_vlan *key_vlan;enum flow_dissect_ret fdret;bool skip_vlan = false; +int num_hdrs =0 ;u8 ip_proto =0 ;bool ret;
@@ -714,7 +727,9 @@ bool __skb_flow_dissect(const struct sk_buff *skb,case FLOW_DISSECT_RET_OUT_GOOD : goto out_good;case FLOW_DISSECT_RET_PROTO_AGAIN : - goto proto_again; +if (skb_flow_dissect_allowed (&num_hdrs)) + goto proto_again; + goto out_good;case FLOW_DISSECT_RET_CONTINUE :case FLOW_DISSECT_RET_IPPROTO_AGAIN :break ;
@@ -843,9 +858,13 @@ bool __skb_flow_dissect(const struct sk_buff *skb,/* Process result of IP proto processing */ switch (fdret) {case FLOW_DISSECT_RET_PROTO_AGAIN : - goto proto_again; +if (skb_flow_dissect_allowed (&num_hdrs)) + goto proto_again; +break ;case FLOW_DISSECT_RET_IPPROTO_AGAIN : - goto ip_proto_again; +if (skb_flow_dissect_allowed (&num_hdrs)) + goto ip_proto_again; +break ;case FLOW_DISSECT_RET_OUT_GOOD :case FLOW_DISSECT_RET_CONTINUE :break ;
Signature · 1 line
2.11.0
From: Tom Herbert <[email protected]>
Date: Fri, 1 Sep 2017 14:04:10 -0700
Quoted 14 lines
This patch set fixes some basic issues with
__skb_flow_dissectfunction.Items addressed:
- Cleanup control flow in the function; in particular eliminate a bunch of goto's and implement a simplified control flow model
- Add limits for number of encapsulations and headers that can be dissectedv2:
- Simplify the logic for limits on flow dissection. Just set the limit based on the number of headers the flow dissector can processes. The accounted headers includes encapsulation headers, extension headers, or other shim headers.
Quoted 3 lines
Tested:
Ran normal traffic, GUE, and VXLAN traffic.
Applied, thanks Tom.