CWE-366: Race Condition within a Thread

Base Draft Simple

CWE版本: 4.18

更新日期: 2025-09-09

弱点描述

If two threads of execution use a resource simultaneously, there exists the possibility that resources may be used while invalid, in turn making the state of execution undefined.

常见后果

影响范围: Integrity Other

技术影响: Alter Execution Logic Unexpected State

说明: The main problem is that -- if a lock is overcome -- data could be altered in a bad state.

潜在缓解措施

阶段: Architecture and Design

描述: Use locking functionality. This is the recommended solution. Implement some form of locking mechanism around code which alters or reads persistent data in a multithreaded environment.

阶段: Architecture and Design

描述: Create resource-locking validation checks. If no inherent locking mechanisms exist, use flags and signals to enforce your own blocking scheme when resources are being used by other threads of execution.

检测方法

方法: 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 searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

有效性: High

观察示例

参考: CVE-2022-2621

Chain: two threads in a web browser use the same resource (CWE-366), but one of those threads can destroy the resource before the other has completed (CWE-416).

引入模式

阶段 说明
Implementation -

适用平台

编程语言
C (Undetermined) C++ (Undetermined) Java (Undetermined) C# (Undetermined)

分类映射

分类名称 条目ID 条目名称 映射适配度
CLASP - Race condition within a thread -
CERT C Secure Coding CON32-C Prevent data races when accessing bit-fields from multiple threads CWE More Abstract
CERT C Secure Coding CON40-C Do not refer to an atomic variable twice in an expression CWE More Abstract
CERT C Secure Coding CON43-C Do not allow data races in multithreaded code Exact
The CERT Oracle Secure Coding Standard for Java (2011) VNA02-J Ensure that compound operations on shared variables are atomic -
The CERT Oracle Secure Coding Standard for Java (2011) VNA03-J Do not assume that a group of calls to independently atomic methods is atomic -
Software Fault Patterns SFP19 Missing Lock -
关键信息

CWE ID: CWE-366

抽象级别: Base

结构: Simple

状态: Draft

利用可能性: Medium

相关弱点
相关攻击模式
CAPEC-26 CAPEC-29