kern: osd: trash a slot's methods upon deregistration

This both lets us quickly identify a slot that's been deallocated while
debugging, and forces us to take a fault if something tries to call one
of the methods anyways somehow with osd_destructors[slot - 1] == NULL.

Reviewed by:	imp, jamie
Differential Revision:	https://reviews.freebsd.org/D48075
This commit is contained in:
Kyle Evans committed 2026-06-24 22:08:24 -05:00
1 parent 72ebcfae48
commit 4ffa7e126e
1 file changed
+12
+12
View File
@@ -180,6 +180,18 @@ osd_deregister(u_int type, u_int slot)
osdm[type].osd_destructors[slot - 1] = NULL;
OSD_DEBUG("Slot deregistration (type=%u, slot=%u).", type, slot);
#ifdef INVARIANTS
/*
* We trash the slot's osd_methods upon deregistration so that we take
* a fault if something calls them, rather than potentially
* inadvertently executing some arbitrary function if another module's
* been mapped over the one that deregistered.
*/
for (u_int method = 0; method < osdm[type].osd_nmethods; method++) {
OSD_METHOD(osdm[type], slot, method) = (void *)0xdeadc0de;
}
#endif
rm_wunlock(&osdm[type].osd_object_lock);
sx_xunlock(&osdm[type].osd_module_lock);
}