gve_prep_tso() uses m_pullup() via PULLUP_HDR() to make protocol headers
contiguous in the first mbuf, but both gve_prep_tso() and
gve_tx_fill_ctx_descs() take struct mbuf * by value:
- When m_pullup() allocates a new head mbuf (freeing the old head), the new chain is leaked and callers continue reading, copying, and later freeing the freed mbuf pointer.
- When m_pullup() fails, it frees the chain and returns NULL, leaving callers with a dangling non-NULL pointer that gve_xmit_br() frees a second time on EINVAL.
- In DQO-RDA mode, gve_xmit_dqo() calls gve_map_mbuf_dqo() before gve_prep_tso(), leaving the DMA map pointing at pre-pullup buffers without the updated th->th_sum.
Additionally, gve_prep_tso() pulls up sizeof(struct tcphdr *) (8 bytes)
instead of sizeof(*th) (20 bytes), and gve_xmit_br() falls through to
BPF_MTAP(ifp, NULL) and a doorbell write when a transmit helper frees
the chain and sets *mbuf to NULL on error.
Pass struct mbuf ** into gve_prep_tso(), PULLUP_HDR(), and
gve_xmit_dqo_qpl() (matching gve_xmit_dqo()), and invoke gve_prep_tso()
before DMA mapping and pending-packet allocation so
gve_tx_fill_ctx_descs() only writes descriptors. Fix the TCP header
pullup size to sizeof(*th) followed by *header_len, reject non-IP
EtherTypes, and handle err != 0 with mbuf == NULL || err == EINVAL in
gve_xmit_br() before BPF_MTAP().
Tested on a FreeBSD 14.5 N4 instance (DQO QPL) with INVARIANTS and
MBUF_STRESS_TEST enabled: reproduced the use-after-free panic in
gve_xmit_dqo_qpl() -> m_copydata() with net.inet.ip.mbuf_frag_size=20 on
the unpatched driver, and verified single- and multi-stream TSO sweeps
(mbuf_frag_size = 20, 14, 42, -2, 2048) with tcpdump, DTrace, and
vmstat -z showing 1-for-1 head-replacement propagation and no panics or
mbuf leaks.
Fixes: d438b4ef0cfc ("gve: Add DQO RDA support")
Fixes: 2348ac893d10 ("gve: Add DQO QPL support")
Reviewed-by: Jasper Tran O'Leary <jtranoleary@google.com>
Signed-off-by: Tim Hostetler <thostet@google.com>