
OpenSSL-src-rust は、Rust で記述され、クレートとしてパッケージ化された、OpenSSL をソースからビルドするためのソースコードとロジックです。現在、メンテナンスされている OpenSSL のバージョン に対応する2つのメンテナンスブランチがあります。main は OpenSSL 3.0 をビルドし、release/111 は OpenSSL 1.1.1 をビルドします。
OpenSSL 3.0.4 リリースでは、AVX512IFMA 命令をサポートする X86_64 CPU 向け RSA 実装に深刻なバグが導入されました。この問題により、そのようなマシンでは 2048 ビットの秘密鍵を使用する RSA 実装が不正になり、計算中にメモリ破壊が発生します。メモリ破壊の結果、攻撃者は計算を実行しているマシン上でリモートコード実行を引き起こす可能性があります。X86_64 アーキテクチャの AVX512IFMA 命令をサポートするマシン上で動作し、2048 ビットの RSA 秘密鍵を使用する SSL/TLS サーバーやその他のサーバーは、この問題の影響を受けます。
この脆弱性により、X86_64 アーキテクチャの AVX512IFMA 命令をサポートするマシン上で、openssl-src-rust を使用した OpenSSL バージョン 3.0 のビルドが失敗し、プロセスがクラッシュするようになりました。
openssl-src(Rust)
>= 300.0.8, < 300.0.9
(GHSA-735f-pg76-fxc4)エラーまたはクラッシュを再現する手順は次のとおりです:
AVX512 対応 CPU で OpenSSL-3.0.4 をビルドします(このデモでは Core i7-1065G7 を使用しています)。次のコマンドを使用します:
CFLAGS="-O3 -g -fsanitize=address" ./config
make
テストを実行します:
make V=1 TESTS=test_exp test
サニタイザーは次のように報告します:
==481618==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60c000089400 at pc 0x7f01e32a9509 bp 0x7fff643ec100 sp 0x7fff643ec0f8
READ of size 8 at 0x60c000089400 thread T0
#0 0x7f01e32a9508 in bn_select_words crypto/bn/rsaz_exp.h:64
#1 0x7f01e32a9508 in bn_reduce_once_in_place crypto/bn/rsaz_exp.h:74
#2 0x7f01e32a9508 in ossl_rsaz_mod_exp_avx512_x2 crypto/bn/rsaz_exp_x2.c:223
#3 0x7f01e3287dc8 in BN_mod_exp_mont_consttime_x2 crypto/bn/bn_exp.c:1448
#4 0x4042c3 in test_mod_exp_x2 test/exptest.c:260
#5 0x40611a in run_tests test/testutil/driver.c:370
#6 0x4039ba in main test/testutil/main.c:30
#7 0x7f01e2c29319 in __libc_start_call_main (/usr/lib/libc.so.6+0x29319)
#8 0x7f01e2c293e4 in __libc_start_main_impl (/usr/lib/libc.so.6+0x293e4)
#9 0x403c40 in _start (/home/xry111/sources/lfs/openssl-3.0.4/test/exptest+0x403c40)
0x60c000089400 is located 0 bytes to the right of 128-byte region [0x60c000089380,0x60c000089400)
allocated by thread T0 here:
#0 0x7f01e3ae5107 in __interceptor_malloc ../../../../libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x7f01e34aa7a8 in CRYPTO_zalloc crypto/mem.c:197
SUMMARY: AddressSanitizer: heap-buffer-overflow crypto/bn/rsaz_exp.h:64 in bn_select_words
Shadow bytes around the buggy address:
0x0c1880009230: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa
0x0c1880009240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c1880009250: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c1880009260: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa
0x0c1880009270: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c1880009280:[fa]fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c1880009290: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa
0x0c18800092a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c18800092b0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
0x0c18800092c0: 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa fa
0x0c18800092d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==481618==ABORTING
この問題の発見者は、OpenSSL コードへの以前のコミットがバグを導入した可能性があると指摘しています。そのコミットは、BN_mod_exp_consttime が非還元の結果を生成しないように修正するものでした。bn_reduce_once_in_place 関数がヒープメモリ破壊を引き起こしました。
@@ -220,6 +220,9 @@ int ossl_rsaz_mod_exp_avx512_x2(BN_ULONG *res1,
from_words52(res1, factor_size, rr1_red);
from_words52(res2, factor_size, rr2_red);
bn_reduce_once_in_place(res1, /*carry=*/0, m1, storage, factor_size);
bn_reduce_once_in_place(res2, /*carry=*/0, m2, storage, factor_size);
これは、このコミットにある更新によって修正されました。この更新では、bn_reduce_once_in_place は BN_ULONG の数値を期待するが、factor_size は法のビットサイズであると述べられています。この更新は、2022年10月12日にリリースされた OpenSSL 3.0.5 に含まれました。
@@ -257,6 +257,9 @@ int ossl_rsaz_mod_exp_avx512_x2(BN_ULONG *res1,
from_words52(res1, factor_size, rr1_red);
from_words52(res2, factor_size, rr2_red);
/* bn_reduce_once_in_place expects number of BN_ULONG, not bit size */
factor_size /= sizeof(BN_ULONG) * 8;
bn_reduce_once_in_place(res1, /*carry=*/0, m1, storage, factor_size);
bn_reduce_once_in_place(res2, /*carry=*/0, m2, storage, factor_size);
攻撃者は、ネットワーク(例: TCP/IP ネットワーク)を介して送信を行うことで、この脆弱性を理論的に悪用できる可能性があります。悪用に成功すると、以下の結果を引き起こす可能性があります:
| 重大度 | 緊急 9.8 / 10 |
|---|
| 攻撃元区分 | ネットワーク |
| 攻撃条件の複雑さ | 低 |
| 必要な特権レベル | 不要 |
| ユーザー操作 | 不要 |
| スコープ | 変更なし |
| 機密性への影響 | 高 |
| 完全性への影響 | 高 |
| 可用性への影響 | 高 |