CWE-558 在多线程应用程序中使用getlogin()

Use of getlogin() in Multithreaded Application

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: unkown

基本描述

The application 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.

相关缺陷

  • cwe_Nature: ChildOf cwe_CWE_ID: 663 cwe_View_ID: 1000 cwe_Ordinal: Primary

适用平台

Language: [{'cwe_Name': 'C', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}]

常见的影响

范围 影响 注释
['Integrity', 'Access Control', 'Other'] ['Modify Application Data', 'Bypass Protection Mechanism', 'Other']

可能的缓解方案

Architecture and Design

策略:

Using names for security purposes is not advised. Names are easy to forge and can have overlapping user IDs, potentially causing confusion or impersonation.

Implementation

策略:

Use getlogin_r() instead, which is reentrant, meaning that other processes are locked out from changing the username.

示例代码

The following code relies on getlogin() to determine whether or not a user is trusted. It is easily subverted.

bad C

pwd = getpwnam(getlogin());
if (isTrustedGroup(pwd->pw_gid)) {
allow();
} else {
deny();
}

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
7 Pernicious Kingdoms Often Misused: Authentication
Software Fault Patterns SFP3 Use of an improper API