-
Notifications
You must be signed in to change notification settings - Fork 33
/
missing-runlock-on-rwmutex.yaml
54 lines (53 loc) · 1.43 KB
/
missing-runlock-on-rwmutex.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
rules:
- id: missing-runlock-on-rwmutex
message: >-
Missing `RUnlock` on an `RWMutex` (`$T` variable) lock before returning from a function
languages: [go]
severity: ERROR
metadata:
category: security
cwe: "CWE-667: Improper Locking"
subcategory: [vuln]
confidence: MEDIUM
likelihood: HIGH
impact: MEDIUM
technology: [--no-technology--]
description: "Missing `RUnlock` on an `RWMutex` lock before returning from a function"
references:
- https://pkg.go.dev/sync#RWMutex
- https://blog.trailofbits.com/2020/06/09/how-to-check-if-a-mutex-is-locked-in-go/
patterns:
- pattern-either:
- pattern: panic(...)
- pattern: return ...
- metavariable-pattern:
metavariable: $T
patterns:
- pattern: |
($T : sync.RWMutex)
- pattern-inside: |
$T.RLock()
...
- pattern-not-inside: |
$T.RUnlock()
...
- pattern-not-inside: |
defer $T.RUnlock()
...
- pattern-not-inside: |
defer func(...) {
...
$T.RUnlock()
...
}(...)
...
- pattern-not-inside: |
$FOO(..., ..., func(...) {
...
})
- pattern-not-inside: |
return func(...) {
...
$T.RUnlock()
...
}