flawopen.com/Teardowns/cve-2021-3156-sudo-baron-samedit
Baron Samedit (CVE-2021-3156) 기술 분석: Sudo의 인자 이스케이프 해제 과정에서 발생한 힙 오버플로우로 인해 10년 만에 드러난 로컬 루트 권한 상승 결함.
서류 검토원에게 '백슬래시가 나오면 다음 글자를 그대로 복사하라'는 엄격한 규칙이 있는 상황을 상상해 보십시오. 서류 끝에 백슬래시만 남겨둔 신청서를 제출하자, 검토원은 종이 여백을 넘어 책상 위 다음 기밀 서류에 결재 도장을 덮어써 버렸습니다.
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';