Description
The product uses the getlogin() function in a multithreaded context, potentially causing it to return incorrect values.
The getlogin() function returns a pointer to a string that contains the name of the user associated with the calling process. The function is not reentrant, meaning that if it is called from another process, the contents are not locked out and the value of the string can be changed by another process. This makes it very risky to use because the username can be changed by other processes, so the results of the function cannot be trusted.
Potential Impact
Integrity, Access Control, Other
Modify Application Data, Bypass Protection Mechanism, Other
Demonstrative Examples
pwd = getpwnam(getlogin());if (isTrustedGroup(pwd->pw_gid)) {allow();} else {deny();}Mitigations & Prevention
Using names for security purposes is not advised. Names are easy to forge and can have overlapping user IDs, potentially causing confusion or impersonation.
Use getlogin_r() instead, which is reentrant, meaning that other processes are locked out from changing the username.
Detection Methods
- Automated Static Analysis — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea
Related Weaknesses
Taxonomy Mappings
- 7 Pernicious Kingdoms: — Often Misused: Authentication
- Software Fault Patterns: SFP3 — Use of an improper API
Frequently Asked Questions
What is CWE-558?
CWE-558 (Use of getlogin() in Multithreaded Application) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Variant-level weakness. The product uses the getlogin() function in a multithreaded context, potentially causing it to return incorrect values.
How can CWE-558 be exploited?
Attackers can exploit CWE-558 (Use of getlogin() in Multithreaded Application) to modify application data, bypass protection mechanism, other. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-558?
Key mitigations include: Using names for security purposes is not advised. Names are easy to forge and can have overlapping user IDs, potentially causing confusion or impersonation.
What is the severity of CWE-558?
CWE-558 is classified as a Variant-level weakness (Low-Medium abstraction). Its actual severity depends on the specific context and how the weakness manifests in your application.