calipso: Add validation of CALIPSO option.
Subsystems (5)
RFC PATCH 16/17 calipso: Add validation of CALIPSO option.
We check lengths, checksum and the DOI. We leave checking of the level and categories for the socket layer.
--- include/net/calipso.h | 6 ++++++ net/ipv6/calipso.c | 43 +++++++++++++++++++++++++++++++++++++++++++ net/ipv6/exthdrs.c | 27 +++++++++++++++++++++++++++ 3 files changed, 76 insertions(+)
include/net/calipso.h +6 -0
@@ -65,6 +65,7 @@ struct calipso_doi {#ifdef CONFIG_NETLABEL int __init calipso_init (void );void calipso_exit (void ); +bool calipso_validate (const struct sk_buff *skb,const unsigned char *option);#else static inline int __init calipso_init (void ) {
@@ -74,6 +75,11 @@ static inline int __init calipso_init(void)static inline void calipso_exit (void ) { } +static inline bool calipso_validate (const struct sk_buff *skb, +const unsigned char *option) +{ +return true; +}#endif /* CONFIG_NETLABEL */ #endif /* _CALIPSO_H */
net/ipv6/calipso.c +43 -0
49 lines not on this page · raw message
net/ipv6/exthdrs.c +27 -0
@@ -43,6 +43,7 @@#include <net/ndisc.h> #include <net/ip6_route.h> #include <net/addrconf.h> +#include <net/calipso.h> #if IS_ENABLED (CONFIG_IPV6_MIP6 )#include <net/xfrm.h> #endif
@@ -603,6 +604,28 @@ drop:return false; } +/* CALIPSO RFC 5570 */ + +static bool ipv6_hop_calipso (struct sk_buff *skb,int optoff) +{ +const unsigned char *nh =skb_network_header (skb); + +if (nh[optoff +1 ] <8 ) + goto drop; + +if (nh[optoff +6 ] *4 +8 > nh[optoff +1 ]) + goto drop; + +if (!calipso_validate (skb, nh + optoff)) + goto drop; + +return true; + +drop: +kfree_skb (skb); +return false; +} +static const struct tlvtype_proc tlvprochopopt_lst[] = { { .type =IPV6_TLV_ROUTERALERT ,
@@ -612,6 +635,10 @@ static const struct tlvtype_proc tlvprochopopt_lst[] = { .type = IPV6_TLV_JUMBO, .func = ipv6_hop_jumbo, }, + { + .type = IPV6_TLV_CALIPSO, + .func = ipv6_hop_calipso, + }, { -1, } };
Signature · 7 lines
1.8.0 _______________________________________________ Selinux mailing list [email protected] To unsubscribe, send email to [email protected] To get help, send an email containing "help" to [email protected]
Quoted 13 lines · Huw Davies
net/ipv6/exthdrs.c +12
-0+/* CALIPSO RFC 5570 */ + +static bool ipv6_hop_calipso (struct sk_buff *skb,int optoff) +{ +const unsigned char *nh =skb_network_header (skb); + +if (nh[optoff +1 ] <8 ) + goto drop; + +if (nh[optoff +6 ] *4 +8 > nh[optoff +1 ]) + goto drop; +
net/ipv6/exthdrs.c drop: · line 628
Quoted 10 lines
net/ipv6/exthdrs.c +10
-0+if (!calipso_validate (skb, nh + optoff)) + goto drop; + +return true; + +drop: +kfree_skb (skb); +return false; +} +
Formally, if an extension header could not be processed, the packet should be discarded and an icmp error parameter extension should be send. I think we shouldn't let those packets pass here.
Thanks,
Hannes
Quoted 20 lines · Hannes Frederic Sowa
Quoted 19 lines · Huw Davies
net/ipv6/exthdrs.c +18
-0+/* CALIPSO RFC 5570 */ + +static bool ipv6_hop_calipso (struct sk_buff *skb,int optoff) +{ +const unsigned char *nh =skb_network_header (skb); + +if (nh[optoff +1 ] <8 ) + goto drop; + +if (nh[optoff +6 ] *4 +8 > nh[optoff +1 ]) + goto drop; + +if (!calipso_validate (skb, nh + optoff)) + goto drop; + +return true; + +drop:
Quoted 8 lines
net/ipv6/exthdrs.c drop: · line 628
Quoted 4 lines
net/ipv6/exthdrs.c +4
-0+kfree_skb (skb); +return false; +} +Formally, if an extension header could not be processed, the packet should be discarded and an icmp error parameter extension should be send. I think we shouldn't let those packets pass here.
Thanks for your comments Hannes, I'm looking into your other suggestions.
I'm confused about this one. AFAICS, this will drop packets that we can't process. We don't send the icmp error, but I can certainly add that. Is that what you mean?
Thanks,
Huw.
Quoted 30 lines · Huw Davies
Quoted 20 lines · Hannes Frederic Sowa
Quoted 19 lines · Huw Davies
net/ipv6/exthdrs.c +18
-0+/* CALIPSO RFC 5570 */ + +static bool ipv6_hop_calipso (struct sk_buff *skb,int optoff) +{ +const unsigned char *nh =skb_network_header (skb); + +if (nh[optoff +1 ] <8 ) + goto drop; + +if (nh[optoff +6 ] *4 +8 > nh[optoff +1 ]) + goto drop; + +if (!calipso_validate (skb, nh + optoff)) + goto drop; + +return true; + +drop:Quoted 8 lines
net/ipv6/exthdrs.c drop: · line 628
Quoted 4 lines
net/ipv6/exthdrs.c +4
-0+kfree_skb (skb); +return false; +} +Formally, if an extension header could not be processed, the packet should be discarded and an icmp error parameter extension should be send. I think we shouldn't let those packets pass here.
Quoted 6 lines
Thanks for your comments Hannes, I'm looking into your other suggestions.
I'm confused about this one. AFAICS, this will drop packets that we can't process. We don't send the icmp error, but I can certainly add that. Is that what you mean?
Actually, the implementation of calipso_validate will accept the packets because it defaults to return true if we don't compile the module. At least we should drop the packet if it is not loaded. I am in favor of adding the parameter problem icmp error. So, yes, I think it should be added.
Bye,
Hannes
Quoted 10 lines · Hannes Frederic Sowa
Quoted 3 lines · Huw Davies
I'm confused about this one. AFAICS, this will drop packets that we can't process. We don't send the icmp error, but I can certainly add that. Is that what you mean?
Actually, the implementation of
calipso_validatewill accept the packets because it defaults to return true if we don't compile the module. At least we should drop the packet if it is not loaded. I am in favor of adding the parameter problem icmp error. So, yes, I think it should be added.
Yet the option value is 0x07, i.e. the two highest bits are both zero which according to:
https://tools.ietf.org/html/rfc2460#section-4.2
means we should just skip it.
https://tools.ietf.org/html/rfc5570#section-5.1.1
reaffirms that.
In terms of sending an icmp on error while validating:
https://tools.ietf.org/html/rfc5570#section-6.2.2
is pretty conservative in that case too. Most errors should just be silently dropped.
Huw.