Skip to content

Commit 07605f5

Browse files
author
Ted Reed
committed
Formatting and use lower case string matching
1 parent 107662f commit 07605f5

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-273/PrivilegeDroppingOutoforder.ql

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* @name LinuxPrivilegeDroppingOutoforder
33
* @description A syscall commonly associated with privilege dropping is being called out of order.
4-
Normally a process drops group ID and sets supplimental groups for the target user
5-
before setting the target user ID. This can have security impact if the return code
6-
from these methods is not checked.
4+
* Normally a process drops group ID and sets supplimental groups for the target user
5+
* before setting the target user ID. This can have security impact if the return code
6+
* from these methods is not checked.
77
* @kind problem
88
* @problem.severity recommendation
99
* @id cpp/drop-linux-privileges-outoforder
@@ -16,7 +16,7 @@ import cpp
1616

1717
predicate argumentMayBeRoot(Expr e) {
1818
e.getValue() = "0" or
19-
e.(VariableAccess).getTarget().getName().matches("%oot%")
19+
e.(VariableAccess).getTarget().getName().toLowerCase().matches("%root%")
2020
}
2121

2222
class SetuidLikeFunctionCall extends FunctionCall {
@@ -31,16 +31,15 @@ class SetuidLikeWrapperCall extends FunctionCall {
3131
SetuidLikeFunctionCall baseCall;
3232

3333
SetuidLikeWrapperCall() {
34-
this = baseCall or
34+
this = baseCall
35+
or
3536
exists(SetuidLikeWrapperCall fc |
3637
this.getTarget() = fc.getEnclosingFunction() and
3738
baseCall = fc.getBaseCall()
3839
)
3940
}
4041

41-
SetuidLikeFunctionCall getBaseCall() {
42-
result = baseCall
43-
}
42+
SetuidLikeFunctionCall getBaseCall() { result = baseCall }
4443
}
4544

4645
class CallBeforeSetuidFunctionCall extends FunctionCall {
@@ -62,43 +61,41 @@ class CallBeforeSetuidWrapperCall extends FunctionCall {
6261
CallBeforeSetuidFunctionCall baseCall;
6362

6463
CallBeforeSetuidWrapperCall() {
65-
this = baseCall or
64+
this = baseCall
65+
or
6666
exists(CallBeforeSetuidWrapperCall fc |
6767
this.getTarget() = fc.getEnclosingFunction() and
6868
baseCall = fc.getBaseCall()
6969
)
7070
}
7171

72-
CallBeforeSetuidFunctionCall getBaseCall() {
73-
result = baseCall
74-
}
72+
CallBeforeSetuidFunctionCall getBaseCall() { result = baseCall }
7573
}
7674

7775
predicate setuidBeforeSetgid(
78-
SetuidLikeWrapperCall setuidWrapper,
79-
CallBeforeSetuidWrapperCall setgidWrapper) {
76+
SetuidLikeWrapperCall setuidWrapper, CallBeforeSetuidWrapperCall setgidWrapper
77+
) {
8078
setgidWrapper.getAPredecessor+() = setuidWrapper
8179
}
8280

8381
predicate isAccessed(FunctionCall fc) {
84-
exists(Variable v | v.getAnAssignedValue() = fc) or
85-
exists(Operation c | fc = c.getAChild() | c.isCondition()) or
82+
exists(Variable v | v.getAnAssignedValue() = fc)
83+
or
84+
exists(Operation c | fc = c.getAChild() | c.isCondition())
85+
or
8686
// ignore pattern where result is intentionally ignored by a cast to void.
8787
fc.hasExplicitConversion()
8888
}
8989

90-
from
91-
Function func,
92-
CallBeforeSetuidFunctionCall fc,
93-
SetuidLikeFunctionCall setuid
90+
from Function func, CallBeforeSetuidFunctionCall fc, SetuidLikeFunctionCall setuid
9491
where
9592
setuidBeforeSetgid(setuid, fc) and
9693
// Require the call return code to be used in a condition or assigned.
9794
// This introduces false negatives where the return is checked but then
9895
// errno == EPERM allows execution to continue.
9996
not isAccessed(fc) and
10097
func = fc.getEnclosingFunction()
101-
select fc, "This function is called within " + func + ", and potentially after " +
102-
"$@, and may not succeed. Be sure to check the return code and errno, otherwise permissions " +
103-
"may not be dropped.",
104-
setuid, setuid.getTarget().getName()
98+
select fc,
99+
"This function is called within " + func + ", and potentially after " +
100+
"$@, and may not succeed. Be sure to check the return code and errno, otherwise permissions " +
101+
"may not be dropped.", setuid, setuid.getTarget().getName()

0 commit comments

Comments
 (0)