calipso: Add validation of CALIPSO option.
Subsystems (5)
RFC PATCH v2 16/18 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.
Signed-off-by Huw Davies <[email protected]>
--- 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 · 1 line
1.8.0