|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `syscall` package. |
| 3 | + */ |
| 4 | + |
| 5 | +import go |
| 6 | + |
| 7 | +/** Provides models of commonly used functions in the `syscall` package. */ |
| 8 | +module Syscall { |
| 9 | + private class FunctionModels extends TaintTracking::FunctionModel { |
| 10 | + FunctionInput inp; |
| 11 | + FunctionOutput outp; |
| 12 | + |
| 13 | + FunctionModels() { |
| 14 | + // signature: func BytePtrFromString(s string) (*byte, error) |
| 15 | + hasQualifiedName("syscall", "BytePtrFromString") and |
| 16 | + (inp.isParameter(0) and outp.isResult(0)) |
| 17 | + or |
| 18 | + // signature: func ByteSliceFromString(s string) ([]byte, error) |
| 19 | + hasQualifiedName("syscall", "ByteSliceFromString") and |
| 20 | + (inp.isParameter(0) and outp.isResult(0)) |
| 21 | + or |
| 22 | + // signature: func StringBytePtr(s string) *byte |
| 23 | + hasQualifiedName("syscall", "StringBytePtr") and |
| 24 | + (inp.isParameter(0) and outp.isResult()) |
| 25 | + or |
| 26 | + // signature: func StringByteSlice(s string) []byte |
| 27 | + hasQualifiedName("syscall", "StringByteSlice") and |
| 28 | + (inp.isParameter(0) and outp.isResult()) |
| 29 | + or |
| 30 | + // signature: func StringSlicePtr(ss []string) []*byte |
| 31 | + hasQualifiedName("syscall", "StringSlicePtr") and |
| 32 | + (inp.isParameter(0) and outp.isResult()) |
| 33 | + } |
| 34 | + |
| 35 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 36 | + input = inp and output = outp |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + private class MethodModels extends TaintTracking::FunctionModel, Method { |
| 41 | + FunctionInput inp; |
| 42 | + FunctionOutput outp; |
| 43 | + |
| 44 | + MethodModels() { |
| 45 | + // signature: func (RawConn).Read(f func(fd uintptr) (done bool)) error |
| 46 | + this.implements("syscall", "RawConn", "Read") and |
| 47 | + (inp.isReceiver() and outp.isParameter(0)) |
| 48 | + or |
| 49 | + // signature: func (Conn).SyscallConn() (RawConn, error) |
| 50 | + this.implements("syscall", "Conn", "SyscallConn") and |
| 51 | + ( |
| 52 | + inp.isReceiver() and outp.isResult(0) |
| 53 | + or |
| 54 | + inp.isResult(0) and outp.isReceiver() |
| 55 | + ) |
| 56 | + or |
| 57 | + // signature: func (RawConn).Write(f func(fd uintptr) (done bool)) error |
| 58 | + this.implements("syscall", "RawConn", "Write") and |
| 59 | + (inp.isParameter(0) and outp.isReceiver()) |
| 60 | + } |
| 61 | + |
| 62 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 63 | + input = inp and output = outp |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments