Skip to content

Commit ce9ecb8

Browse files
Paolo Abenigregkh
authored andcommitted
ip: fix IP_CHECKSUM handling
[ Upstream commit ca4ef4574f1ee5252e2cd365f8f5d5bafd048f32 ] 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: ad6f939 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 353dd72 commit ce9ecb8

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

net/ipv4/ip_sockglue.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb,
105105
if (skb->ip_summed != CHECKSUM_COMPLETE)
106106
return;
107107

108-
if (offset != 0)
109-
csum = csum_sub(csum,
110-
csum_partial(skb->data + tlen,
111-
offset, 0));
108+
if (offset != 0) {
109+
int tend_off = skb_transport_offset(skb) + tlen;
110+
csum = csum_sub(csum, skb_checksum(skb, tend_off, offset, 0));
111+
}
112112

113113
put_cmsg(msg, SOL_IP, IP_CHECKSUM, sizeof(__wsum), &csum);
114114
}

0 commit comments

Comments
 (0)