Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 566260 - dev-libs/openssl: openssl-1.0.2d-parallel.patch has race condition
Summary: dev-libs/openssl: openssl-1.0.2d-parallel.patch has race condition
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-19 19:28 UTC by ryan.barnett
Modified: 2015-11-24 15:42 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch to fix race condition (0001-openssl-1.0.2d-fix-parallel-build-race-condition.patch,1.63 KB, application/mbox)
2015-11-19 19:28 UTC, ryan.barnett
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ryan.barnett 2015-11-19 19:28:25 UTC
Created attachment 417376 [details]
Patch to fix race condition

The gentoo's patch for parallel builds is used within buildroot and using the autobuilders it is detected that there is a still a race condition to building openssl in parallel. See the discussion here:

http://lists.busybox.net/pipermail/buildroot/2015-November/144686.html

The build-shared target depends on do_crypto and link-shared, which will be executed in parallel. do_crypto calls link_a.linux_shared -> link_a.gnu which does SYMLINK_SO; in parallel, link-shared calls symlink.linux_shared which also does SYMLINK_SO. Before the symlink is created, it is rm'ed, but there is a tiny chance that the second one is created after the rm has been called.

I have attached the patch that fixes this race condition by forcing the symlink (using 'ln -sf' instead of 'ln -s')
Comment 1 ryan.barnett 2015-11-20 16:54:17 UTC
The error originally see during a failure is either:

  ln: failed to create symbolic link 'libssl.so': File exists
  ln: creating symbolic link `libcrypto.so': File exists

And to update patch originally attached is to remove the 'rm -f' before the symbolic links:

diff --git a/dev-libs/openssl/files/openssl-1.0.2d-parallel-build.patch b/dev-libs/openssl/files/openssl-1.0.2d-parallel-build.patch
index b7aa0ea..9b74380 100644
--- a/dev-libs/openssl/files/openssl-1.0.2d-parallel-build.patch
+++ b/dev-libs/openssl/files/openssl-1.0.2d-parallel-build.patch
@@ -118,14 +118,26 @@ https://rt.openssl.org/Ticket/Display.html?id=3738&user=guest&pass=guest
      LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
      $${SHAREDCMD} $${SHAREDFLAGS} \
        -o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \
-@@ -122,6 +123,7 @@
+@@ -117,15 +117,15 @@ SYMLINK_SO=      \
+               prev=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
+               if [ -n "$$SHLIB_COMPAT" ]; then \
+                       for x in $$SHLIB_COMPAT; do \
+-                              ( $(SET_X); rm -f $$SHLIB$$x$$SHLIB_SUFFIX; \
+-                                ln -s $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \
++                              ( $(SET_X);  \
++                                ln -sf $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \
+                               prev=$$SHLIB$$x$$SHLIB_SUFFIX; \
                        done; \
                fi; \
                if [ -n "$$SHLIB_SOVER" ]; then \
-+                      [ -e "$$SHLIB$$SHLIB_SUFFIX" ] || \
-                       ( $(SET_X); rm -f $$SHLIB$$SHLIB_SUFFIX; \
-                         ln -s $$prev $$SHLIB$$SHLIB_SUFFIX ); \
+                       [ -e "$$SHLIB$$SHLIB_SUFFIX" ] || \
+-                      ( $(SET_X); rm -f $$SHLIB$$SHLIB_SUFFIX; \
+-                        ln -s $$prev $$SHLIB$$SHLIB_SUFFIX ); \
++                      ( $(SET_X); \
++                        ln -sf $$prev $$SHLIB$$SHLIB_SUFFIX ); \
                fi; \
+       fi
+
Comment 2 SpanKY gentoo-dev 2015-11-21 00:26:26 UTC
`ln -sf` is no more atomic than `rm; ln`.  there is still a window where things can fail.  you can easily check this:
  i=0; while [ $((i++)) -lt 500 ]; do ln -sf a b & :; done

a good number of those will fail with:
ln: failed to create symbolic link ‘b’: File exists

the deps need to be fixed up
Comment 3 ryan.barnett 2015-11-21 02:22:56 UTC
You are indeed correct, thank you for pointing this out and giving this good example. So I guess my patch is invalid but the bug is still valid.
Comment 4 SpanKY gentoo-dev 2015-11-24 15:42:05 UTC
seems to me the buildroot guys didn't pick up all the Gentoo patches.  the 1.0.2d ebuild applies more than just openssl-1.0.2d-parallel.patch.  in fact, the race you refer to is most likely fixed by openssl-1.0.2a-parallel-symlinking.patch.