mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-11 07:39:47 +00:00
xen-netback: fix fragment detection in checksum setup
The code to detect fragments in checksum_setup() was missing for IPv4 and too eager for IPv6. (It transpires that Windows seems to send IPv6 packets with a fragment header even if they are not a fragment - i.e. offset is zero, and M bit is not set). This patch also incorporates a fix to callers of maybe_pull_tail() where skb->network_header was being erroneously added to the length argument. Signed-off-by: Paul Durrant <paul.durrant@citrix.com> Signed-off-by: Zoltan Kiss <zoltan.kiss@citrix.com> Cc: Wei Liu <wei.liu2@citrix.com> Cc: Ian Campbell <ian.campbell@citrix.com> Cc: David Vrabel <david.vrabel@citrix.com> cc: David Miller <davem@davemloft.net> Acked-by: Wei Liu <wei.liu2@citrix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
df48ada4f8
commit
1431fb31ec
@ -1149,49 +1149,72 @@ static int xenvif_set_skb_gso(struct xenvif *vif,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void maybe_pull_tail(struct sk_buff *skb, unsigned int len)
|
static inline int maybe_pull_tail(struct sk_buff *skb, unsigned int len,
|
||||||
|
unsigned int max)
|
||||||
{
|
{
|
||||||
if (skb_is_nonlinear(skb) && skb_headlen(skb) < len) {
|
if (skb_headlen(skb) >= len)
|
||||||
/* If we need to pullup then pullup to the max, so we
|
return 0;
|
||||||
* won't need to do it again.
|
|
||||||
*/
|
/* If we need to pullup then pullup to the max, so we
|
||||||
int target = min_t(int, skb->len, MAX_TCP_HEADER);
|
* won't need to do it again.
|
||||||
__pskb_pull_tail(skb, target - skb_headlen(skb));
|
*/
|
||||||
}
|
if (max > skb->len)
|
||||||
|
max = skb->len;
|
||||||
|
|
||||||
|
if (__pskb_pull_tail(skb, max - skb_headlen(skb)) == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
if (skb_headlen(skb) < len)
|
||||||
|
return -EPROTO;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This value should be large enough to cover a tagged ethernet header plus
|
||||||
|
* maximally sized IP and TCP or UDP headers.
|
||||||
|
*/
|
||||||
|
#define MAX_IP_HDR_LEN 128
|
||||||
|
|
||||||
static int checksum_setup_ip(struct xenvif *vif, struct sk_buff *skb,
|
static int checksum_setup_ip(struct xenvif *vif, struct sk_buff *skb,
|
||||||
int recalculate_partial_csum)
|
int recalculate_partial_csum)
|
||||||
{
|
{
|
||||||
struct iphdr *iph = (void *)skb->data;
|
|
||||||
unsigned int header_size;
|
|
||||||
unsigned int off;
|
unsigned int off;
|
||||||
int err = -EPROTO;
|
bool fragment;
|
||||||
|
int err;
|
||||||
|
|
||||||
off = sizeof(struct iphdr);
|
fragment = false;
|
||||||
|
|
||||||
header_size = skb->network_header + off + MAX_IPOPTLEN;
|
err = maybe_pull_tail(skb,
|
||||||
maybe_pull_tail(skb, header_size);
|
sizeof(struct iphdr),
|
||||||
|
MAX_IP_HDR_LEN);
|
||||||
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
off = iph->ihl * 4;
|
if (ip_hdr(skb)->frag_off & htons(IP_OFFSET | IP_MF))
|
||||||
|
fragment = true;
|
||||||
|
|
||||||
switch (iph->protocol) {
|
off = ip_hdrlen(skb);
|
||||||
|
|
||||||
|
err = -EPROTO;
|
||||||
|
|
||||||
|
switch (ip_hdr(skb)->protocol) {
|
||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
if (!skb_partial_csum_set(skb, off,
|
if (!skb_partial_csum_set(skb, off,
|
||||||
offsetof(struct tcphdr, check)))
|
offsetof(struct tcphdr, check)))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (recalculate_partial_csum) {
|
if (recalculate_partial_csum) {
|
||||||
struct tcphdr *tcph = tcp_hdr(skb);
|
err = maybe_pull_tail(skb,
|
||||||
|
off + sizeof(struct tcphdr),
|
||||||
|
MAX_IP_HDR_LEN);
|
||||||
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
header_size = skb->network_header +
|
tcp_hdr(skb)->check =
|
||||||
off +
|
~csum_tcpudp_magic(ip_hdr(skb)->saddr,
|
||||||
sizeof(struct tcphdr);
|
ip_hdr(skb)->daddr,
|
||||||
maybe_pull_tail(skb, header_size);
|
skb->len - off,
|
||||||
|
IPPROTO_TCP, 0);
|
||||||
tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
|
|
||||||
skb->len - off,
|
|
||||||
IPPROTO_TCP, 0);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IPPROTO_UDP:
|
case IPPROTO_UDP:
|
||||||
@ -1200,24 +1223,20 @@ static int checksum_setup_ip(struct xenvif *vif, struct sk_buff *skb,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (recalculate_partial_csum) {
|
if (recalculate_partial_csum) {
|
||||||
struct udphdr *udph = udp_hdr(skb);
|
err = maybe_pull_tail(skb,
|
||||||
|
off + sizeof(struct udphdr),
|
||||||
|
MAX_IP_HDR_LEN);
|
||||||
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
header_size = skb->network_header +
|
udp_hdr(skb)->check =
|
||||||
off +
|
~csum_tcpudp_magic(ip_hdr(skb)->saddr,
|
||||||
sizeof(struct udphdr);
|
ip_hdr(skb)->daddr,
|
||||||
maybe_pull_tail(skb, header_size);
|
skb->len - off,
|
||||||
|
IPPROTO_UDP, 0);
|
||||||
udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
|
|
||||||
skb->len - off,
|
|
||||||
IPPROTO_UDP, 0);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (net_ratelimit())
|
|
||||||
netdev_err(vif->dev,
|
|
||||||
"Attempting to checksum a non-TCP/UDP packet, "
|
|
||||||
"dropping a protocol %d packet\n",
|
|
||||||
iph->protocol);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1227,75 +1246,99 @@ out:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This value should be large enough to cover a tagged ethernet header plus
|
||||||
|
* an IPv6 header, all options, and a maximal TCP or UDP header.
|
||||||
|
*/
|
||||||
|
#define MAX_IPV6_HDR_LEN 256
|
||||||
|
|
||||||
|
#define OPT_HDR(type, skb, off) \
|
||||||
|
(type *)(skb_network_header(skb) + (off))
|
||||||
|
|
||||||
static int checksum_setup_ipv6(struct xenvif *vif, struct sk_buff *skb,
|
static int checksum_setup_ipv6(struct xenvif *vif, struct sk_buff *skb,
|
||||||
int recalculate_partial_csum)
|
int recalculate_partial_csum)
|
||||||
{
|
{
|
||||||
int err = -EPROTO;
|
int err;
|
||||||
struct ipv6hdr *ipv6h = (void *)skb->data;
|
|
||||||
u8 nexthdr;
|
u8 nexthdr;
|
||||||
unsigned int header_size;
|
|
||||||
unsigned int off;
|
unsigned int off;
|
||||||
|
unsigned int len;
|
||||||
bool fragment;
|
bool fragment;
|
||||||
bool done;
|
bool done;
|
||||||
|
|
||||||
|
fragment = false;
|
||||||
done = false;
|
done = false;
|
||||||
|
|
||||||
off = sizeof(struct ipv6hdr);
|
off = sizeof(struct ipv6hdr);
|
||||||
|
|
||||||
header_size = skb->network_header + off;
|
err = maybe_pull_tail(skb, off, MAX_IPV6_HDR_LEN);
|
||||||
maybe_pull_tail(skb, header_size);
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
nexthdr = ipv6h->nexthdr;
|
nexthdr = ipv6_hdr(skb)->nexthdr;
|
||||||
|
|
||||||
while ((off <= sizeof(struct ipv6hdr) + ntohs(ipv6h->payload_len)) &&
|
len = sizeof(struct ipv6hdr) + ntohs(ipv6_hdr(skb)->payload_len);
|
||||||
!done) {
|
while (off <= len && !done) {
|
||||||
switch (nexthdr) {
|
switch (nexthdr) {
|
||||||
case IPPROTO_DSTOPTS:
|
case IPPROTO_DSTOPTS:
|
||||||
case IPPROTO_HOPOPTS:
|
case IPPROTO_HOPOPTS:
|
||||||
case IPPROTO_ROUTING: {
|
case IPPROTO_ROUTING: {
|
||||||
struct ipv6_opt_hdr *hp = (void *)(skb->data + off);
|
struct ipv6_opt_hdr *hp;
|
||||||
|
|
||||||
header_size = skb->network_header +
|
err = maybe_pull_tail(skb,
|
||||||
off +
|
off +
|
||||||
sizeof(struct ipv6_opt_hdr);
|
sizeof(struct ipv6_opt_hdr),
|
||||||
maybe_pull_tail(skb, header_size);
|
MAX_IPV6_HDR_LEN);
|
||||||
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
hp = OPT_HDR(struct ipv6_opt_hdr, skb, off);
|
||||||
nexthdr = hp->nexthdr;
|
nexthdr = hp->nexthdr;
|
||||||
off += ipv6_optlen(hp);
|
off += ipv6_optlen(hp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IPPROTO_AH: {
|
case IPPROTO_AH: {
|
||||||
struct ip_auth_hdr *hp = (void *)(skb->data + off);
|
struct ip_auth_hdr *hp;
|
||||||
|
|
||||||
header_size = skb->network_header +
|
err = maybe_pull_tail(skb,
|
||||||
off +
|
off +
|
||||||
sizeof(struct ip_auth_hdr);
|
sizeof(struct ip_auth_hdr),
|
||||||
maybe_pull_tail(skb, header_size);
|
MAX_IPV6_HDR_LEN);
|
||||||
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
hp = OPT_HDR(struct ip_auth_hdr, skb, off);
|
||||||
nexthdr = hp->nexthdr;
|
nexthdr = hp->nexthdr;
|
||||||
off += (hp->hdrlen+2)<<2;
|
off += ipv6_authlen(hp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case IPPROTO_FRAGMENT: {
|
||||||
|
struct frag_hdr *hp;
|
||||||
|
|
||||||
|
err = maybe_pull_tail(skb,
|
||||||
|
off +
|
||||||
|
sizeof(struct frag_hdr),
|
||||||
|
MAX_IPV6_HDR_LEN);
|
||||||
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
hp = OPT_HDR(struct frag_hdr, skb, off);
|
||||||
|
|
||||||
|
if (hp->frag_off & htons(IP6_OFFSET | IP6_MF))
|
||||||
|
fragment = true;
|
||||||
|
|
||||||
|
nexthdr = hp->nexthdr;
|
||||||
|
off += sizeof(struct frag_hdr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IPPROTO_FRAGMENT:
|
|
||||||
fragment = true;
|
|
||||||
/* fall through */
|
|
||||||
default:
|
default:
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!done) {
|
err = -EPROTO;
|
||||||
if (net_ratelimit())
|
|
||||||
netdev_err(vif->dev, "Failed to parse packet header\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fragment) {
|
if (!done || fragment)
|
||||||
if (net_ratelimit())
|
|
||||||
netdev_err(vif->dev, "Packet is a fragment!\n");
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
switch (nexthdr) {
|
switch (nexthdr) {
|
||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
@ -1304,17 +1347,17 @@ static int checksum_setup_ipv6(struct xenvif *vif, struct sk_buff *skb,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (recalculate_partial_csum) {
|
if (recalculate_partial_csum) {
|
||||||
struct tcphdr *tcph = tcp_hdr(skb);
|
err = maybe_pull_tail(skb,
|
||||||
|
off + sizeof(struct tcphdr),
|
||||||
|
MAX_IPV6_HDR_LEN);
|
||||||
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
header_size = skb->network_header +
|
tcp_hdr(skb)->check =
|
||||||
off +
|
~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
|
||||||
sizeof(struct tcphdr);
|
&ipv6_hdr(skb)->daddr,
|
||||||
maybe_pull_tail(skb, header_size);
|
skb->len - off,
|
||||||
|
IPPROTO_TCP, 0);
|
||||||
tcph->check = ~csum_ipv6_magic(&ipv6h->saddr,
|
|
||||||
&ipv6h->daddr,
|
|
||||||
skb->len - off,
|
|
||||||
IPPROTO_TCP, 0);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IPPROTO_UDP:
|
case IPPROTO_UDP:
|
||||||
@ -1323,25 +1366,20 @@ static int checksum_setup_ipv6(struct xenvif *vif, struct sk_buff *skb,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (recalculate_partial_csum) {
|
if (recalculate_partial_csum) {
|
||||||
struct udphdr *udph = udp_hdr(skb);
|
err = maybe_pull_tail(skb,
|
||||||
|
off + sizeof(struct udphdr),
|
||||||
|
MAX_IPV6_HDR_LEN);
|
||||||
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
header_size = skb->network_header +
|
udp_hdr(skb)->check =
|
||||||
off +
|
~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
|
||||||
sizeof(struct udphdr);
|
&ipv6_hdr(skb)->daddr,
|
||||||
maybe_pull_tail(skb, header_size);
|
skb->len - off,
|
||||||
|
IPPROTO_UDP, 0);
|
||||||
udph->check = ~csum_ipv6_magic(&ipv6h->saddr,
|
|
||||||
&ipv6h->daddr,
|
|
||||||
skb->len - off,
|
|
||||||
IPPROTO_UDP, 0);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (net_ratelimit())
|
|
||||||
netdev_err(vif->dev,
|
|
||||||
"Attempting to checksum a non-TCP/UDP packet, "
|
|
||||||
"dropping a protocol %d packet\n",
|
|
||||||
nexthdr);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <uapi/linux/ipv6.h>
|
#include <uapi/linux/ipv6.h>
|
||||||
|
|
||||||
#define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
|
#define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
|
||||||
|
#define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
|
||||||
/*
|
/*
|
||||||
* This structure contains configuration options per IPv6 link.
|
* This structure contains configuration options per IPv6 link.
|
||||||
*/
|
*/
|
||||||
|
@ -110,7 +110,8 @@ struct frag_hdr {
|
|||||||
__be32 identification;
|
__be32 identification;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define IP6_MF 0x0001
|
#define IP6_MF 0x0001
|
||||||
|
#define IP6_OFFSET 0xFFF8
|
||||||
|
|
||||||
#include <net/sock.h>
|
#include <net/sock.h>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user