git: f58af5d9c538 - stable/15 - kern: osd: trash a slot's methods upon deregistration

Kyle Evans <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a75395c.3be0b.6ff622d8__1677.9347600945$1786067382$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=f58af5d9c538130d5bcdfabe1d94b56f32aa6fff

commit f58af5d9c538130d5bcdfabe1d94b56f32aa6fff
Author:     Kyle Evans <[email protected]>
AuthorDate: 2026-06-25 03:08:05 +0000
Commit:     Kyle Evans <[email protected]>
CommitDate: 2026-08-06 23:36:03 +0000

    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
    
    (cherry picked from commit 4ffa7e126ed0081b804bda6fb71a60acf49dabda)
---
 sys/kern/kern_osd.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/sys/kern/kern_osd.c b/sys/kern/kern_osd.c
index b64735e7f93a..94377b39dbc1 100644
--- a/sys/kern/kern_osd.c
+++ b/sys/kern/kern_osd.c
@@ -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);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.