From 63b16a5d5cfd3b41f596daccd56d32b2548ec119 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Wed, 25 Jan 2017 16:18:05 +0100 Subject: 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. --- sys/decl.go | 13 ++++++++++++- sys/test.txt | 19 +++++++++++++++++++ sys/vnet.txt | 7 +++---- 3 files changed, 34 insertions(+), 5 deletions(-) (limited to 'sys') 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 -- cgit mrf-deployment