🇰🇷 한글 설명
Linux 커널의 BPF sock_ops 프로그램에서 rtt_min 필드를 읽을 때 소켓 유형을 확인하지 않아 발생하는 Out-of-bounds read 취약점입니다. tcp_conn_request() 경로에서 request_sock 구조체를 tcp_sock로 잘못 캐스팅하여 인접한 커널 메모리를 읽을 수 있습니다.
💡 쉬운 설명
리눅스 운영체제의 핵심 부분에서 데이터의 경계를 넘어서 잘못된 메모리 영역을 읽어버리는 오류가 발견되었습니다. 이로 인해 공격자가 시스템의 중요한 비밀 정보(커널 주소 등)를 훔쳐볼 수 있는 위험이 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
bpf: Fix out-of-bounds read of rtt_min in sock_ops
A sockops prog reading skops->rtt_min never checks the sk type: on the
tcp_conn_request() path sock_ops->sk is a request_sock (non-full), and the
ctx rewrite casts it to a tcp_sock (full) and reads rtt_min past the end of
the request_sock, returning dirty adjacent memory.
SEC("sockops")
int prog(struct bpf_sock_ops *skops)
{
switch (skops->op) {
case BPF_SOCK_OPS_RWND_INIT:
leak = skops->rtt_min; /* reads the request_sock OOB */
...
}
}
For instance one such read returned rtt_min=0xffff8881, the high half of a
leaked kernel pointer.
Guarding that cast is exactly what SOCK_OPS_GET_FIELD() does -- it checks
is_locked_tcp_sock and returns 0 when sock_ops->sk is not a locked full
socket. Every other tcp_sock field in sock_ops goes through it; rtt_min is
the only one open-coded, so it skips the check.
Read rtt_min through SOCK_OPS_GET_FIELD() too. rtt_min is a bit special:
it is a struct minmax and we only want the current min, so pass
rtt_min.s[0].v. That is equivalent to the old hand-computed offset
offsetof(struct tcp_sock, rtt_min) + sizeof_field(struct minmax_sample, t)
(s[0] sits at rtt_min + 0 and .v at + sizeof(.t), i.e. what minmax_get()
returns), so the loaded field is unchanged and only the full-sock guard is
added. The two BUILD_BUG_ON()s that protected the hand-computed offset
are no longer needed.
Before patch:
0: r1 = *(u64 *)(r1 +0) ; r1 = skops->sk
1: r1 = *(u32 *)(r1 +2324) ; ((tcp_sock *)sk)->rtt_min.s[0].v
After patch:
0: *(u64 *)(r1 +56) = r9
1: r9 = *(u8 *)(r1 +50) ; is_locked_tcp_sock
2: if r9 == 0 goto pc+4 ; not a locked full sock -> 0
3: r9 = *(u64 *)(r1 +56)
4: r1 = *(u64 *)(r1 +0) ; r1 = skops->sk
5: r1 = *(u32 *)(r1 +2324) ; rtt_min.s[0].v
6: goto pc+2
7: r9 = *(u64 *)(r1 +56)
8: r1 = 0
📍 영향받는 시스템
Linux Kernel (BPF sock_ops를 사용하는 환경)
⚔️ 공격 벡터
BPF sock_ops 프로그램을 통해 request_sock 구조체의 경계를 넘어 커널 메모리 값을 읽어내는 방식
🛡️ 대응 방법
커널 패치를 적용하여 rtt_min 필드 접근 시 SOCK_OPS_GET_FIELD() 매크로를 통해 소켓 유형 검증을 수행하도록 업데이트해야 합니다.
🔧 검증 코드
출력된 커널 버전이 해당 취약점이 수정된 최신 패치 버전인지 확인합니다.