You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

When multiple threads can read or modify the same data, use mutual exclusion primitives to avoid software flaws that could lead to security vulnerabilities. Concurrency problems can often result in abnormal termination or denial of service, but it is possible for them to result in more serious vulnerabilities.

Non-Compliant Code Example

Assume this simplified code is part of a multithreaded bank system. Threads will call credit() and debit() as money is deposited into and taken from the single account. Because the addition and subtraction operations are not atomic, it is possible that two operations could occur concurrently but only the result of one would be saved. For example, an attacker could credit the account with a sum of money and make a very large number of small debits concurrently. Some of the debits might not affect the account balance because of the race condition, so the attacker is effectively creating money.

int account_balance;

void debit(int amount)
{
  account_balance \-= amount;
}

void credit(int amount)
{
  account_balance \+= amount;
}

Compliant Solution

This solution uses a mutex to make credits and debits atomic operations. All credits and debits will now effect the account balance, so an attacker cannot exploit the race condition to steal money from the bank.

int account_balance;
mutex_t account_lock;

void debit(int amount)
{
  mutex_lock(&account_lock);
  account_balance \-= amount;
  mutex_unlock(&account_lock);
}

void credit(int amount)
{
  mutex_lock(&account_lock);
  account_balance \+= amount;
  mutex_unlock(&account_lock);
}

Risk Assessment

Race conditions caused by multiple threads concurrently accessing and modifying the same data could lead to abnormal termination and denial-of-service attacks, or in cases like the above data integrity violation.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

MSC06-A

2 (medium)

1 (unlikely)

1 (high)

P2

L3

References

[[Seacord 05]] Chapter 7, "File I/O"

  • No labels