google / gvisor

Application Kernel for Containers
https://gvisor.dev
Apache License 2.0
15.63k stars 1.29k forks source link

The checksum of ICMPv4 EchoReply packet seems wrong in netstack #605

Closed buptczq closed 5 years ago

buptczq commented 5 years ago

60971295-6778dd80-a356-11e9-8078-b867f449333d

The checksum of echo packet is set here for raw socket: https://github.com/google/netstack/blob/bd29f38290adc0480bbfa21405f73b8e1f3e7989/tcpip/network/ipv4/icmp.go#L87-L89

The checksum of reply packet is calculated here without clearing the checksum in header: https://github.com/google/netstack/blob/bd29f38290adc0480bbfa21405f73b8e1f3e7989/tcpip/network/ipv4/icmp.go#L95-L97

Is it should be written as the following?

        pkt.SetType(header.ICMPv4EchoReply)
        // Clear the checksum
        pkt.SetChecksum(0)
        pkt.SetChecksum(^header.Checksum(pkt, header.ChecksumVV(vv, 0)))
ghost commented 5 years ago

That did appear to be the fix. Thanks @buptczq!