Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178259521
D62295.1796355367.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D62295.1796355367.diff
View Options
Index: sys/net/if_bridge.c
===================================================================
--- sys/net/if_bridge.c
+++ sys/net/if_bridge.c
@@ -223,9 +223,11 @@
*/
#define BRIDGE_LOCK_INIT(_sc) do { \
sx_init(&(_sc)->sc_sx, "if_bridge"); \
+ sx_init(&(_sc)->sc_ioctl_sx, "if_bridge ioctl lifetime"); \
mtx_init(&(_sc)->sc_rt_mtx, "if_bridge rt", NULL, MTX_DEF); \
} while (0)
#define BRIDGE_LOCK_DESTROY(_sc) do { \
+ sx_destroy(&(_sc)->sc_ioctl_sx); \
sx_destroy(&(_sc)->sc_sx); \
mtx_destroy(&(_sc)->sc_rt_mtx); \
} while (0)
@@ -285,7 +287,9 @@
struct ifnet *sc_ifp; /* make this an interface */
LIST_ENTRY(bridge_softc) sc_list;
struct sx sc_sx;
+ struct sx sc_ioctl_sx;
struct mtx sc_rt_mtx;
+ bool sc_ioctl_dying; /* protected by bridge_ioctl_sx */
uint32_t sc_brtmax; /* max # of addresses */
uint32_t sc_brtcnt; /* cur. # of addresses */
uint32_t sc_brttimeout; /* rt timeout in seconds */
@@ -307,6 +311,8 @@
VNET_DEFINE_STATIC(struct sx, bridge_list_sx);
#define V_bridge_list_sx VNET(bridge_list_sx)
+static struct sx bridge_ioctl_sx;
+SX_SYSINIT(bridge_ioctl_sx, &bridge_ioctl_sx, "if_bridge ioctl");
static eventhandler_tag bridge_detach_cookie;
int bridge_rtable_prune_period = BRIDGE_RTABLE_PRUNE_PERIOD;
@@ -857,6 +863,7 @@
ifp = sc->sc_ifp = if_alloc(IFT_ETHER);
BRIDGE_LOCK_INIT(sc);
+ sc->sc_ioctl_dying = false;
sc->sc_brtmax = BRIDGE_RTABLE_MAX;
sc->sc_brttimeout = BRIDGE_RTABLE_TIMEOUT;
@@ -921,6 +928,7 @@
sc = __containerof(ctx, struct bridge_softc, sc_epoch_ctx);
BRIDGE_LOCK_DESTROY(sc);
+ free(sc->sc_rthash, M_DEVBUF);
free(sc, M_DEVBUF);
}
@@ -932,9 +940,22 @@
static int
bridge_clone_destroy(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags)
{
- struct bridge_softc *sc = ifp->if_softc;
+ struct bridge_softc *sc;
struct bridge_iflist *bif;
+ /*
+ * Close admission before draining ioctls that already hold the per-softc
+ * lifetime lock. Once sc_ioctl_dying is visible under the global gate,
+ * no new ioctl can wait on sc_ioctl_sx.
+ */
+ sx_xlock(&bridge_ioctl_sx);
+ sc = ifp->if_softc;
+ sc->sc_ioctl_dying = true;
+ sx_xunlock(&bridge_ioctl_sx);
+
+ sx_xlock(&sc->sc_ioctl_sx);
+ sx_xunlock(&sc->sc_ioctl_sx);
+
BRIDGE_LOCK(sc);
bridge_stop(ifp);
@@ -963,6 +984,11 @@
IFQ_PURGE(&ifp->if_snd);
#endif
ether_ifdetach(ifp);
+
+ sx_xlock(&bridge_ioctl_sx);
+ ifp->if_softc = NULL;
+ sx_xunlock(&bridge_ioctl_sx);
+
if_free(ifp);
NET_EPOCH_CALL(bridge_clone_destroy_cb, &sc->sc_epoch_ctx);
@@ -978,7 +1004,7 @@
static int
bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
- struct bridge_softc *sc = ifp->if_softc;
+ struct bridge_softc *sc;
struct ifreq *ifr = (struct ifreq *)data;
struct bridge_iflist *bif;
struct thread *td = curthread;
@@ -995,6 +1021,30 @@
const struct bridge_control *bc;
int error = 0, oldmtu;
+ /*
+ * Admit the ioctl while the global gate stabilizes if_softc and the
+ * dying flag. The per-softc shared lock then protects the lifetime for
+ * the complete handler, including temporary drops of BRIDGE_LOCK.
+ */
+ sx_slock(&bridge_ioctl_sx);
+ sc = ifp->if_softc;
+ if (sc == NULL || sc->sc_ioctl_dying) {
+ sx_sunlock(&bridge_ioctl_sx);
+ return (ENXIO);
+ }
+ /*
+ * An exclusive holder must set sc_ioctl_dying while holding the
+ * global gate before acquiring this lock, so this try-lock cannot
+ * fail for a live softc. Fail closed if that invariant is violated.
+ */
+ if (__predict_false(!sx_try_slock(&sc->sc_ioctl_sx))) {
+ KASSERT(0, ("%s: live softc has an exclusive ioctl holder",
+ __func__));
+ sx_sunlock(&bridge_ioctl_sx);
+ return (ENXIO);
+ }
+ sx_sunlock(&bridge_ioctl_sx);
+
BRIDGE_LOCK(sc);
switch (cmd) {
@@ -1132,6 +1182,7 @@
}
BRIDGE_UNLOCK(sc);
+ sx_sunlock(&sc->sc_ioctl_sx);
return (error);
}
@@ -3699,7 +3750,6 @@
KASSERT(sc->sc_brtcnt == 0,
("%s: %d bridge routes referenced", __func__, sc->sc_brtcnt));
- free(sc->sc_rthash, M_DEVBUF);
}
/*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 4, 3:36 AM (40 m, 14 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42196170
Default Alt Text
D62295.1796355367.diff (3 KB)
Attached To
Mode
D62295: if_bridge: Serialize ioctls with interface destruction
Attached
Detach File
Event Timeline