From 78d301098f6ead7fc341b68d7ac5e0a1cd3295c5 Mon Sep 17 00:00:00 2001 From: Willem Jan Withagen Date: Sun, 11 Apr 2021 15:01:22 +0200 Subject: [PATCH] tools: do not unload plugins during destruction. FreeBSD ceph-dencoder crashes in the exit() calls, due to invalid pointer references during the release process of the loaded libraries. Often this is signaled by libc reporting: __cxa_thread_call_dtors: dtr 0x47efc0 from unloaded dso, skipping The cause for this is different behaviour between FreeBSD and Linux: https://groups.google.com/g/bsdmailinglist/c/22ncTZAbDp4/m/Dii_pII5AwAJ _The FreeBSD implementation here looks racy. If one thread dlcloses an object while another thread is exiting, we can end up calling a function at an invalid memory address. It also looks as if it may be possible to unload one library, load another at the same address, and end up executing entirely the wrong code, which would have some serious security implications. The GNU/Linux equivalent of this function locks the DSO in memory until all references to it have gone away. A call to dlclose() on GNU/Linux will not actually unload the library until all threads with destructors in that library have been unloaded. I believe that this reuses the same reference counting mechanism that allows the same library to be dlopened and dlclosed multiple times. Signed-off-by: Willem Jan Withagen --- src/tools/ceph-dencoder/ceph_dencoder.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/ceph-dencoder/ceph_dencoder.cc b/src/tools/ceph-dencoder/ceph_dencoder.cc index ccf51575c73..effcfa41ee9 100644 --- a/src/tools/ceph-dencoder/ceph_dencoder.cc +++ b/src/tools/ceph-dencoder/ceph_dencoder.cc @@ -75,9 +75,11 @@ public: } } ~DencoderPlugin() { +#if !defined(__FreeBSD__) if (mod) { dlclose(mod); } +#endif } int register_dencoders() { assert(mod);