В ядре Linux устранена следующая уязвимость: bpf: Fix skb_pull() BUG в выпуске __bpf_redirect_neigh() The: Это продолжение исправлений короткого заголовка уровня ссылок от Eric. После vlan pop_eth, привилегированная программа SCHED_ACT BPF может вызвать bpf_skb_change_head(skb, 1, 0), а затем bpf_redirect_neigh(). __bpf_redirect_neigh() вызывает skb_pull(skb, sizeof(*ethh)) после проверки только того, что mac_header < network_header. Ничто не подтверждает, что заголовок MAC достаточно длинный, что он линейный, или что заголовок IP, который перенаправление продолжает читать, также линейный.
Программа SCHED_ACT BPF может делать: bpf_skb_change_head(skb, 1, 0; bpf_redirect_neigh(lo, NULL, 0, 0; после vlan pop_eth. Затем skb имеет mac_len 1 и только один байт линейных данных; skb_pull(ETH_HLEN) отправляет skb->len < skb->data_len BUG в __skb_pull(): ядро BUG в ./include/linux/skbuff.h:2839! RIP: skb_pull+0x40/0x50 Call Trace: skb_do_redirect -> packet_xmit -> Паника packet_sendmsg Kernel - не синхронизация: исключение Fatal в прерывании Пути v4 и v6 читают ip_hdr() и ipv6_hdr(), как только заголовок MAC исчезнет. На кадре AF_PACKET ниже, который оставляет headlen 0 после вытягивания, поэтому сетевой заголовок сидит на skb->tail, а поиск маршрута читает ip4h->protocol, ip4h->saddr и ip4h->daddr мимо линейной области.
Исправление: Use skb_network_offset(), который представляет собой диапазон заголовков MAC, вместо skb->mac_len. mac_len равен нулю для локально сгенерированных пакетов tc egress и netkit, в то время как диапазон по-прежнему отвергает однобайтовый заголовок, производимый pop_eth + bpf_skb_change_head(skb, 1, 0). Единая проверка также охватывает тест mac_header network_header, который он заменяет. Используйте pskb_may_pull(), чтобы сделать заголовок Ethernet линейным до его чтения или вытягивания, и сделать заголовок IP линейным как в пути v4, так и в пути v6 перед чтением ip_hdr()/ipv6_hdr().
Указатели заголовка берутся после вытягивания, так как pskb_may_pull() может перераспределять skb->head. Условия для воссоздания ошибки: На x86-64 с 4 страницами KiB включите CONFIG_PACKET, CONFIG_BPF_SYSCALL, CONFIG_NET_SCH_INGRESS, CONFIG_NET_CLS_MATCHALL, CONFIG_NET_ACT_VLAN и CONFIG_NET_ACT_BPF. Запустите root с загрузкой BPF, сетевым администрированием и привилегиями raw-packet.
Bring lo up and attach a SCHED_ACT program that calls bpf_skb_change_head(skb, 1, 0), then returns bpf_redirect_neigh(skb->ifindex, NULL, 0, 0): ip link set lo up tc qdisc add dev lo clsact tc filter add dev lo egress matchall action vlan pop_eth pipe \ action bpf object-file neigh_chghead.o section action Send an untagged ETH_P_IP frame of ETH_HLEN + 8192 bytes through an AF_PACKET/SOCK_RAW socket bound to lo, without PACKET_VNET_HDR or PACKET_QDISC_BYPASS. Использовать одноадресный адрес MAC. skb отправителя имеет 14-байтовый линейный префикс Ethernet и фрагментированную полезную нагрузку; pop_eth удаляет этот префикс, а change_head восстанавливает только один линейный байт. Нефиксированный сосед перенаправляет затем пытается вытянуть 14 байт и BUGs.
Отправка одного и того же кадра без pop_eth и change_head оставляет заголовок IP во фрагментах, который является поиском маршрута после skb->tail.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: bpf: Fix skb_pull() BUG in __bpf_redirect_neigh() The issue: This is a follow-up to the short link-layer header fixes from Eric. After vlan pop_eth, a privileged SCHED_ACT BPF program can call bpf_skb_change_head(skb, 1, 0) and then bpf_redirect_neigh(). __bpf_redirect_neigh() calls skb_pull(skb, sizeof(*ethh)) after checking only that mac_header < network_header. Nothing verifies that the MAC header is long enough, that it is linear, or that the IP header the redirect goes on to read is linear either. A SCHED_ACT BPF program can do: bpf_skb_change_head(skb, 1, 0); bpf_redirect_neigh(lo, NULL, 0, 0); after vlan pop_eth. The skb then has mac_len == 1 and only one byte of linear data; skb_pull(ETH_HLEN) trips the skb->len < skb->data_len BUG in __skb_pull(): kernel BUG at ./include/linux/skbuff.h:2839! RIP: skb_pull+0x40/0x50 Call Trace: skb_do_redirect -> packet_xmit -> packet_sendmsg Kernel panic - not syncing: Fatal exception in interrupt The v4 and v6 paths read ip_hdr() and ipv6_hdr() as soon as the MAC header is gone. On the AF_PACKET frame below that leaves headlen == 0 after the pull, so the network header sits at skb->tail and the route lookup reads ip4h->protocol, ip4h->saddr and ip4h->daddr past the linear area. The Fix: Use skb_network_offset(), which is the MAC header span, instead of skb->mac_len. mac_len is zero for locally generated tc egress and netkit packets, while the span still rejects the one-byte header produced by pop_eth + bpf_skb_change_head(skb, 1, 0). The single check also covers the mac_header >= network_header test it replaces. Use pskb_may_pull() to make the Ethernet header linear before it is read or pulled, and to make the IP header linear in both the v4 and the v6 path before ip_hdr()/ipv6_hdr() is read. The header pointers are taken after the pull, since pskb_may_pull() may reallocate skb->head. Conditions to recreate the bug: On x86-64 with 4 KiB pages, enable CONFIG_PACKET, CONFIG_BPF_SYSCALL, CONFIG_NET_SCH_INGRESS, CONFIG_NET_CLS_MATCHALL, CONFIG_NET_ACT_VLAN and CONFIG_NET_ACT_BPF. Run as root with BPF loading, network administration and raw-packet privileges. Bring lo up and attach a SCHED_ACT program that calls bpf_skb_change_head(skb, 1, 0), then returns bpf_redirect_neigh(skb->ifindex, NULL, 0, 0): ip link set lo up tc qdisc add dev lo clsact tc filter add dev lo egress matchall action vlan pop_eth pipe \ action bpf object-file neigh_chghead.o section action Send an untagged ETH_P_IP frame of ETH_HLEN + 8192 bytes through an AF_PACKET/SOCK_RAW socket bound to lo, without PACKET_VNET_HDR or PACKET_QDISC_BYPASS. Use a unicast destination MAC. The sender's skb has a 14-byte linear Ethernet prefix and a fragmented payload; pop_eth removes that prefix and change_head restores only one linear byte. The unfixed neighbor redirect then tries to pull 14 bytes and BUGs. Sending the same frame without pop_eth and change_head leaves the IP header in the frags, which is the route lookup reading past skb->tail.