Page MenuHomeFreeBSD

bpf: Fix potential race conditions
ClosedPublic

Authored by zlei on Jun 25 2024, 7:47 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Feb 3, 12:17 PM
Unknown Object (File)
Nov 29 2024, 10:59 PM
Unknown Object (File)
Sep 26 2024, 8:03 PM
Unknown Object (File)
Sep 23 2024, 11:19 PM
Unknown Object (File)
Sep 23 2024, 6:41 AM
Unknown Object (File)
Sep 22 2024, 8:07 PM
Unknown Object (File)
Sep 16 2024, 3:47 PM
Unknown Object (File)
Sep 11 2024, 7:45 AM

Details

Reviewers
None
Group Reviewers
network
Commits
rG7def047a1ae9: bpf: Fix potential race conditions
Summary

The global lock (BPF_LOCK) does not (and should not) guarantee the
liveness of ifp, so it is potential that bpf_setif() would reference
dead_bpf_if or freed bpf_if.

As the progress of attach is not atomic, there is also a small window
that userland could have inconsistant view of available data link types
of the interface (via BIOCGDLTLIST ioctl).

Fix them by checking our side, aka bpf_iflist, rather than the interface's
side to ensure that the requested interface is attached to bpf.

This have side effect of reverting a bpf interface attach operation
(BIOCSETIF ioctl) from O(1) to O(N) (where N is the number of bpf
interfaces). Well since normally we have sane amount of interfaces and
the attach operation is not frequent, this O(N) is affordable.

Fixes: 16d878cc99ef Fix the following bpf(4) race condition ...
MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

zlei requested review of this revision.Jun 25 2024, 7:47 AM
This revision was not accepted when it landed; it landed in state Needs Review.Mon, Feb 3, 12:17 PM
This revision was automatically updated to reflect the committed changes.