From nobody Wed May 14 08:05:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524157843812268.53858335783866; Thu, 19 Apr 2018 10:10:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39DEB3134EBE; Thu, 19 Apr 2018 17:10:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA98D89FA8; Thu, 19 Apr 2018 17:10:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 995094CA9F; Thu, 19 Apr 2018 17:10:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3JHAAGr015094 for ; Thu, 19 Apr 2018 13:10:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 424CD2026E04; Thu, 19 Apr 2018 17:10:10 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B39E2026DFD; Thu, 19 Apr 2018 17:10:09 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 19 Apr 2018 18:09:51 +0100 Message-Id: <20180419171002.17117-4-berrange@redhat.com> In-Reply-To: <20180419171002.17117-1-berrange@redhat.com> References: <20180419171002.17117-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/14] build: prevent unloading of dlopen'd modules X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 19 Apr 2018 17:10:42 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 We previously added "-z nodelete" to the build of libvirt.so to prevent crashes when thread local destructors run which point to a code that has been dlclose()d: commit 384b9a76a5e387f64cfe8f83f4a518bb302e80f7 Author: Daniel P. Berrang=C3=A9 Date: Thu Apr 19 11:42:22 2018 +0100 driver: prevent unloading of dlopen'd modules The libvirtd loadable modules can suffer from the same problem if they were ever unloaded. Fortunately we don't ever call dlclose() on them, but lets add a second layer of protection by linking them with the "-z nodelete" flag. While we're doing this, lets add a third layer of protection by passing RTLD_NODELETE to dlopen(). Signed-off-by: Daniel P. Berrang=C3=A9 --- src/Makefile.am | 6 +++++- src/driver.c | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 2f8e5f6908..0d8d380df1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -51,7 +51,11 @@ AM_LDFLAGS =3D $(DRIVER_MODULES_LDFLAGS) \ $(CYGWIN_EXTRA_LDFLAGS) \ $(MINGW_EXTRA_LDFLAGS) \ $(NULL) -AM_LDFLAGS_MOD =3D -module -avoid-version $(AM_LDFLAGS) +AM_LDFLAGS_MOD =3D \ + -module \ + -avoid-version \ + $(LIBVIRT_NODELETE) \ + $(AM_LDFLAGS) AM_LDFLAGS_MOD_NOUNDEF =3D $(AM_LDFLAGS_MOD) $(NO_UNDEFINED_LDFLAGS) =20 POD2MAN =3D pod2man -c "Virtualization Support" -r "$(PACKAGE)-$(VERSION)" diff --git a/src/driver.c b/src/driver.c index 52e1ae345a..7d4c78eaaa 100644 --- a/src/driver.c +++ b/src/driver.c @@ -45,6 +45,11 @@ static void * virDriverLoadModuleFile(const char *file) { void *handle =3D NULL; + int flags =3D RTLD_NOW | RTLD_GLOBAL; + +# ifdef RTLD_NODELETE + flags |=3D RTLD_NODELETE; +# endif =20 VIR_DEBUG("Load module file '%s'", file); =20 @@ -55,7 +60,7 @@ virDriverLoadModuleFile(const char *file) =20 virUpdateSelfLastChanged(file); =20 - if (!(handle =3D dlopen(file, RTLD_NOW | RTLD_GLOBAL))) + if (!(handle =3D dlopen(file, flags))) VIR_ERROR(_("failed to load module %s %s"), file, dlerror()); =20 return handle; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list