Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 72ef65f

Browse files
committed
Add taint-tracking for syscall
1 parent 362d210 commit 72ef65f

File tree

3 files changed

+178
-0
lines changed

3 files changed

+178
-0
lines changed

ql/src/semmle/go/frameworks/Stdlib.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import semmle.go.frameworks.stdlib.PathFilepath
2020
import semmle.go.frameworks.stdlib.Reflect
2121
import semmle.go.frameworks.stdlib.Strconv
2222
import semmle.go.frameworks.stdlib.Strings
23+
import semmle.go.frameworks.stdlib.Syscall
2324
import semmle.go.frameworks.stdlib.TextScanner
2425
import semmle.go.frameworks.stdlib.TextTabwriter
2526
import semmle.go.frameworks.stdlib.TextTemplate
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
}

ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Syscall.go

Lines changed: 111 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)