HomeFreeBSD

if_ovpn: free crp, mbuf, and release refcount on crypto_dispatch() failure

Description

if_ovpn: free crp, mbuf, and release refcount on crypto_dispatch() failure

When crypto_dispatch() or crypto_dispatch_async() returns non-zero,
the registered callback is never invoked. In both ovpn_transmit_to_peer()
and ovpn_udp_input(), if_ovpn.c did not free the cryptop request, release
the peer/sc reference count, or free the mbuf on dispatch failure.

This results in three simultaneous leaks per failed dispatch:

  • crp allocated via crypto_getreq() is never freed
  • peer->refcount (encrypt) or sc->refcount (decrypt) incremented but never decremented
  • mbuf passed to crypto_use_mbuf() is never freed

The leaks are reachable under memory pressure when the OCF scheduler
returns ENOMEM from crypto_dispatch(). The registered callbacks
(ovpn_encrypt_tx_cb, ovpn_decrypt_rx_cb) correctly handle crp_etype
for crypto operation failures; this fix addresses the separate
dispatch-level failure path where no callback is invoked.

Found during code review following FreeBSD-SA-26:52.if_wg.

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D58754

Details

Provenance
ing.castellanosdz_gmail.comAuthored on Aug 10 2026, 1:09 PM
kpCommitted on Aug 10 2026, 1:09 PM
Reviewer
kp
Differential Revision
D58754: if_ovpn: free crp, mbuf, and release refcount on crypto_dispatch() failure
Parents
rG46241b7d6647: iavf: Do not publish link-up while stopped
Branches
Unknown
Tags
Unknown