Page MenuHomeFreeBSD

bpf: don't clear pointer from descriptor to the tap on descriptor close
ClosedPublic

Authored by glebius on Feb 2 2026, 9:59 PM.
Tags
None
Referenced Files
F157399704: D55064.id171024.diff
Thu, May 21, 12:07 AM
F157399698: D55064.id171024.diff
Thu, May 21, 12:07 AM
F157399689: D55064.id171024.diff
Thu, May 21, 12:07 AM
F157324100: D55064.id171181.diff
Wed, May 20, 8:28 AM
F157311206: D55064.id171024.diff
Wed, May 20, 5:42 AM
Unknown Object (File)
Sun, May 17, 9:24 PM
Unknown Object (File)
Sun, May 17, 2:41 AM
Unknown Object (File)
Fri, May 15, 12:06 AM
Subscribers

Details

Summary

During packet processing the descriptor is looked up using epoch(9) and it
can be accessed after bpf_detachd(). In scenario of descriptor close the
tap point is alive (it actually produces packets) and thus the pointer can
be legitimately dereferenced. This fixes a race on a bpf(4) device close
that would otherwise result in panic.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 70353
Build 67236: arc lint + arc unit

Event Timeline

Is bpf_chkdir() dereferencing a NULL d->bd_bif in net epoch ?

bpfwrite() is locked checking d->bd_bif == NULL and returns ENXIO incase true, and if not, will bpfwrite() then possibly reference a freed bpf_if ?

Is bpf_chkdir() dereferencing a NULL d->bd_bif in net epoch ?

Yes.

bpfwrite() is locked checking d->bd_bif == NULL and returns ENXIO incase true, and if not, will bpfwrite() then possibly reference a freed bpf_if ?

I did not test the writer descriptor case. The panic I'm fixing is about detaching bpf reader. And your question is quite orthogonal: it is not about detaching descriptor, it is a about detaching tap. I can't answer right away, except that suggested patch should neither improve nor regress a scenario with detaching tap. As you see, we still set pointer to NULL when tap is detaching.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 4 2026, 10:07 PM
This revision was automatically updated to reflect the committed changes.