diff options
| author | Andrey Konovalov <andreyknvl@google.com> | 2017-01-25 16:18:05 +0100 |
|---|---|---|
| committer | Andrey Konovalov <andreyknvl@google.com> | 2017-01-25 20:31:13 +0100 |
| commit | 63b16a5d5cfd3b41f596daccd56d32b2548ec119 (patch) | |
| tree | 3dfa93b07083b7ee4c21aa430aeedc92b9a16bb4 /sys | |
| parent | c8d03a05f3acd375badcde94264909d149784778 (diff) | |
prog, sys: add csum type, embed checksums for ipv4 packets
This change adds a `csum[kind, type]` type.
The only available kind right now is `ipv4`.
Using `csum[ipv4, int16be]` in `ipv4_header` makes syzkaller calculate
and embed correct checksums into ipv4 packets.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/decl.go | 13 | ||||
| -rw-r--r-- | sys/test.txt | 19 | ||||
| -rw-r--r-- | sys/vnet.txt | 7 |
3 files changed, 34 insertions, 5 deletions
diff --git a/sys/decl.go b/sys/decl.go index 3c98d1038..14f1105de 100644 --- a/sys/decl.go +++ b/sys/decl.go @@ -191,6 +191,17 @@ type ProcType struct { ValuesPerProc uint64 } +type CsumKind int + +const ( + CsumIPv4 CsumKind = iota +) + +type CsumType struct { + IntTypeCommon + Kind CsumKind +} + type VmaType struct { TypeCommon RangeBegin int64 // in pages @@ -573,7 +584,7 @@ func ForeachType(meta *Call, f func(Type)) { rec(opt) } case *ResourceType, *BufferType, *VmaType, *LenType, - *FlagsType, *ConstType, *IntType, *ProcType: + *FlagsType, *ConstType, *IntType, *ProcType, *CsumType: default: panic("unknown type") } diff --git a/sys/test.txt b/sys/test.txt index 0ce7ec819..75b8428fd 100644 --- a/sys/test.txt +++ b/sys/test.txt @@ -389,3 +389,22 @@ syz_bf_struct1 { syz_test$bf0(a0 ptr[in, syz_bf_struct0]) syz_test$bf1(a0 ptr[in, syz_bf_struct1]) + +# Checksums + +syz_test$csum_encode(a0 ptr[in, syz_csum_encode]) +syz_test$csum_ipv4(a0 ptr[in, syz_csum_ipv4]) + +syz_csum_encode { + f0 int16 + f1 int16be + f2 array[int32, 0:4] + f3 int8:4 + f4 int8:4 + f5 array[int8, 4] +} [packed] + +syz_csum_ipv4 { + f0 csum[ipv4, int16] + f1 syz_csum_encode +} [packed] diff --git a/sys/vnet.txt b/sys/vnet.txt index 67344b186..a959f8909 100644 --- a/sys/vnet.txt +++ b/sys/vnet.txt @@ -149,14 +149,13 @@ ipv4_header { version const[4, int8:4] ecn int8:2 dscp int8:6 - tot_len len[ipv4_packet, int16be] - identification int16be + total_len len[ipv4_packet, int16be] + id int16be frag_off int16:13 flags int16:3 ttl int8 protocol flags[ipv4_types, int8] -# TODO: embed correct checksum - csum const[0, int16] + csum csum[ipv4, int16be] src_ip ipv4_addr dst_ip ipv4_addr options ipv4_options |
