🇰🇷 한글 설명
Linux 커널의 macvlan 모듈에서 macvlan_common_newlink() 함수가 오류 복구 과정에서 발생시키는 Use-After-Free 취약점입니다. 잘못된 링크 생성 시도 시 네트워크 장치가 해제되어도 소스 해시 테이블에 참조가 남아 있어, 이후 패킷 처리 과정에서 커널 충돌을 유발할 수 있습니다.
💡 쉬운 설명
네트워크 설정을 잘못 입력하여 오류가 발생했을 때, 컴퓨터가 사용하던 메모리를 제대로 정리하지 못하는 문제입니다. 이로 인해 해커가 특정 패킷을 보내면 시스템이 갑자기 멈추거나 꺼질 수 있습니다.
🇺🇸 원문 (English)
In the Linux kernel, the following vulnerability has been resolved:
macvlan: fix error recovery in macvlan_common_newlink()
valis provided a nice repro to crash the kernel:
ip link add p1 type veth peer p2
ip link set address 00:00:00:00:00:20 dev p1
ip link set up dev p1
ip link set up dev p2
ip link add mv0 link p2 type macvlan mode source
ip link add invalid% link p2 type macvlan mode source macaddr add 00:00:00:00:00:20
ping -c1 -I p1 1.2.3.4
He also gave a very detailed analysis:
<quote valis>
The issue is triggered when a new macvlan link is created with
MACVLAN_MODE_SOURCE mode and MACVLAN_MACADDR_ADD (or
MACVLAN_MACADDR_SET) parameter, lower device already has a macvlan
port and register_netdevice() called from macvlan_common_newlink()
fails (e.g. because of the invalid link name).
In this case macvlan_hash_add_source is called from
macvlan_change_sources() / macvlan_common_newlink():
This adds a reference to vlan to the port's vlan_source_hash using
macvlan_source_entry.
vlan is a pointer to the priv data of the link that is being created.
When register_netdevice() fails, the error is returned from
macvlan_newlink() to rtnl_newlink_create():
if (ops->newlink)
err = ops->newlink(dev, ¶ms, extack);
else
err = register_netdevice(dev);
if (err < 0) {
free_netdev(dev);
goto out;
}
and free_netdev() is called, causing a kvfree() on the struct
net_device that is still referenced in the source entry attached to
the lower device's macvlan port.
Now all packets sent on the macvlan port with a matching source mac
address will trigger a use-after-free in macvlan_forward_source().
</quote valis>
With all that, my fix is to make sure we call macvlan_flush_sources()
regardless of @create value whenever "goto destroy_macvlan_port;"
path is taken.
Many thanks to valis for following up on this issue.
📍 영향받는 시스템
Linux Kernel (macvlan 모듈 사용 환경)
⚔️ 공격 벡터
특정 MAC 주소를 가진 macvlan 인터페이스를 생성하는 과정에서 의도적으로 오류를 유발한 뒤, 일치하는 소스 MAC 주소를 가진 패킷을 전송
🛡️ 대응 방법
Linux 커널을 최신 보안 패치가 적용된 버전으로 업데이트하여 macvlan_flush_sources() 호출 로직을 적용해야 함
🔧 검증 코드
현재 실행 중인 커널 버전을 확인하여 취약점이 해결된 최신 패치 버전인지 확인합니다.