diff options
author | Paolo Abeni <pabeni@redhat.com> | 2017-02-21 03:33:18 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-02-21 12:23:53 -0500 |
commit | ca4ef4574f1ee5252e2cd365f8f5d5bafd048f32 (patch) | |
tree | 0e9ae821b92bfa2cb2e143e15b4b98e829d59528 | |
parent | 8dcd81a993f4f65d22dfecb4360204b428c36cff (diff) |
ip: fix IP_CHECKSUM handling
The skbs processed by ip_cmsg_recv() are not guaranteed to
be linear e.g. when sending UDP packets over loopback with
MSGMORE.
Using csum_partial() on [potentially] the whole skb len
is dangerous; instead be on the safe side and use skb_checksum().
Thanks to syzkaller team to detect the issue and provide the
reproducer.
v1 -> v2:
- move the variable declaration in a tighter scope
Fixes: ad6f939ab193 ("ip: Add offset parameter to ip_cmsg_recv")
Reported-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/ipv4/ip_sockglue.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index ce1386a67e24..ebd953bc5607 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c | |||
@@ -116,10 +116,10 @@ static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb, | |||
116 | if (skb->ip_summed != CHECKSUM_COMPLETE) | 116 | if (skb->ip_summed != CHECKSUM_COMPLETE) |
117 | return; | 117 | return; |
118 | 118 | ||
119 | if (offset != 0) | 119 | if (offset != 0) { |
120 | csum = csum_sub(csum, | 120 | int tend_off = skb_transport_offset(skb) + tlen; |
121 | csum_partial(skb_transport_header(skb) + tlen, | 121 | csum = csum_sub(csum, skb_checksum(skb, tend_off, offset, 0)); |
122 | offset, 0)); | 122 | } |
123 | 123 | ||
124 | put_cmsg(msg, SOL_IP, IP_CHECKSUM, sizeof(__wsum), &csum); | 124 | put_cmsg(msg, SOL_IP, IP_CHECKSUM, sizeof(__wsum), &csum); |
125 | } | 125 | } |