Page MenuHomeFreeBSD

if_bridge: fix potential panic
ClosedPublic

Authored by kp on May 18 2023, 6:38 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 26 2024, 11:46 AM
Unknown Object (File)
Jan 28 2024, 1:37 AM
Unknown Object (File)
Jan 27 2024, 7:11 PM
Unknown Object (File)
Dec 15 2023, 4:35 PM
Unknown Object (File)
Oct 9 2023, 3:26 AM
Unknown Object (File)
Sep 17 2023, 3:45 PM
Unknown Object (File)
Aug 27 2023, 3:30 AM
Unknown Object (File)
Aug 18 2023, 12:43 AM

Details

Summary

When a new bridge_rtnode is added it is added with a NULL brt_dst. The
brt_dst is set after the entry is added. This means there's a small
window where another core could also attempt to add this node, leading
to the code attempting to log that the MAC addresses moved to a new
interface.
Aside from that being a spurious log entry it also panics, because
obif is NULL (and we attempt to dereference it).

Avoid this by settings brt_dst before we insert the bridge_rtnode.
Assert that obif is non-NULL, as an extra precaution.

Reported by: olivier@

Diff Detail

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

Event Timeline

kp requested review of this revision.May 18 2023, 6:38 PM

Generally looks good to me.

sys/net/if_bridge.c
2944

I think the increasing bif_addrcnt should be kept after bridge_rtnode_insert() succeed .

This revision is now accepted and ready to land.May 19 2023, 7:23 AM
sys/net/if_bridge.c
2945

A second thought, as an alternate we can place a decreasing if bridge_rtnode_insert() fails.

bif->bif_addrcnt--;

Both should be OK, as write operations on bif_addrcnt is protected by BRIDGE_RT_LOCK. Only one read operation may have a small inconsistency window.

static int
bridge_ioctl_gifflags(struct bridge_softc *sc, void *arg)
{
...
    req->ifbr_addrcnt = bif->bif_addrcnt;
...
}
sys/net/if_bridge.c
2944

That is a very good point. I think I like having the increment after the insert more than reducing it again, so I'll do that.

This revision was automatically updated to reflect the committed changes.