Page MenuHomeFreeBSD

linker: Don't invoke dtors without having invoked ctors
ClosedPublic

Authored by markj on Mar 29 2024, 8:29 PM.
Tags
None
Referenced Files
F87324402: D44559.id136358.diff
Mon, Jul 1, 7:04 PM
Unknown Object (File)
Thu, Jun 27, 10:06 AM
Unknown Object (File)
Sat, Jun 15, 7:42 PM
Unknown Object (File)
May 22 2024, 12:54 PM
Unknown Object (File)
May 6 2024, 9:22 PM
Unknown Object (File)
Apr 28 2024, 10:15 AM
Unknown Object (File)
Apr 26 2024, 4:34 AM
Unknown Object (File)
Apr 7 2024, 1:09 AM
Subscribers

Details

Summary

I have a kernel module which fails to load because of an unrecognized
relocation type. link_elf_load_file() fails before the module's ctors
are invoked and it calls linker_file_unload(), which causes the module's
dtors to be executed, resulting in a kernel panic.

Add a flag to the linker file to ensure that dtors are not invoked if
unloading due to an error.

At the moment I only implemented this for link_elf_obj.c since
link_elf.c doesn't invoke dtors, but I refactored link_elf.c to make
them more similar.

Fixes: 9e575fadf491 ("link_elf_obj: Invoke fini callbacks")

Diff Detail

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

Event Timeline

markj requested review of this revision.Mar 29 2024, 8:29 PM
sys/kern/link_elf_obj.c
664

In this form the assert can be MPASS. For KASSERT, at least the linker file name would be useful to print.

sys/sys/linker.h
85

Might be, change the bool to 'epoch' int. Indicating no ctr called/ctr called/dtr called. Then you can assert e.g. that dtr not called twice.

markj added inline comments.
sys/sys/linker.h
85

I made it into an enum.

markj marked an inline comment as done.

Apply kib's suggestions.

This revision is now accepted and ready to land.Mar 30 2024, 1:24 PM
zlei added a subscriber: zlei.

Looks good to me.