Commit 4f9bd530 authored by Kevin Mitchell's avatar Kevin Mitchell Committed by Pablo Neira Ayuso

netfilter: conntrack: skip verification of zero UDP checksum

The checksum is optional for UDP packets. However nf_reject would
previously require a valid checksum to elicit a response such as
ICMP_DEST_UNREACH.

Add some logic to nf_reject_verify_csum to determine if a UDP packet has
a zero checksum and should therefore not be verified.
Signed-off-by: default avatarKevin Mitchell <kevmitch@arista.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 3412e164
...@@ -5,12 +5,28 @@ ...@@ -5,12 +5,28 @@
#include <linux/types.h> #include <linux/types.h>
#include <uapi/linux/in.h> #include <uapi/linux/in.h>
static inline bool nf_reject_verify_csum(__u8 proto) static inline bool nf_reject_verify_csum(struct sk_buff *skb, int dataoff,
__u8 proto)
{ {
/* Skip protocols that don't use 16-bit one's complement checksum /* Skip protocols that don't use 16-bit one's complement checksum
* of the entire payload. * of the entire payload.
*/ */
switch (proto) { switch (proto) {
/* Protocols with optional checksums. */
case IPPROTO_UDP: {
const struct udphdr *udp_hdr;
struct udphdr _udp_hdr;
udp_hdr = skb_header_pointer(skb, dataoff,
sizeof(_udp_hdr),
&_udp_hdr);
if (!udp_hdr || udp_hdr->check)
return true;
return false;
}
case IPPROTO_GRE:
/* Protocols with other integrity checks. */ /* Protocols with other integrity checks. */
case IPPROTO_AH: case IPPROTO_AH:
case IPPROTO_ESP: case IPPROTO_ESP:
...@@ -19,9 +35,6 @@ static inline bool nf_reject_verify_csum(__u8 proto) ...@@ -19,9 +35,6 @@ static inline bool nf_reject_verify_csum(__u8 proto)
/* Protocols with partial checksums. */ /* Protocols with partial checksums. */
case IPPROTO_UDPLITE: case IPPROTO_UDPLITE:
case IPPROTO_DCCP: case IPPROTO_DCCP:
/* Protocols with optional checksums. */
case IPPROTO_GRE:
return false; return false;
} }
return true; return true;
......
...@@ -80,6 +80,7 @@ struct sk_buff *nf_reject_skb_v4_unreach(struct net *net, ...@@ -80,6 +80,7 @@ struct sk_buff *nf_reject_skb_v4_unreach(struct net *net,
struct iphdr *niph; struct iphdr *niph;
struct icmphdr *icmph; struct icmphdr *icmph;
unsigned int len; unsigned int len;
int dataoff;
__wsum csum; __wsum csum;
u8 proto; u8 proto;
...@@ -99,10 +100,11 @@ struct sk_buff *nf_reject_skb_v4_unreach(struct net *net, ...@@ -99,10 +100,11 @@ struct sk_buff *nf_reject_skb_v4_unreach(struct net *net,
if (pskb_trim_rcsum(oldskb, ntohs(ip_hdr(oldskb)->tot_len))) if (pskb_trim_rcsum(oldskb, ntohs(ip_hdr(oldskb)->tot_len)))
return NULL; return NULL;
dataoff = ip_hdrlen(oldskb);
proto = ip_hdr(oldskb)->protocol; proto = ip_hdr(oldskb)->protocol;
if (!skb_csum_unnecessary(oldskb) && if (!skb_csum_unnecessary(oldskb) &&
nf_reject_verify_csum(proto) && nf_reject_verify_csum(oldskb, dataoff, proto) &&
nf_ip_checksum(oldskb, hook, ip_hdrlen(oldskb), proto)) nf_ip_checksum(oldskb, hook, ip_hdrlen(oldskb), proto))
return NULL; return NULL;
...@@ -311,6 +313,7 @@ EXPORT_SYMBOL_GPL(nf_send_reset); ...@@ -311,6 +313,7 @@ EXPORT_SYMBOL_GPL(nf_send_reset);
void nf_send_unreach(struct sk_buff *skb_in, int code, int hook) void nf_send_unreach(struct sk_buff *skb_in, int code, int hook)
{ {
struct iphdr *iph = ip_hdr(skb_in); struct iphdr *iph = ip_hdr(skb_in);
int dataoff = ip_hdrlen(skb_in);
u8 proto = iph->protocol; u8 proto = iph->protocol;
if (iph->frag_off & htons(IP_OFFSET)) if (iph->frag_off & htons(IP_OFFSET))
...@@ -320,12 +323,13 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook) ...@@ -320,12 +323,13 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook)
nf_reject_fill_skb_dst(skb_in) < 0) nf_reject_fill_skb_dst(skb_in) < 0)
return; return;
if (skb_csum_unnecessary(skb_in) || !nf_reject_verify_csum(proto)) { if (skb_csum_unnecessary(skb_in) ||
!nf_reject_verify_csum(skb_in, dataoff, proto)) {
icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0); icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0);
return; return;
} }
if (nf_ip_checksum(skb_in, hook, ip_hdrlen(skb_in), proto) == 0) if (nf_ip_checksum(skb_in, hook, dataoff, proto) == 0)
icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0); icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0);
} }
EXPORT_SYMBOL_GPL(nf_send_unreach); EXPORT_SYMBOL_GPL(nf_send_unreach);
......
...@@ -31,7 +31,7 @@ static bool nf_reject_v6_csum_ok(struct sk_buff *skb, int hook) ...@@ -31,7 +31,7 @@ static bool nf_reject_v6_csum_ok(struct sk_buff *skb, int hook)
if (thoff < 0 || thoff >= skb->len || (fo & htons(~0x7)) != 0) if (thoff < 0 || thoff >= skb->len || (fo & htons(~0x7)) != 0)
return false; return false;
if (!nf_reject_verify_csum(proto)) if (!nf_reject_verify_csum(skb, thoff, proto))
return true; return true;
return nf_ip6_checksum(skb, hook, thoff, proto) == 0; return nf_ip6_checksum(skb, hook, thoff, proto) == 0;
...@@ -388,7 +388,7 @@ static bool reject6_csum_ok(struct sk_buff *skb, int hook) ...@@ -388,7 +388,7 @@ static bool reject6_csum_ok(struct sk_buff *skb, int hook)
if (thoff < 0 || thoff >= skb->len || (fo & htons(~0x7)) != 0) if (thoff < 0 || thoff >= skb->len || (fo & htons(~0x7)) != 0)
return false; return false;
if (!nf_reject_verify_csum(proto)) if (!nf_reject_verify_csum(skb, thoff, proto))
return true; return true;
return nf_ip6_checksum(skb, hook, thoff, proto) == 0; return nf_ip6_checksum(skb, hook, thoff, proto) == 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment