openssl-1.0.2a-parallel-symlinking.patch?id=c8abcbe8de5d3b6cdd68c162f398c011ff6e2d9d 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. https://rt.openssl.org/Ticket/Display.html?id=3780&user=guest&pass=guest
  2. From cc81af135bda47eaa6956a0329cbbc55bf993ac1 Mon Sep 17 00:00:00 2001
  3. From: Mike Frysinger <vapier@gentoo.org>
  4. Date: Fri, 3 Apr 2015 01:16:23 -0400
  5. Subject: [PATCH] fix race when symlink shareds libs
  6. When the crypto/ssl targets attempt to build their shared libs, they run:
  7. cd ..; make libcrypto.so.1.0.0
  8. The top level Makefile in turn runs the build-shared target for that lib.
  9. The build-shared target depends on both do_$(SHLIB_TARGET) & link-shared.
  10. When building in parallel, make is allowed to run both of these. They
  11. both run Makefile.shared for their respective targets:
  12. do_$(SHLIB_TARGET) ->
  13. link_a.linux-shared ->
  14. link_a.gnu ->
  15. ...; $(LINK_SO_A) ->
  16. $(LINK_SO) ->
  17. $(SYMLINK_SO)
  18. link-shared ->
  19. symlink.linux-shared ->
  20. symlink.gnu ->
  21. ...; $(SYMLINK_SO)
  22. The shell code for SYMLINK_SO attempts to do a [ -e lib ] check, but fails
  23. basic TOCTOU semantics. Depending on the load, that means two processes
  24. will run the sequence:
  25. rm -f libcrypto.so
  26. ln -s libcrypto.so.1.0.0 libcrypto.so
  27. Which obviously fails:
  28. ln: failed to create symbolic link 'libcrypto.so': File exists
  29. Since we know do_$(SHLIB_TARGET) will create the symlink for us, don't
  30. bother depending on link-shared at all in the top level Makefile when
  31. building things.
  32. Reported-by: Martin von Gagern <Martin.vGagern@gmx.net>
  33. URL: https://bugs.gentoo.org/545028
  34. ---
  35. Makefile.org | 5 ++++-
  36. 1 file changed, 4 insertions(+), 1 deletion(-)
  37. diff --git a/Makefile.org b/Makefile.org
  38. index 890bfe4..576c60e 100644
  39. --- a/Makefile.org
  40. +++ b/Makefile.org
  41. @@ -350,7 +350,10 @@ link-shared:
  42. libs="$$libs -l$$i"; \
  43. done
  44. -build-shared: do_$(SHLIB_TARGET) link-shared
  45. +# The link target in Makefile.shared will create the symlink for us, so no need
  46. +# to call link-shared directly. Doing so will cause races with two processes
  47. +# trying to symlink the lib.
  48. +build-shared: do_$(SHLIB_TARGET)
  49. do_$(SHLIB_TARGET):
  50. @ set -e; libs='-L. $(SHLIBDEPS)'; for i in $(SHLIBDIRS); do \
  51. --
  52. 2.3.4