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
Unknown Object (File)
Tue, Oct 22, 7:04 AM
Unknown Object (File)
Tue, Oct 22, 7:04 AM
Unknown Object (File)
Tue, Oct 22, 7:04 AM
Unknown Object (File)
Tue, Oct 22, 7:04 AM
Unknown Object (File)
Tue, Oct 22, 6:58 AM
Unknown Object (File)
Sep 25 2024, 1:26 AM
Unknown Object (File)
Sep 24 2024, 5:18 AM
Unknown Object (File)
Sep 21 2024, 2:08 PM
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 Skipped
Unit
Tests Skipped
Build Status
Buildable 56833
Build 53721: arc lint + arc unit

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.