Page MenuHome GnuPG

OS X 10.12 and FAIL: random
Closed, DuplicatePublic

Description

I'm building libgcrypt 1.8.6 on OS X 10.12 with triplet x86_64-apple-darwin16.7.0. make check is failing.

Making check in tests
make  check-TESTS
version:1.8.6:10806:1.38:12600:
cc:40201:clang:4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2):
ciphers:arcfour:blowfish:cast5:des:aes:twofish:serpent:rfc2268:seed:camellia:idea:salsa20:gost28147:chacha20:
pubkeys:dsa:elgamal:rsa:ecc:
digests:crc:gostr3411-94::md4:md5:rmd160:sha1:sha256:sha512:sha3:tiger:whirlpool:stribog:blake2:
rnd-mod:linux:
cpu-arch:x86:
mpi-asm:amd64/mpih-add1.S:amd64/mpih-sub1.S:amd64/mpih-mul1.S:amd64/mpih-mul2.S:amd64/mpih-mul3.S:amd64/mpih-lshift.S:amd64/mpih-rshift.S:
hwflist:intel-cpu:intel-fast-shld:intel-bmi2:intel-ssse3:intel-sse4.1:intel-pclmul:intel-aesni:intel-rdrand:intel-avx:intel-avx2:intel-rdtsc:
fips-mode:n:n:
rng-type:standard:1:2010000:1:
PASS: version
PASS: t-secmem
PASS: mpitests
PASS: t-sexp
PASS: t-convert
PASS: t-mpi-bit
PASS: t-mpi-point
PASS: curves
PASS: t-lock
PASS: prime
PASS: basic
PASS: keygen
PASS: pubkey
PASS: hmac
PASS: hashtest
PASS: t-kdf
PASS: keygrip
PASS: fips186-dsa
PASS: aeswrap
PASS: pkcs1v2
dyld: Library not loaded: /Users/jwalton/tmp/ok2delete/lib/libgcrypt.20.dylib
  Referenced from: /Users/jwalton/Build-Scripts/libgcrypt-1.8.6/tests/.libs/random
  Reason: image not found
random: running '/Users/jwalton/Build-Scripts/libgcrypt-1.8.6/tests/.libs/random --in-recursion --early-rng-check' failed
FAIL: random
PASS: dsa-rfc6979
      256 of 1026 tests done
      512 of 1026 tests done
      768 of 1026 tests done
      1024 of 1026 tests done
      1026 tests done
...

I can't find log files for the self tests. If you know where they are, then please say so.

libgcrypt-1.8.6 $ find . -name '*.log'
./config.log
libgcrypt-1.8.6 $

Here is config.log:

.

Details

Version
1.8.6

Event Timeline

There are no log file but you can run the test by hand:

$ cd tests
$ ./random --debug

but I doubt that this will help because it seems that random is not run at all.

I'm afraid that the dynamic linker doesn't allow hardcoding library path in an executable on macOS.
(It is only supported on some limited platforms.)

If so, you need to install (make install), before you invoke make check.

I believe the problem here is OS X 10.12's (and above) System Integrity Protection (SIP). SIP protects system integrity by doing things like sanitizing environmental variables for system programs. Sanitizing environmental variables on system programs avoids code injections.

There are two parts to the sentence. First is "sanitizing environmental variables", and that includes DYLD_LIBRARY_PATH. The second part is "for system programs". SIP protects system programs like /bin/make and /bin/sh. SIP does not protect user programs, like $HOME/bin/foobar.

A break due to System Integrity Protection (SIP) makes sense. Linux is OK, and OS X 10.9 is OK. The problem is OS X 10.12, which introduced SIP.

So what is happening (if I am parsing things correctly)...

  1. make check compiles libgcrypt-1.8.6/tests/random.c into libgcrypt-1.8.6/tests/.libs/random (notice addition of .libs)
  2. make is invoked. make is a system program and the environment is sanitized.
  3. make eventually executes libgcrypt-1.8.6/tests/random.
  4. libgcrypt-1.8.6/tests/random wrapper script sets up DYLD_LIBRARY_PATH. It is a user program, so the environment is not sanitized.
  5. libgcrypt-1.8.6/tests/random calls libgcrypt-1.8.6/tests/.libs/random. It is a user program, so the environment is not sanitized.
  6. libgcrypt-1.8.6/tests/.libs/random (compiled from random.c) eventually calls system (cmdline). The environment is sanitized.

At step (5), system runs a command like .../tests/.libs/random --in-recursion --early-rng-check. .../tests/.libs/random is _not_ a system program, but the loader/interpreter is protected from the DYLD_LIBRARY_PATH code injection. Because SIP is protecting the loader/interpreter from code injections, DYLD_LIBRARY_PATH is sanitized.

I don't see an easy fix here. (But I may be parsing things incorrectly).

Even if you call one of the exec* functions, I believe SIP will still scrub the environmental variables. Using exec* instead of system is just trying to do an end-around, so SIP won't allow it either.

We can't fix the linked library for the random test program using otool or install_name because make check is atomic. It builds and runs in one step. If we could get in between the build and the run, then we could probably fix the problem.

I _think_ the way to fix this is to break-out random.c into individual programs, and have the individual program directly test the generator. The individual programs are user programs, and they avoid the system calls. Their environment should be preserved.