From b97dee873b419c5386b2742530c98a18dae36e2b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 7 Feb 2020 22:26:45 +0100 Subject: pkg/compiler: allow for escaped strings This adds stringnozescapes to allow parsing of escape sequences in strings. --- docs/syscall_descriptions_syntax.md | 2 ++ executor/defs.h | 12 ++++++------ pkg/compiler/types.go | 21 ++++++++++++++++----- sys/linux/gen/386.go | 20 ++++++++++---------- sys/linux/gen/amd64.go | 20 ++++++++++---------- sys/linux/gen/arm.go | 20 ++++++++++---------- sys/linux/gen/arm64.go | 20 ++++++++++---------- sys/linux/gen/mips64le.go | 20 ++++++++++---------- sys/linux/gen/ppc64le.go | 20 ++++++++++---------- sys/linux/socket_netlink_generic_wireguard.txt | 18 +++++++++--------- 10 files changed, 93 insertions(+), 80 deletions(-) diff --git a/docs/syscall_descriptions_syntax.md b/docs/syscall_descriptions_syntax.md index 33652c8cb..43374d4dd 100644 --- a/docs/syscall_descriptions_syntax.md +++ b/docs/syscall_descriptions_syntax.md @@ -41,6 +41,8 @@ rest of the type-options are type-specific: "stringnoz": a non-zero-terminated memory buffer (no pointer indirection implied), type-options: either a string value in quotes for constant strings (e.g. "foo"), or a reference to string flags, +"stringnozescapes": same as "stringnoz", except escape sequences are respected, in order to have + binary strings such as "\x12\x34\x56". "fmt": a string representation of an integer (not zero-terminated), type-options: format (one of "dec", "hex", "oct") and the value (a resource, int, flags, const or proc) the resulting data is always fixed-size (formatted as "%020llu", "0x%016llx" or "%023llo", respectively) diff --git a/executor/defs.h b/executor/defs.h index bc6309526..d3a4aefc2 100644 --- a/executor/defs.h +++ b/executor/defs.h @@ -70,7 +70,7 @@ #if GOARCH_386 #define GOARCH "386" -#define SYZ_REVISION "d2504537da18b6b281d18ba28bbc0a5f83ff4414" +#define SYZ_REVISION "b039e148ad0f2e941e7b8250cc2bc80ba0a74639" #define SYZ_EXECUTOR_USES_FORK_SERVER 1 #define SYZ_EXECUTOR_USES_SHMEM 1 #define SYZ_PAGE_SIZE 4096 @@ -80,7 +80,7 @@ #if GOARCH_amd64 #define GOARCH "amd64" -#define SYZ_REVISION "281a88f4075fb82f6f33925bffd5dc807b03cba5" +#define SYZ_REVISION "969a02b81c319bf95f747c0c20e9a1a37c835c75" #define SYZ_EXECUTOR_USES_FORK_SERVER 1 #define SYZ_EXECUTOR_USES_SHMEM 1 #define SYZ_PAGE_SIZE 4096 @@ -90,7 +90,7 @@ #if GOARCH_arm #define GOARCH "arm" -#define SYZ_REVISION "b46b050bffb9a4dae28f51ae1bc22b864dfb8722" +#define SYZ_REVISION "4b5f90e70357180f05406a5588c99cbc87c48178" #define SYZ_EXECUTOR_USES_FORK_SERVER 1 #define SYZ_EXECUTOR_USES_SHMEM 1 #define SYZ_PAGE_SIZE 4096 @@ -100,7 +100,7 @@ #if GOARCH_arm64 #define GOARCH "arm64" -#define SYZ_REVISION "a5e9983359193b7ef3640d2985db4c4dbd612cfa" +#define SYZ_REVISION "116a25388bfe6e8673fde14050e8445dc0a16981" #define SYZ_EXECUTOR_USES_FORK_SERVER 1 #define SYZ_EXECUTOR_USES_SHMEM 1 #define SYZ_PAGE_SIZE 4096 @@ -110,7 +110,7 @@ #if GOARCH_mips64le #define GOARCH "mips64le" -#define SYZ_REVISION "22ef1007569df159e60009bfb0f3ea12a44ab1f9" +#define SYZ_REVISION "5540717ec5bcfd48e4e2c777b92397b7b94fa8cb" #define SYZ_EXECUTOR_USES_FORK_SERVER 1 #define SYZ_EXECUTOR_USES_SHMEM 1 #define SYZ_PAGE_SIZE 4096 @@ -120,7 +120,7 @@ #if GOARCH_ppc64le #define GOARCH "ppc64le" -#define SYZ_REVISION "cbaaf91a41825f27e07b539eb10deb84ac566bee" +#define SYZ_REVISION "75c21eeb70e84b3911e33fe09516a53f3792beae" #define SYZ_EXECUTOR_USES_FORK_SERVER 1 #define SYZ_EXECUTOR_USES_SHMEM 1 #define SYZ_PAGE_SIZE 4096 diff --git a/pkg/compiler/types.go b/pkg/compiler/types.go index 43efee202..251e0fcaa 100644 --- a/pkg/compiler/types.go +++ b/pkg/compiler/types.go @@ -514,11 +514,12 @@ func genTextType(t *ast.Type) prog.TextKind { } const ( - stringnoz = "stringnoz" + stringnoz = "stringnoz" + stringnozescapes = "stringnozescapes" ) var typeString = &typeDesc{ - Names: []string{"string", stringnoz}, + Names: []string{"string", stringnoz, stringnozescapes}, CanBeTypedef: true, OptArgs: 2, Args: []namedArg{ @@ -526,7 +527,7 @@ var typeString = &typeDesc{ {Name: "size", Type: typeArgInt}, }, Check: func(comp *compiler, t *ast.Type, args []*ast.Type, base prog.IntTypeCommon) { - if t.Ident == stringnoz && len(args) > 1 { + if (t.Ident == stringnoz || t.Ident == stringnozescapes) && len(args) > 1 { comp.error(args[0].Pos, "fixed-size string can't be non-zero-terminated") } }, @@ -558,7 +559,7 @@ var typeString = &typeDesc{ return &prog.BufferType{ TypeCommon: base.TypeCommon, Kind: prog.BufferFilename, - NoZ: t.Ident == stringnoz, + NoZ: t.Ident == stringnoz || t.Ident == stringnozescapes, } } subkind := "" @@ -575,7 +576,7 @@ var typeString = &typeDesc{ Kind: prog.BufferString, SubKind: subkind, Values: vals, - NoZ: t.Ident == stringnoz, + NoZ: t.Ident == stringnoz || t.Ident == stringnozescapes, } }, } @@ -591,6 +592,16 @@ func (comp *compiler) genStrings(t *ast.Type, args []*ast.Type) []string { } if t.Ident == stringnoz { return vals + } else if t.Ident == stringnozescapes { + for i := range vals { + unquote, err := strconv.Unquote(`"` + vals[i] + `"`) + if err != nil { + comp.error(args[0].Pos, fmt.Sprintf("unable to unquote stringnozescapes %q: %v", vals[i], err)) + } else { + vals[i] = unquote + } + } + return vals } var size uint64 if len(args) > 1 { diff --git a/sys/linux/gen/386.go b/sys/linux/gen/386.go index 261463775..4d31b4cb3 100644 --- a/sys/linux/gen/386.go +++ b/sys/linux/gen/386.go @@ -45533,17 +45533,17 @@ var structDescs_386 = []*KeyedStruct{ &IntType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "int16", FldName: "upix", TypeSize: 2, ArgDir: 1}}}, }}}, {StructKey{Name: "wireguard_private_key"}, &StructDesc{TypeCommon: TypeCommon{TypeName: "wireguard_private_key", TypeSize: 128}, Fields: []Type{ - &BufferType{TypeCommon: TypeCommon{TypeName: "stringnoz", FldName: "zero", TypeSize: 128}, Kind: 2, Values: []string{"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00"}, NoZ: true}, - &BufferType{TypeCommon: TypeCommon{TypeName: "stringnoz", FldName: "a", TypeSize: 128}, Kind: 2, Values: []string{"\\xa0\\x5c\\xa8\\x4f\\x6c\\x9c\\x8e\\x38\\x53\\xe2\\xfd\\x7a\\x70\\xae\\x0f\\xb2\\x0f\\xa1\\x52\\x60\\x0c\\xb0\\x08\\x45\\x17\\x4f\\x08\\x07\\x6f\\x8d\\x78\\x43"}, NoZ: true}, - &BufferType{TypeCommon: TypeCommon{TypeName: "stringnoz", FldName: "b", TypeSize: 128}, Kind: 2, Values: []string{"\\xb0\\x80\\x73\\xe8\\xd4\\x4e\\x91\\xe3\\xda\\x92\\x2c\\x22\\x43\\x82\\x44\\xbb\\x88\\x5c\\x69\\xe2\\x69\\xc8\\xe9\\xd8\\x35\\xb1\\x14\\x29\\x3a\\x4d\\xdc\\x6e"}, NoZ: true}, - &BufferType{TypeCommon: TypeCommon{TypeName: "stringnoz", FldName: "c", TypeSize: 128}, Kind: 2, Values: []string{"\\xa0\\xcb\\x87\\x9a\\x47\\xf5\\xbc\\x64\\x4c\\x0e\\x69\\x3f\\xa6\\xd0\\x31\\xc7\\x4a\\x15\\x53\\xb6\\xe9\\x01\\xb9\\xff\\x2f\\x51\\x8c\\x78\\x04\\x2f\\xb5\\x42"}, NoZ: true}, + &BufferType{TypeCommon: TypeCommon{TypeName: "stringnozescapes", FldName: "zero", TypeSize: 128}, Kind: 2, Values: []string{"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"}, NoZ: true}, + &BufferType{TypeCommon: TypeCommon{TypeName: "stringnozescapes", FldName: "a", TypeSize: 128}, Kind: 2, Values: []string{"\xa0\\\xa8Ol\x9c\x8e8S\xe2\xfdzp\xae\x0f\xb2\x0f\xa1R`\f\xb0\bE\x17O\b\ao\x8dxC"}, NoZ: true}, + &BufferType{TypeCommon: TypeCommon{TypeName: "stringnozescapes", FldName: "b", TypeSize: 128}, Kind: 2, Values: []string{"\xb0\x80s\xe8\xd4N\x91\xe3ڒ,\"C\x82D\xbb\x88\\i\xe2i\xc8\xe9\xd85\xb1\x14):M\xdcn"}, NoZ: true}, + &BufferType{TypeCommon: TypeCommon{TypeName: "stringnozescapes", FldName: "c", TypeSize: 128}, Kind: 2, Values: []string{"\xa0ˇ\x9aG\xf5\xbcdL\x0ei?\xa6\xd01\xc7J\x15S\xb6\xe9\x01\xb9\xff/Q\x8cx\x04/\xb5B"}, NoZ: true}, }}}, {StructKey{Name: "wireguard_public_key"}, &StructDesc{TypeCommon: TypeCommon{TypeName: "wireguard_public_key", TypeSize: 128}, Fields: []Type{ - &BufferType{TypeCommon: TypeCommon{TypeName: "stringnoz", FldName: "zero", TypeSize: 128}, Kind: 2, Values: []string{"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00"}, NoZ: true}, - &BufferType{TypeCommon: TypeCommon{TypeName: "stringnoz", FldName: "neg", TypeSize: 128}, Kind: 2, Values: []string{"\\xdb\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff"}, NoZ: true}, - &BufferType{TypeCommon: TypeCommon{TypeName: "stringnoz", FldName: "a_g", TypeSize: 128}, Kind: 2, Values: []string{"\\x97\\x5c\\x9d\\x81\\xc9\\x83\\xc8\\x20\\x9e\\xe7\\x81\\x25\\x4b\\x89\\x9f\\x8e\\xd9\\x25\\xae\\x9f\\x09\\x23\\xc2\\x3c\\x62\\xf5\\x3c\\x57\\xcd\\xbf\\x69\\x1c"}, NoZ: true}, - &BufferType{TypeCommon: TypeCommon{TypeName: "stringnoz", FldName: "b_g", TypeSize: 128}, Kind: 2, Values: []string{"\\xd1\\x73\\x28\\x99\\xf6\\x11\\xcd\\x89\\x94\\x03\\x4d\\x7f\\x41\\x3d\\xc9\\x57\\x63\\x0e\\x54\\x93\\xc2\\x85\\xac\\xa4\\x00\\x65\\xcb\\x63\\x11\\xbe\\x69\\x6b"}, NoZ: true}, - &BufferType{TypeCommon: TypeCommon{TypeName: "stringnoz", FldName: "c_g", TypeSize: 128}, Kind: 2, Values: []string{"\\xf4\\x4d\\xa3\\x67\\xa8\\x8e\\xe6\\x56\\x4f\\x02\\x02\\x11\\x45\\x67\\x27\\x08\\x2f\\x5c\\xeb\\xee\\x8b\\x1b\\xf5\\xeb\\x73\\x37\\x34\\x1b\\x45\\x9b\\x39\\x22"}, NoZ: true}, + &BufferType{TypeCommon: TypeCommon{TypeName: "stringnozescapes", FldName: "zero", TypeSize: 128}, Kind: 2, Values: []string{"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"}, NoZ: true}, + &BufferType{TypeCommon: TypeCommon{TypeName: "stringnozescapes", FldName: "neg", TypeSize: 128}, Kind: 2, Values: []string{"\xdb\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"}, NoZ: true}, + &BufferType{TypeCommon: TypeCommon{TypeName: "stringnozescapes", FldName: "a_g", TypeSize: 128}, Kind: 2, Values: []string{"\x97\\\x9d\x81Ƀ\xc8 \x9e\xe7\x81%K\x89\x9f\x8e\xd9%\xae\x9f\t#\xc2