В ядре Linux устранена следующая уязвимость:
igc: избегать двойного возврата кадра в XDP_REDIRECT
Когда кадр не может быть передан в XDP_REDIRECT
(например, из-за полной очереди), необходимо освободить
это, вызвав xdp_return_frame_rx_napi. Однако это ответственность вызывающего абонента.
ndo_xdp_xmit (см., например, bq_xmit_all в
kernel/bpf/devmap.c) и, таким образом, вызывая его внутри
igc_xdp_xmit (который является ndo_xdp_xmit файла igc
драйвер) также приведет к повреждению памяти. Фактически, bq_xmit_all ожидает, что он сможет вернуть все
кадров после последнего успешно переданного.
Поэтому перерыв на первый не переданный кадр,
но не вызывайте xdp_return_frame_rx_napi в igc_xdp_xmit. Это в равной степени реализовано и в других драйверах Intel.
например, IGB. Есть две альтернативы этому, которые были отклонены:
1.
Вернуть num_frames, так как все кадры были бы
переданные и освободите их внутри igc_xdp_xmit. Хотя это может работать технически, это не то, что
возвращаемое значение предназначено для представления (т.е.
количество УСПЕШНО переданных пакетов).
2. Переработать файл kernel/bpf/devmap.c и все драйверы на
поддержка непоследовательно отбрасываемых пакетов.
Помимо того, что он сложен, он, вероятно, имеет отрицательный
влияние на производительность без значительного выигрыша
поскольку в любом случае маловероятно, что следующий кадр
может быть передано, если предыдущее было отброшено. Повреждение памяти можно воспроизвести с помощью
следующий скрипт, который приводит к панике ядра
через несколько секунд. По сути, это генерирует больше
трафик, чем может передать сетевая карта i225, и отправляет его
через XDP_REDIRECT от виртуального интерфейса к
физический интерфейс, в котором отбрасываются кадры.
#!/бин/баш
ИНТЕРФЕЙС=enp4s0
INTERFACE_IDX=`cat /sys/class/net/$INTERFACE/ifindex`
sudo ip link добавить dev veth1 тип имя узла veth veth2
настройка sudo ip link $INTERFACE
sudo ip link настроить veth1
sudo ip link настроить veth2
кот << EOF > redirect.bpf.c
SEC("прог")
int перенаправление (struct xdp_md *ctx)
{
вернуть bpf_redirect ($ INTERFACE_IDX, 0);
}
char _license[] SEC("лицензия") = "GPL";
ЭОФ
clang -O2 -g -Wall -target bpf -c redirect.bpf.c -o redirect.bpf.o
sudo ip link set veth2 xdp obj redirect.bpf.o
кот << EOF > pass.bpf.c
SEC("прог")
int pass (struct xdp_md *ctx)
{
вернуть XDP_PASS;
}
char _license[] SEC("лицензия") = "GPL";
ЭОФ
clang -O2 -g -Wall -target bpf -c pass.bpf.c -o pass.bpf.o
sudo ip link set $INTERFACE xdp obj pass.bpf.o
кот << EOF > trafgen.cfg
{
/* Заголовок Ethernet */
0xe8, 0x6a, 0x64, 0x41, 0xbf, 0x46,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
const16(ETH_P_IP),
/* Заголовок IPv4 */
0b01000101,0,# Версия IPv4, МГП, ТОС
const16(1028), # общая длина IPv4 (длина UDP + 20 байт (IP-заголовок))
const16(2), # идентификатор IPv4
0b01000000, 0, # Флаги IPv4, фрагментация выключена
64, # Срок жизни IPv4
17, #Протокол UDP
csumip(14, 33), # контрольная сумма IPv4
/* UDP-заголовок */
10, 0, 1, 1, #IP Src — адаптируем по необходимости
10, 0, 1, 2,#IP Dest — адаптируем по необходимости
const16(6666), # Исходный порт UDP
const16(6666), # Порт назначения UDP
const16(1008), # длина UDP (заголовок UDP 8 байт + длина полезной нагрузки)
csumudp(14, 34), # контрольная сумма UDP
/* Полезная нагрузка */
заполнить('W', 1000),
}
ЭОФ
sudo trafgen -i trafgen.cfg -b3000MB -o veth1 --cpp
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: igc: avoid returning frame twice in XDP_REDIRECT When a frame can not be transmitted in XDP_REDIRECT (e.g. due to a full queue), it is necessary to free it by calling xdp_return_frame_rx_napi. However, this is the responsibility of the caller of the ndo_xdp_xmit (see for example bq_xmit_all in kernel/bpf/devmap.c) and thus calling it inside igc_xdp_xmit (which is the ndo_xdp_xmit of the igc driver) as well will lead to memory corruption. In fact, bq_xmit_all expects that it can return all frames after the last successfully transmitted one. Therefore, break for the first not transmitted frame, but do not call xdp_return_frame_rx_napi in igc_xdp_xmit. This is equally implemented in other Intel drivers such as the igb. There are two alternatives to this that were rejected: 1. Return num_frames as all the frames would have been transmitted and release them inside igc_xdp_xmit. While it might work technically, it is not what the return value is meant to represent (i.e. the number of SUCCESSFULLY transmitted packets). 2. Rework kernel/bpf/devmap.c and all drivers to support non-consecutively dropped packets. Besides being complex, it likely has a negative performance impact without a significant gain since it is anyway unlikely that the next frame can be transmitted if the previous one was dropped. The memory corruption can be reproduced with the following script which leads to a kernel panic after a few seconds. It basically generates more traffic than a i225 NIC can transmit and pushes it via XDP_REDIRECT from a virtual interface to the physical interface where frames get dropped. #!/bin/bash INTERFACE=enp4s0 INTERFACE_IDX=`cat /sys/class/net/$INTERFACE/ifindex` sudo ip link add dev veth1 type veth peer name veth2 sudo ip link set up $INTERFACE sudo ip link set up veth1 sudo ip link set up veth2 cat << EOF > redirect.bpf.c SEC("prog") int redirect(struct xdp_md *ctx) { return bpf_redirect($INTERFACE_IDX, 0); } char _license[] SEC("license") = "GPL"; EOF clang -O2 -g -Wall -target bpf -c redirect.bpf.c -o redirect.bpf.o sudo ip link set veth2 xdp obj redirect.bpf.o cat << EOF > pass.bpf.c SEC("prog") int pass(struct xdp_md *ctx) { return XDP_PASS; } char _license[] SEC("license") = "GPL"; EOF clang -O2 -g -Wall -target bpf -c pass.bpf.c -o pass.bpf.o sudo ip link set $INTERFACE xdp obj pass.bpf.o cat << EOF > trafgen.cfg { /* Ethernet Header */ 0xe8, 0x6a, 0x64, 0x41, 0xbf, 0x46, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, const16(ETH_P_IP), /* IPv4 Header */ 0b01000101, 0, # IPv4 version, IHL, TOS const16(1028), # IPv4 total length (UDP length + 20 bytes (IP header)) const16(2), # IPv4 ident 0b01000000, 0, # IPv4 flags, fragmentation off 64, # IPv4 TTL 17, # Protocol UDP csumip(14, 33), # IPv4 checksum /* UDP Header */ 10, 0, 1, 1, # IP Src - adapt as needed 10, 0, 1, 2, # IP Dest - adapt as needed const16(6666), # UDP Src Port const16(6666), # UDP Dest Port const16(1008), # UDP length (UDP header 8 bytes + payload length) csumudp(14, 34), # UDP checksum /* Payload */ fill('W', 1000), } EOF sudo trafgen -i trafgen.cfg -b3000MB -o veth1 --cpp
Характеристики атаки
Последствия
Строка CVSS v3.1
Тип уязвимости (CWE)
Уязвимые продукты 9
| Конфигурация | От (включительно) | До (исключительно) |
|---|---|---|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
5.13
|
6.1.82
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
6.2
|
6.6.22
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
6.7
|
6.7.10
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.8:rc1:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.8:rc2:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.8:rc3:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.8:rc4:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.8:rc5:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.8:rc6:*:*:*:*:*:*
|
— | — |