CWE-567 在多现场上下文中未能对共享数据进行同步访问

admin 2021年12月16日16:17:27评论252 views字数 2413阅读8分2秒阅读模式

CWE-567 在多现场上下文中未能对共享数据进行同步访问

Unsynchronized Access to Shared Data in a Multithreaded Context

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: unkown

基本描述

The product does not properly synchronize shared data, such as static variables across threads, which can lead to undefined behavior and unpredictable data changes.

扩展描述

Within servlets, shared static variables are not protected from concurrent access, but servlets are multithreaded. This is a typical programming mistake in J2EE applications, since the multithreading is handled by the framework. When a shared variable can be influenced by an attacker, one thread could wind up modifying the variable to contain data that is not valid for a different thread that is also using the data within the variable.

Note that this weakness is not unique to servlets.

相关缺陷

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

  • cwe_Nature: CanPrecede cwe_CWE_ID: 488 cwe_View_ID: 1000

适用平台

Language: {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}

常见的影响

范围 影响 注释
['Confidentiality', 'Integrity', 'Availability'] ['Read Application Data', 'Modify Application Data', 'DoS: Instability', 'DoS: Crash, Exit, or Restart'] If the shared variable contains sensitive data, it may be manipulated or displayed in another user session. If this data is used to control the application, its value can be manipulated to cause the application to crash or perform poorly.

可能的缓解方案

Implementation

策略:

Remove the use of static variables used between servlets. If this cannot be avoided, use synchronized access for these variables.

示例代码

The following code implements a basic counter for how many times the page has been accesed.

bad Java

public static class Counter extends HttpServlet {

static int count = 0;
protected void doGet(HttpServletRequest in, HttpServletResponse out)
throws ServletException, IOException {

out.setContentType("text/plain");
PrintWriter p = out.getWriter();
count++;
p.println(count + " hits so far!");

}

}

Consider when two separate threads, Thread A and Thread B, concurrently handle two different requests:

None

At this point, both Thread A and Thread B print that one hit has been seen, even though two separate requests have been processed. The value of count should be 2, not 1.

While this example does not have any real serious implications, if the shared variable in question is used for resource tracking, then resource consumption could occur. Other scenarios exist.

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
The CERT Oracle Secure Coding Standard for Java (2011) VNA00-J Ensure visibility when accessing shared primitive variables
The CERT Oracle Secure Coding Standard for Java (2011) VNA02-J Ensure that compound operations on shared variables are atomic
Software Fault Patterns SFP19 Missing Lock

相关攻击模式

  • CAPEC-25

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

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年12月16日16:17:27
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CWE-567 在多现场上下文中未能对共享数据进行同步访问https://cn-sec.com/archives/613104.html

发表评论

匿名网友 填写信息