diff options
author | Andrei Vagin <avagin@google.com> | 2020-12-21 15:47:58 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-12-21 15:50:33 -0800 |
commit | 946cb909e62e0aaca9e3bbb7cf059dd6b0eab2ce (patch) | |
tree | 14fe1c74964616bdf89dd0c23880226de95936be /pkg/tcpip/header/icmpv4.go | |
parent | 981faa2c122922e0cb9f2996c56b4b7c38e18bfb (diff) |
Don't modify a packet header when it can be used by other endpoints
Reported-by: syzbot+48c43f82fe7738fceae9@syzkaller.appspotmail.com
PiperOrigin-RevId: 348540796
Diffstat (limited to 'pkg/tcpip/header/icmpv4.go')
-rw-r--r-- | pkg/tcpip/header/icmpv4.go | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/pkg/tcpip/header/icmpv4.go b/pkg/tcpip/header/icmpv4.go index 1be90d7d5..5f9b8e9e2 100644 --- a/pkg/tcpip/header/icmpv4.go +++ b/pkg/tcpip/header/icmpv4.go @@ -200,19 +200,13 @@ func (b ICMPv4) SetSequence(sequence uint16) { // ICMPv4Checksum calculates the ICMP checksum over the provided ICMP header, // and payload. func ICMPv4Checksum(h ICMPv4, vv buffer.VectorisedView) uint16 { - // Calculate the IPv6 pseudo-header upper-layer checksum. - xsum := uint16(0) - for _, v := range vv.Views() { - xsum = Checksum(v, xsum) - } + xsum := ChecksumVV(vv, 0) - // h[2:4] is the checksum itself, set it aside to avoid checksumming the checksum. - h2, h3 := h[2], h[3] - h[2], h[3] = 0, 0 - xsum = ^Checksum(h, xsum) - h[2], h[3] = h2, h3 + // h[2:4] is the checksum itself, skip it to avoid checksumming the checksum. + xsum = Checksum(h[:2], xsum) + xsum = Checksum(h[4:], xsum) - return xsum + return ^xsum } // ICMPOriginFromNetProto returns the appropriate SockErrOrigin to use when |