The TCP checksum is weak, and the Ethernet checksum will accept corrupt TCP that passed the TCP checksum

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

Interesting:

At Twitter, a team had a unusual failure where corrupt data ended up in memcache. The root cause appears to have been a switch that was corrupting packets. Most packets were being dropped and the throughput was much lower than normal, but some were still making it through. The hypothesis is that occasionally the corrupt packets had valid TCP and Ethernet checksums. One “lucky” packet stored corrupt data in memcache. Even after the switch was replaced, the errors continued until the cache was cleared.

I was very excited to hear about this error, because it is a real-world example of something I wrote about back in July 2008: The TCP checksum is weak. However, the Ethernet CRC is strong, so how could a corrupt packet pass both checks? The answer is that the Ethernet CRC is recalculated by switches. As long as the corrupt packet has the same TCP checksum, the hardware will happily recalculate a new, valid Ethernet CRC. As a result, if you are creating a new network protocol, please append a CRC (I suggest CRC32C, implemented in hardware on recent Intel, AMD, and ARM CPUs). An alternative is to use an encryption protocol (e.g. TLS), since they include cryptographic hashes (e.g. see a description of packet corruption in OSPF being fixed with TLS). The rest of this article describes the details about how this is possible, mostly so I don’t forget them.

Properties of the TCP checksum

The TCP checksum is two bytes long, and can detect any burst error of 15 bits, and most burst errors of 16 bits (excluding switching 0x0000 and 0xffff). This means that to keep the same checksum, a packet must be corrupted in at least two locations, at least 2 bytes apart. If the chance is purely random, we should expect approximately 1 in 216 (approximately 0.001%) of corrupt packets to not be detected. This seems small, but on one Gigabit Ethernet connection, that could be as many as 15 packets per second. For details about how to compute the TCP checksum and its error properties, see RFC 1071.

Post external references

  1. 1
    http://www.evanjones.ca/tcp-and-ethernet-checksums-fail.html
Source