CWE-273¶
Improper Check for Dropped Privileges. [Privilege-Issues, Improper-Check-Or-Handling-Of-Exceptional-Conditions]
Required inputs: IR
Background Details Demonstrative Examples
Background Details Demonstrative Examples
Example 1
This code attempts to take on the privileges of a user before creating a file, thus avoiding performing the action with unnecessarily high privileges:
Example Language:C++
bool DoSecureStuff(HANDLE hPipe) {
bool fDataWritten = false;
ImpersonateNamedPipeClient(hPipe);
HANDLE hFile = CreateFile(...);
/../
RevertToSelf()
/../
}
The call to ImpersonateNamedPipeClient may fail, but the return value is not checked. If the call fails, the code may execute with higher privileges than intended. In this case, an attacker could exploit this behavior to write a file to a location that the attacker does not have access to.
Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See section 9.4. "3rd-Party Licenses" in the documentation for full details.Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
check_privilege_drop |
setuid(getuid()) call must be followed by a setuid(0) != -1 check. |
None |
False |
discarded_return_with_entity |
Return value of function discarded. |
None |
False |
unhandled_return_value |
Return value of function call not properly checked. |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
allow_assignment_to_globals¶
allow_assignment_to_globals : bool = False
allow_assignment_to_variables_with_pointers¶
allow_assignment_to_variables_with_pointers : bool = True
allowed_functions¶
allowed_functions : set[bauhaus.analysis.config.FunctionName] = {'memcpy', 'memmove', 'memset', 'strcat', 'strcpy', 'strncat', 'strncpy'}
check_operators¶
check_operators : bool = False
functions¶
functions
Allows to declare function names for which a check must exist. The check is expressed as an IR pattern.Type: dict[bauhaus.analysis.config.QualifiedName, bauhaus.ir.common.algorithms.matchers.Matcher]
Default:
{ 'ImpersonateNamedPipeClient': <bauhaus.rules.axivion.expressions.calls.unhandled_return_value.BinaryRelationAnyMatcher object at 0x7f6f1b83a0b0> }
known_check_functions¶
known_check_functions : set[bauhaus.analysis.config.FunctionName] = set()
report_references¶
report_references : bool = False