CWE-366 单线程内的竞争条件

admin 2022年1月2日04:09:28评论130 views字数 2127阅读7分5秒阅读模式

CWE-366 单线程内的竞争条件

Race Condition within a Thread

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: Medium

基本描述

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.

相关缺陷

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

  • cwe_Nature: ChildOf cwe_CWE_ID: 362 cwe_View_ID: 699 cwe_Ordinal: Primary

适用平台

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

常见的影响

范围 影响 注释
['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 sanity 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.

示例代码

The following example demonstrates the weakness.

bad C

int foo = 0;
int storenum(int num) {

static int counter = 0;
counter++;
if (num > foo) foo = num;
return foo;

}

bad Java

public classRace {

static int foo = 0;
public static void main() {


new Threader().start();
foo = 1;

}
public static class Threader extends Thread {


public void run() {

System.out.println(foo);

}

}

}

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
CLASP Race condition within a thread
CERT C Secure Coding CON32-C CWE More Abstract Prevent data races when accessing bit-fields from multiple threads
CERT C Secure Coding CON40-C CWE More Abstract Do not refer to an atomic variable twice in an expression
CERT C Secure Coding CON43-C Exact Do not allow data races in multithreaded code
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

相关攻击模式

  • CAPEC-26
  • CAPEC-29

引用

文章来源于互联网:scap中文网

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月2日04:09:28
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CWE-366 单线程内的竞争条件http://cn-sec.com/archives/612898.html

发表评论

匿名网友 填写信息