CWE一覧に戻る
CWE-362

不適切な同期による共有リソースの同時実行(「レースコンディション)

Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
脆弱性 レビュー中
JA

この製品には、共有リソースへの一時的な排他アクセスを必要とする並行コード・シーケンスが含まれているが、並行して動作する別のコード・シーケンスによって共有リソースが変更される可能性のあるタイミング・ウィンドウが存在する。

レースコンディションは並行環境内で発生し、事実上、コードシーケンスの特性である。文脈によって、コード・シーケンスは、関数呼び出し、少数の命令、一連のプログラム呼び出しなどの形になる。

レース・コンディションは、密接に関連するこれらの特性に違反する:

競合状態は、「干渉するコード・シーケンス」がまだ共有リソースにアクセスできるときに存在し、排他性に違反する。

干渉コード・シーケンスには、"信頼できる "ものと "信頼できない "ものがある。信頼された干渉コード・シーケンスは製品内で発生し、攻撃者によって変更されることはなく、間接的にしか呼び出すことができない。信頼されない妨害コード列は、攻撃者が直接作成することができ、通常、脆弱な製品の外部に存在します。

EN

The product contains a concurrent code sequence that requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence operating concurrently.

A race condition occurs within concurrent environments, and it is effectively a property of a code sequence. Depending on the context, a code sequence may be in the form of a function call, a small number of instructions, a series of program invocations, etc.

A race condition violates these properties, which are closely related:

A race condition exists when an "interfering code sequence" can still access the shared resource, violating exclusivity.

The interfering code sequence could be "trusted" or "untrusted." A trusted interfering code sequence occurs within the product; it cannot be modified by the attacker, and it can only be invoked indirectly. An untrusted interfering code sequence can be authored directly by the attacker, and typically it is external to the vulnerable product.

Scope: Availability / Impact: DoS: Resource Consumption (CPU); DoS: Resource Consumption (Memory); DoS: Resource Consumption (Other)
Scope: Availability / Impact: DoS: Crash, Exit, or Restart; DoS: Instability
Scope: Confidentiality, Integrity / Impact: Read Files or Directories; Read Application Data
Scope: Access Control / Impact: Execute Unauthorized Code or Commands; Gain Privileges or Assume Identity; Bypass Protection Mechanism
In languages that support it, use synchronization primitives. Only wrap these around critical code to minimize the impact on performance.
Use thread-safe capabilities such as the data access abstraction in Spring.
Minimize the usage of shared resources in order to remove as much complexity as possible from the control flow and to reduce the likelihood of unexpected conditions occurring.

Additionally, this will minimize the amount of synchronization necessary and may even help to reduce the likelihood of a denial of service where an attacker may be able to repeatedly trigger a critical section (CWE-400).
When using multithreading and operating on shared variables, only use thread-safe functions.
Use atomic operations on shared variables. Be wary of innocent-looking constructs such as "x++". This may appear atomic at the code layer, but it is actually non-atomic at the instruction layer, since it involves a read, followed by a computation, followed by a write.
Use a mutex if available, but be sure to avoid related weaknesses such as CWE-412.
Avoid double-checked locking (CWE-609) and other implementation errors that arise when trying to avoid the overhead of synchronization.
Disable interrupts or signals over critical parts of the code, but also make sure that the code does not go into a large or infinite loop.
Use the volatile type modifier for critical variables to avoid unexpected compiler optimization or reordering. This does not necessarily solve the synchronization problem, but it can help.
Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.
MITRE公式ページ — CWE-362