🇰🇷 한글 설명
Linux kernel WireGuard의 netlink 인터페이스에서 peer 제거 시 dangling pointer를 제대로 검사하지 않아 이미 해제된 메모리에 접근하는 use-after-free 취약점입니다. wg_peer_remove_all() 함수에서 peer를 스택의 임시 리스트로 이동시킨 후, netlink dump가 resume될 때 해제된 peer에서 반복 작업을 시도합니다.
💡 쉬운 설명
WireGuard VPN 설정을 자주 변경할 때 프로그램이 이미 삭제된 데이터에 접근하려는 메모리 버그입니다. 공격자가 이를 악용하면 커널 크래시나 권한 상승이 가능합니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
wireguard: netlink: check for dangling peer via is_dead instead of empty list
If all peers are removed via wg_peer_remove_all(), rather than setting
peer_list to empty, the peer is added to a temporary list with a head on
the stack of wg_peer_remove_all(). If a netlink dump is resumed and the
cursored peer is one that has been removed via wg_peer_remove_all(), it
will iterate from that peer and then attempt to dump freed peers.
Fix this by instead checking peer->is_dead, which was explictly created
for this purpose. Also move up the device_update_lock lockdep assertion,
since reading is_dead relies on that.
It can be reproduced by a small script like:
echo "Setting config..."
ip link add dev wg0 type wireguard
wg setconf wg0 /big-config
(
while true; do
echo "Showing config..."
wg showconf wg0 > /dev/null
done
) &
sleep 4
wg setconf wg0 <(printf "[Peer]\nPublicKey=$(wg genkey)\n")
Resulting in:
BUG: KASAN: slab-use-after-free in __lock_acquire+0x182a/0x1b20
Read of size 8 at addr ffff88811956ec70 by task wg/59
CPU: 2 PID: 59 Comm: wg Not tainted 6.8.0-rc2-debug+ #5
Call Trace:
<TASK>
dump_stack_lvl+0x47/0x70
print_address_description.constprop.0+0x2c/0x380
print_report+0xab/0x250
kasan_report+0xba/0xf0
__lock_acquire+0x182a/0x1b20
lock_acquire+0x191/0x4b0
down_read+0x80/0x440
get_peer+0x140/0xcb0
wg_get_device_dump+0x471/0x1130
📍 영향받는 시스템
Linux kernel 6.8.0-rc2 이전 버전 (WireGuard 활성 시스템)
⚔️ 공격 벡터
로컬 공격자가 반복적인 wg setconf/wg showconf 명령어 실행으로 netlink dump 조건을 유발하여 use-after-free 트리거
🛡️ 대응 방법
Linux kernel을 6.8.0 이상으로 업그레이드하거나 해당 패치 적용 (peer->is_dead 플래그 사용으로 dangling peer 검사)
🔧 검증 코드
커널 버전이 6.7 이하면 취약, 6.8 이상이면 패치됨. 정확한 확인은 커널 빌드 정보와 패치 로그 검토 필요
uname -r | grep -E '^(6\.[0-7]\.|[0-5]\.)' && echo 'Vulnerable' || echo 'May be patched'