HomeFreeBSD

kern: osd: avoid dereferencing freed slots

Description

kern: osd: avoid dereferencing freed slots

If a slot is freed that isn't the last one, we'll set its destructor to
NULL to indicate that it's been freed and leave a hole in the slot map.
Check osd_destructors in osd_call() to avoid dereferencing a method that
is potentially from a module that's been unloaded.

This scenario would most commonly surface when two modules are loaded
that osd_register(), then the earlier one deregisters and an osd_call()
is made after the fact. In the specific report that triggered the
investigation, kldload if_wg -> kldload linux* -> kldunload if_wg ->
destroy a jail -> panic.

Noted in the review, but left for follow-up work, is that the realloc
that may happen in osd_deregister() should likely go away and the
assumption that reallocating to a smaller size cannot fail is actually
not correct.

Reported by: dim
Reviewed by: markj, jamie
Differential Revision: https://reviews.freebsd.org/D41404

Details

Provenance
kevansAuthored on Aug 10 2023, 5:32 PM
Reviewer
markj
Differential Revision
D41404: kern: osd: avoid dereferencing freed slots
Parents
rG60a41168d195: UFS: panic rather than forcibly unmount the root fs
Branches
Unknown
Tags
Unknown