HomeFreeBSD

ifnet: if_detach(): Fix races with vmove operations

Description

ifnet: if_detach(): Fix races with vmove operations

The rationality is that the driver private data holds a strong reference
to the interface, and the detach operation shall never fail. Given the
vmove operation, if_vmove_loan(), if_vmove_reclaim() or vnet_if_return()
is not atomic and spans multiple steps, acquire ifnet_detach_sxlock only
for if_detach_internal() and if_vmove() is not sufficient. It is possible
that the thread running if_detach() sees stale vnet, or the vmoving is
in progress, then if_unlink_ifnet() will fail.

Fix that by extending coverage of ifnet_detach_sxlock a bit to also
cover if_unlink_ifnet(), so that the entire detach and vmove operation
is serialized.

Given it is an error when the if_unlink_ifnet() fails, and if_detach()
is a public KPI, prefer panic() over assertion on failure, to indicate
explicitly that bad thing happens. That shall also prevent potential
corrupted status of the interface, which is a bit hard to diagnose.

PR: 292993
Reviewed by: glebius
MFC after: 5 days
Differential Revision: https://reviews.freebsd.org/D56374

(cherry picked from commit ba7f47d47dc1a177e4d8f115f791ec25f3da0eab)
(cherry picked from commit 5c4021ca0abe4e17200f5faa2fd71014ef0a5f09)

Details

Provenance
zleiAuthored on Apr 25 2026, 7:56 PM
Reviewer
glebius
Differential Revision
D56374: ifnet: if_detach(): Fix races with if_vmove()
Parents
rG33da0a256bfc: tests/netgraph: Add a test for races between if_detach() and vnet_if_return()
Branches
Unknown
Tags
Unknown