Commit d46c7676 authored by Eric Dumazet's avatar Eric Dumazet Committed by Greg Kroah-Hartman

udp: fix IP_CHECKSUM handling

[ Upstream commit 10df8e61 ]

First bug was added in commit ad6f939a ("ip: Add offset parameter to
ip_cmsg_recv") : Tom missed that ipv4 udp messages could be received on
AF_INET6 socket. ip_cmsg_recv(msg, skb) should have been replaced by
ip_cmsg_recv_offset(msg, skb, sizeof(struct udphdr));

Then commit e6afc8ac ("udp: remove headers from UDP packets before
queueing") forgot to adjust the offsets now UDP headers are pulled
before skb are put in receive queue.

Fixes: ad6f939a ("ip: Add offset parameter to ip_cmsg_recv")
Fixes: e6afc8ac ("udp: remove headers from UDP packets before queueing")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Cc: Sam Kumar <samanthakumar@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Tested-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 80d59090
...@@ -553,7 +553,7 @@ int ip_options_rcv_srr(struct sk_buff *skb); ...@@ -553,7 +553,7 @@ int ip_options_rcv_srr(struct sk_buff *skb);
*/ */
void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb); void ipv4_pktinfo_prepare(const struct sock *sk, struct sk_buff *skb);
void ip_cmsg_recv_offset(struct msghdr *msg, struct sk_buff *skb, int offset); void ip_cmsg_recv_offset(struct msghdr *msg, struct sk_buff *skb, int tlen, int offset);
int ip_cmsg_send(struct net *net, struct msghdr *msg, int ip_cmsg_send(struct net *net, struct msghdr *msg,
struct ipcm_cookie *ipc, bool allow_ipv6); struct ipcm_cookie *ipc, bool allow_ipv6);
int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval, int ip_setsockopt(struct sock *sk, int level, int optname, char __user *optval,
...@@ -575,7 +575,7 @@ void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 dport, ...@@ -575,7 +575,7 @@ void ip_local_error(struct sock *sk, int err, __be32 daddr, __be16 dport,
static inline void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb) static inline void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb)
{ {
ip_cmsg_recv_offset(msg, skb, 0); ip_cmsg_recv_offset(msg, skb, 0, 0);
} }
bool icmp_global_allow(void); bool icmp_global_allow(void);
......
...@@ -98,7 +98,7 @@ static void ip_cmsg_recv_retopts(struct msghdr *msg, struct sk_buff *skb) ...@@ -98,7 +98,7 @@ static void ip_cmsg_recv_retopts(struct msghdr *msg, struct sk_buff *skb)
} }
static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb, static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb,
int offset) int tlen, int offset)
{ {
__wsum csum = skb->csum; __wsum csum = skb->csum;
...@@ -106,7 +106,9 @@ static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb, ...@@ -106,7 +106,9 @@ static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb,
return; return;
if (offset != 0) if (offset != 0)
csum = csum_sub(csum, csum_partial(skb->data, offset, 0)); csum = csum_sub(csum,
csum_partial(skb->data + tlen,
offset, 0));
put_cmsg(msg, SOL_IP, IP_CHECKSUM, sizeof(__wsum), &csum); put_cmsg(msg, SOL_IP, IP_CHECKSUM, sizeof(__wsum), &csum);
} }
...@@ -152,7 +154,7 @@ static void ip_cmsg_recv_dstaddr(struct msghdr *msg, struct sk_buff *skb) ...@@ -152,7 +154,7 @@ static void ip_cmsg_recv_dstaddr(struct msghdr *msg, struct sk_buff *skb)
} }
void ip_cmsg_recv_offset(struct msghdr *msg, struct sk_buff *skb, void ip_cmsg_recv_offset(struct msghdr *msg, struct sk_buff *skb,
int offset) int tlen, int offset)
{ {
struct inet_sock *inet = inet_sk(skb->sk); struct inet_sock *inet = inet_sk(skb->sk);
unsigned int flags = inet->cmsg_flags; unsigned int flags = inet->cmsg_flags;
...@@ -215,7 +217,7 @@ void ip_cmsg_recv_offset(struct msghdr *msg, struct sk_buff *skb, ...@@ -215,7 +217,7 @@ void ip_cmsg_recv_offset(struct msghdr *msg, struct sk_buff *skb,
} }
if (flags & IP_CMSG_CHECKSUM) if (flags & IP_CMSG_CHECKSUM)
ip_cmsg_recv_checksum(msg, skb, offset); ip_cmsg_recv_checksum(msg, skb, tlen, offset);
} }
EXPORT_SYMBOL(ip_cmsg_recv_offset); EXPORT_SYMBOL(ip_cmsg_recv_offset);
......
...@@ -1342,7 +1342,7 @@ int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, ...@@ -1342,7 +1342,7 @@ int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock,
*addr_len = sizeof(*sin); *addr_len = sizeof(*sin);
} }
if (inet->cmsg_flags) if (inet->cmsg_flags)
ip_cmsg_recv_offset(msg, skb, sizeof(struct udphdr)); ip_cmsg_recv_offset(msg, skb, sizeof(struct udphdr), off);
err = copied; err = copied;
if (flags & MSG_TRUNC) if (flags & MSG_TRUNC)
......
...@@ -498,7 +498,8 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -498,7 +498,8 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (is_udp4) { if (is_udp4) {
if (inet->cmsg_flags) if (inet->cmsg_flags)
ip_cmsg_recv(msg, skb); ip_cmsg_recv_offset(msg, skb,
sizeof(struct udphdr), off);
} else { } else {
if (np->rxopt.all) if (np->rxopt.all)
ip6_datagram_recv_specific_ctl(sk, msg, skb); ip6_datagram_recv_specific_ctl(sk, msg, skb);
......
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