flawopen.com/Teardowns/cve-2021-3156-sudo-baron-samedit
Baron Samedit (CVE-2021-3156) の技術的解説:Sudo のコマンドライン引数解析ルーチンに10年間潜んでいたエスケープ処理の不備と Root 権限昇格の手順。
書類審査員には「バックスラッシュがあれば次の1文字をそのまま書き写す」というルールがあると想像してください。末尾がバックスラッシュで終わる書類を渡された審査員は、用紙の端を越えて机の上の書類にまでペンを走らせ、他の申請書の許可印を勝手に書き換えてしまいました。
setuid バイナリヒープオーバーフローローカル権限昇格根本原因は、オープンソースシステムにおける未検証の境界パラメータに起因し、状態の非同期化とセキュリティ制御の迂回を可能にします。
Unprivileged user executes 'sudoedit -s \', bypassing normal argument escaping flags.
The unescape pointer jumps past the null byte delimiter into uninitialized heap memory.
The heap overflow overwrites the sudo_nss service structure in glibc.
Sudo loads an attacker-controlled shared library (/tmp/libnss_x.so.2) as root, granting instant root shell access.
/* VULNERABLE: Unescape loop skips past string termination null byte */
for (to = user_args, from = NewArgv[0]; *from != '\0'; from++) {
if (from[0] == '\\' && !isspace((unsigned char)from[1]))
from++; /* BUG: If from[1] == '\0', loop skips past null terminator! */
*to++ = *from;
}
*to = '\0'; /* Corrupts adjacent heap chunks with root auth structures */
/* FIXED: Explicitly check that from[1] is neither space nor the null byte */
for (to = user_args, from = NewArgv[0]; *from != '\0'; from++) {
if (from[0] == '\\' && from[1] != '\0' && !isspace((unsigned char)from[1]))
from++;
*to++ = *from;
}
*to = '\0';