2723ca
From a9e8373030b39aadfc33af67443085df83e9e344 Mon Sep 17 00:00:00 2001
2723ca
From: Daniel Berrange <berrange@redhat.com>
2723ca
Date: Wed, 14 Aug 2013 16:00:56 +0200
2723ca
Subject: [libusb-compat PATCH] Link with -znodelete to disallow unloading
2723ca
2723ca
Since libusb-0.1 did not have any init / exit function, code using the
2723ca
libusb-0.1 API will not call libusb_exit.
2723ca
2723ca
Now, libgphoto uses libusb and will dlopen() and dlclose() it. Unfortunately
2723ca
since there is no way to ensure libusb_close() is called, when libgphoto
2723ca
dlcloses the libusb.so library, the thread from libusbx.so will not be
2723ca
stopped. So a thread will remain running, executing code from a memory
2723ca
region that has now been freed. Crash-tastic results ensue.
2723ca
2723ca
I don't see a good way to fix this from libusb or libusbx, given the need to
2723ca
preserve the existing API of libusb.
2723ca
2723ca
If, however, we link libusb.so using  -znodelete, we will prevent it from
2723ca
ever being unloaded, despite the dlclose() calls. This is not ideal, but
2723ca
better than allowing it to be unloaded which is a guaranteed crash.
2723ca
2723ca
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2723ca
---
2723ca
 libusb/Makefile.am | 2 +-
2723ca
 1 file changed, 1 insertion(+), 1 deletion(-)
2723ca
2723ca
diff --git a/libusb/Makefile.am b/libusb/Makefile.am
2723ca
index 33a609a..a20fdb5 100644
2723ca
--- a/libusb/Makefile.am
2723ca
+++ b/libusb/Makefile.am
2723ca
@@ -5,5 +5,5 @@ libusb_la_SOURCES = core.c usbi.h
2723ca
 libusb_la_CFLAGS = -fvisibility=hidden $(AM_CFLAGS) $(LIBUSB_1_0_CFLAGS)
2723ca
 libusb_la_LIBADD = $(LIBUSB_1_0_LIBS)
2723ca
 libusb_la_LDFLAGS = -version-info $(LT_MAJOR):$(LT_REVISION):$(LT_AGE) \
2723ca
-	-release 0.1
2723ca
+	-release 0.1 -Wl,-z -Wl,nodelete
2723ca
 
2723ca
--- libusb-compat-0.1.5.orig/libusb/Makefile.in	2013-05-21 00:40:35.000000000 +0100
2723ca
+++ libusb-compat-0.1.5.orig/libusb/Makefile.in	2013-08-13 22:20:32.831532426 +0100
2723ca
@@ -297,7 +297,7 @@ libusb_la_SOURCES = core.c usbi.h
2723ca
 libusb_la_CFLAGS = -fvisibility=hidden $(AM_CFLAGS) $(LIBUSB_1_0_CFLAGS)
2723ca
 libusb_la_LIBADD = $(LIBUSB_1_0_LIBS)
2723ca
 libusb_la_LDFLAGS = -version-info $(LT_MAJOR):$(LT_REVISION):$(LT_AGE) \
2723ca
-	-release 0.1
2723ca
+	-release 0.1 -Wl,-z -Wl,nodelete
2723ca
 
2723ca
 all: all-am
2723ca
 
2723ca
-- 
2723ca
1.8.3.1
2723ca