|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `sync/atomic` package. |
| 3 | + */ |
| 4 | + |
| 5 | +import go |
| 6 | + |
| 7 | +/** Provides models of commonly used functions in the `sync/atomic` package. */ |
| 8 | +module SyncAtomic { |
| 9 | + private class FunctionModels extends TaintTracking::FunctionModel { |
| 10 | + FunctionInput inp; |
| 11 | + FunctionOutput outp; |
| 12 | + |
| 13 | + FunctionModels() { |
| 14 | + // signature: func AddUintptr(addr *uintptr, delta uintptr) (new uintptr) |
| 15 | + hasQualifiedName("sync/atomic", "AddUintptr") and |
| 16 | + ( |
| 17 | + inp.isParameter(1) and |
| 18 | + (outp.isParameter(0) or outp.isResult()) |
| 19 | + ) |
| 20 | + or |
| 21 | + // signature: func CompareAndSwapPointer(addr *unsafe.Pointer, old unsafe.Pointer, new unsafe.Pointer) (swapped bool) |
| 22 | + hasQualifiedName("sync/atomic", "CompareAndSwapPointer") and |
| 23 | + (inp.isParameter(2) and outp.isParameter(0)) |
| 24 | + or |
| 25 | + // signature: func CompareAndSwapUintptr(addr *uintptr, old uintptr, new uintptr) (swapped bool) |
| 26 | + hasQualifiedName("sync/atomic", "CompareAndSwapUintptr") and |
| 27 | + (inp.isParameter(2) and outp.isParameter(0)) |
| 28 | + or |
| 29 | + // signature: func LoadPointer(addr *unsafe.Pointer) (val unsafe.Pointer) |
| 30 | + hasQualifiedName("sync/atomic", "LoadPointer") and |
| 31 | + (inp.isParameter(0) and outp.isResult()) |
| 32 | + or |
| 33 | + // signature: func LoadUintptr(addr *uintptr) (val uintptr) |
| 34 | + hasQualifiedName("sync/atomic", "LoadUintptr") and |
| 35 | + (inp.isParameter(0) and outp.isResult()) |
| 36 | + or |
| 37 | + // signature: func StorePointer(addr *unsafe.Pointer, val unsafe.Pointer) |
| 38 | + hasQualifiedName("sync/atomic", "StorePointer") and |
| 39 | + (inp.isParameter(1) and outp.isParameter(0)) |
| 40 | + or |
| 41 | + // signature: func StoreUintptr(addr *uintptr, val uintptr) |
| 42 | + hasQualifiedName("sync/atomic", "StoreUintptr") and |
| 43 | + (inp.isParameter(1) and outp.isParameter(0)) |
| 44 | + or |
| 45 | + // signature: func SwapPointer(addr *unsafe.Pointer, new unsafe.Pointer) (old unsafe.Pointer) |
| 46 | + hasQualifiedName("sync/atomic", "SwapPointer") and |
| 47 | + ( |
| 48 | + inp.isParameter(1) and outp.isParameter(0) |
| 49 | + or |
| 50 | + inp.isParameter(0) and outp.isResult() |
| 51 | + ) |
| 52 | + or |
| 53 | + // signature: func SwapUintptr(addr *uintptr, new uintptr) (old uintptr) |
| 54 | + hasQualifiedName("sync/atomic", "SwapUintptr") and |
| 55 | + ( |
| 56 | + inp.isParameter(1) and outp.isParameter(0) |
| 57 | + or |
| 58 | + inp.isParameter(0) and outp.isResult() |
| 59 | + ) |
| 60 | + } |
| 61 | + |
| 62 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 63 | + input = inp and output = outp |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + private class MethodModels extends TaintTracking::FunctionModel, Method { |
| 68 | + FunctionInput inp; |
| 69 | + FunctionOutput outp; |
| 70 | + |
| 71 | + MethodModels() { |
| 72 | + // signature: func (*Value).Load() (x interface{}) |
| 73 | + this.hasQualifiedName("sync/atomic", "Value", "Load") and |
| 74 | + (inp.isReceiver() and outp.isResult()) |
| 75 | + or |
| 76 | + // signature: func (*Value).Store(x interface{}) |
| 77 | + this.hasQualifiedName("sync/atomic", "Value", "Store") and |
| 78 | + (inp.isParameter(0) and outp.isReceiver()) |
| 79 | + } |
| 80 | + |
| 81 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 82 | + input = inp and output = outp |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments