C and C++ Binaries


IO.RACE : ファイルシステム競合状態

要旨

ファイル名をチェックする関数 (check) を実行し、その後その同じファイル名を使用するための関数 (use) を実行したとき、ファイルシステムの競合条件の脆弱性の可能性があります。 ソースコード内では、'check' と 'use' の間で実際のファイルが変更された場合でも、この二つのファイルが同じものと見なしています。 例えば、オリジナルファイルへのリンクを機密情報を含んだファイルへのリンクへ入れ替えてしまうような攻撃が考えられます。

プロパティ

クラス名 File System Race Condition
日本語クラス名 ファイルシステム競合状態
クラス分類 セキュリティ (security)
ニーモニック IO.RACE
カテゴリー
CWE CWE:367 Time-of-check Time-of-use (TOCTOU) Race Condition
CERT-C CERT-C:FIO01-C Be careful using functions that use file names for identification
  CERT-C:FIO24-C Do not open a file that is already open
  CERT-C:FIO45-C Avoid TOCTOU race conditions while accessing files
DISA-6r1 DISA-6r1:V-222567 The application must not be vulnerable to race conditions.
  DISA-6r1:V-222612 The application must not be vulnerable to overflow attacks.
DISA-5r3 DISA-5r3:V-70185 The application must not be vulnerable to race conditions.
  DISA-5r3:V-70277 The application must not be vulnerable to overflow attacks.
DISA-4r3 DISA-4r3:V-70185 The application must not be vulnerable to race conditions.
  DISA-4r3:V-70277 The application must not be vulnerable to overflow attacks.
DISA-3r10 DISA-3r10:V-16804 The designer will ensure the application does not rely solely on a resource name to control access to a resource.
  DISA-3r10:V-16815 The designer will ensure the application is not vulnerable to race conditions.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="File System Race Condition"

ワーニングを引き起こす関数

CodeSonar ships with library models that allow it to a large number of functions that take a file name or directory name argument. If a file/directory name is passed to one of these functions (the check) and later the same name is passed to another of these functions (the use), a warning will be issued.

If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be capable of triggering File System Race Condition warnings.

Functions that can trigger warnings include...
gcc Builtins __builtin_execl(), __builtin_execv(),
libc chmod(), open(), stat()
Win32 CanShareFolderW(), PathMakeUniqueName(), freopen_s()

TOCTTOU(time of check to time of use)脆弱性は、攻撃者に権限のないファイルシステムへのアクセスを許します。 例えば以下のような open 前の unlink は攻撃に関して脆弱です。

#include <fcntl.h>
#include <unistd.h>

void tocttou(const void *secret, size_t secret_size){
    int fdesc;
    /* choose a filename for recording sensitive data */
    char *fname = "myfile.txt";
    /* unlink to ensure that fname isn't already in use by someone else */
    unlink(fname);
    /* DANGER */

    /* open the file and write the data to it */
    fdesc = open(fname, O_CREAT|O_RDWR);           /* 'File System Race Condition' warning issued here */
    if (fdesc < 0){return;}
    (void) write(fdesc, secret, secret_size);
    (void) close(fdesc);
}

の箇所は、攻撃者が myfile.txt ファイルを作成することが可能で、ファイルの所有権を獲得し中身へのアクセスが可能になります。

さらに問題となるのは、 myfile.txt/etc/passwd にリンクすることにより、システムパスワードを壊すことが可能な点です。

多くの TOCTTOU 脆弱性は、ソフトウェアが決められた名前をつけたファイルを攻撃者が使用することで起こります。 これはファイル名ではなくファイルディスクリプタやファイルストリームを参照することで避けることが可能です。

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。