[BUG] drivers/net/ftmac100.c: device-reported RX frame length drives an unbounded `memcpy` into the fixed packet buffer (OOB write)
Los mantenedores suelen responder en 1 día
Ya se ha fusionado un pull request relacionado.
- #21304 de @Swatantra-66 — fusionado
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 70/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- c
- Área
- embedded-iot, security
Línea de trabajo
Empieza con ftmac100_receive() en drivers/net/ftmac100.c y luego revisa la máscara de longitud RX en include/nuttx/net/ftmac100.h y el tamaño del búfer de paquetes en el controlador. Confirma la longitud máxima aceptada frente a la capacidad del destino y compara la ruta de rechazo en drivers/net/encx24j600.c. El trabajo estará terminado cuando las tramas demasiado grandes o no válidas se descarten de forma segura y se superen las comprobaciones pertinentes del controlador.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description / Steps to reproduce the issue
In drivers/net/ftmac100.c (Faraday FTMAC100 10/100 MAC) the RX path memcpys the DMA-descriptor
frame length into the fixed packet buffer with no clamp against buffer capacity. The bound is
absent in all build configurations (not assert-gated). This is an out-of-bounds write of up
to ~1455 bytes of wire-controlled data past the per-interface packet buffer, into adjacent interface
buffers / BSS. The attacker is a link peer (or a malfunctioning/compromised MAC) that reports an
oversized RX frame length in the DMA descriptor status word.
ftmac100_receive() reads the RX frame length directly from the DMA descriptor and memcpys
that many bytes into the device packet buffer with no clamp against the buffer capacity:
/* drivers/net/ftmac100.c */
624 len = FTMAC100_RXDES0_RFL(rxdes->rxdes0); /* RX Frame Length from DMA descriptor */
625 data = (FAR uint8_t *)rxdes->rxdes2; /* DMA RX buffer pointer */
...
635 memcpy(priv->ft_dev.d_buf, data, len); /* no clamp vs d_buf capacity */
636 priv->ft_dev.d_len = len;
FTMAC100_RXDES0_RFL (include/nuttx/net/ftmac100.h:118) is ((des) & 0x7ff), i.e. a value
of 0..2047 taken verbatim from the descriptor status word the MAC/DMA writes.
The destination priv->ft_dev.d_buf is g_pktbuf[intf] (ftmac100.c:180,1353), sized
PKTBUF_SIZE = MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE. With the default
CONFIG_NET_ETH_PKTSIZE = 590 (include/nuttx/net/netconfig.h:207) the buffer is ~592 bytes,
so a reported length up to 2047 overflows it by up to ~1455 bytes.
There is no length check at all — not even a DEBUGASSERT — between the RFL read at :624
and the memcpy at :635. ftmac100_receive() runs off the RX interrupt work path for every
received frame; the length field is attacker/wire controlled and no userspace open()/read() is
required. Gated by CONFIG_FTMAC100 (e.g. QEMU/moxart, k210-class targets).
Why this is a bug (smoking gun): a sibling MAC driver rejects the oversized length.
drivers/net/encx24j600.c:1620-1628 reads the hardware RX status-vector length and drops the
frame when it is out of range:
else if (pktlen > (CONFIG_NET_ETH_PKTSIZE + 4) || pktlen <= (ETH_HDRLEN + 4))
{ nerr("Bad packet size dropped"); enc_rxrmpkt(...); NETDEV_RXERRORS(...); }
ftmac100 omits this equivalent bounds check on the same kind of device-reported RX length.
Note the precondition is modest: the destination is only ~592 bytes (default config) while the RFL
field allows up to 2047 and the DMA RX region is 2044 bytes, so any ordinary receivable frame larger
than ~592 bytes (a normal ~1000-byte Ethernet frame) already overflows via the unchecked memcpy —
no forged 2000-byte giant frame is required. The ~1455-byte figure is just the worst case
(2047 - 592).
Steps:
- Build with
CONFIG_FTMAC100and bring up the interface. - From a link peer (or a malfunctioning/compromised MAC) deliver/report an RX frame larger than the
~592-byted_buf— an ordinary ~1000-byte Ethernet frame suffices; up to 2047 is possible. ftmac100_receive()memcpys that many bytes into the ~592-byteg_pktbuf, overflowing it.
An AddressSanitizer build with the RFL mask (0x7ff), the 592-byte g_pktbuf, and an unclamped
memcpy of a normal oversize frame (e.g. len=1000) reports:
heap-buffer-overflow WRITE past the 592-byte region
Suggested fix: before the memcpy, reject or clamp the reported length, mirroring the
encx24j600 check:
if (len > CONFIG_NET_ETH_PKTSIZE || len <= ETH_HDRLEN)
{
NETDEV_RXERRORS(&priv->ft_dev);
/* drop the frame, advance the descriptor */
}
On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
ubuntu 22
NuttX Version
master
Issue Architecture
[Arch: all]
Issue Area
[Area: Drivers]
Host information
No response
Verification
- I have verified before submitting the report.
- Lenguaje dominante
- C
- Estrellas
- 4.1k
- Forks
- 1.7k
- Merge medio
- 1 d 3 h
- PR fusionados (30 d)
- 786
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/nuttx
-
[BUG] drivers/net/lan9250.c: `.bss`/global `pktbuf` overflow in `lan9250_recv_buffer` — RX-status packet length bounded only by `DEBUGASSERT` (SPI path only)Posiblemente ocupada @SofianElmotiem la tomó hoy. AbiertoArch: all Area: Drivers OS: Linux Type: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
apache/nuttx#21112 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
apache/nuttx#19435 · 8 comentarios ·
Los mantenedores suelen responder en 1 día
-
Type: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
apache/nuttx#17343 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Arch: all OS: Linux Type: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
apache/nuttx#16249 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
-
Type: Enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
Todos los issues de apache/nuttx
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
colbymchenry/codegraph#3223 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
arduino/ArduinoCore-megaavr#152 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
FujiNetWIFI/fujinet-firmware#2261 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
kivy/python-for-android#3405 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Nmap
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día