692 Commits

Author SHA1 Message Date
Jim Klimov
5217bcd13d src/sunos_endian.h: No newline at end of file
For pedantic compilers this is actually a fatal error, since per
(older?) C standards the file should end with an EOL.
2021-03-28 18:54:26 +03:00
Wolfgang Hommel
8ae4c9bc0e Merge pull request #313 from dkg/test-variadic-promotion
Test variadic promotion
2021-03-06 09:46:07 +01:00
Daniel Kahn Gillmor
6733dc3a8d tests: Confirm variadic argument promotion assumptions when INTERCEPT_SYSCALL
The test suite should not succeed if INTERCEPT_SYSCALL is defined but
the variadic argument promotion test fails.

OTOH, if we're not asking for INTERCEPT_SYSCALL, we don't care about
the results of that test.
2021-03-05 22:48:47 -05:00
Daniel Kahn Gillmor
008d33fdf2 Test assumptions about variadic re-packing
This test uses the same style of re-packing variadic arguments through
two layers of variadic calls, and compares that call chain against one
direct variadic call.

The outer function uses the same kind of re-packing used in
src/libfaketime.c's syscall (leading to real_syscall), but the inner
functions use different assumptions about the types of each argument.

This is not an entirely comprehensive test, because we only define two
different inner function signatures.  If some particular syscall is
breaking when intercepted, consider adding something like its expected
function signature in test/variadic/inner.c, and invoke it in
test/variadic/main.c.

Note that we don't test any floating point types (those types are
typically passed in registers in x86-64, not on the stack, and are
also not used for any syscall that i'm aware of).
2021-03-05 22:48:47 -05:00
Daniel Kahn Gillmor
5a0071f952 Centralize assumptions about variadic argument re-packing
By stating these assumptions in src/faketime_common.h, we can reuse
them in the tests as well as in the code.
2021-03-05 21:46:18 -05:00
Daniel Kahn Gillmor
51f1248593 tests: use CFLAGS from the environment.
This makes the test build process use the same sort of CFLAGS as the rest of the code.
2021-03-05 21:45:23 -05:00
Daniel Kahn Gillmor
e70b143733 Prepare to add new tests depending on the definitions
We want to be able to conditionally add tests.  This sets up to be
able to do that cleanly.
2021-03-05 21:45:23 -05:00
Wolfgang Hommel
e1073c8733 Promote syscall passthrough arguments to long instead of int (#310) 2021-03-04 19:24:24 +01:00
Wolfgang Hommel
01b0b4bb56 Merge pull request #312 from dkg/avoid-diversion
Pass through syscall(__NR_clock_gettime) if FAKERANDOM is unset
2021-03-03 06:36:26 +01:00
Daniel Kahn Gillmor
5f5756ccd9 Pass through syscall(__NR_clock_gettime) if FAKERANDOM is unset
If FAKERANDOM is unset, we were still intercepting syscall() and
passing it through to clock_gettime, rather than letting it fall
through to real_syscall.

That would have the effect of diverting syscall(__NR_clock_gettime,…)
into the libc invocation of clock_gettime(…) (via real_clock_gettime).
While that probably does the same thing, it's probably a mistake to do
such a diversion when FAKETIME is unset.
2021-03-02 20:01:18 -05:00
Wolfgang Hommel
bca9f1bf90 Merge pull request #311 from dkg/more-testing
More snippet testing and better documentation
2021-03-02 21:44:56 +01:00
Daniel Kahn Gillmor
d3f3ee38c6 Add syscall_clock_gettime_heap snippet
This invokes clock_gettime, but uses a timespec from the heap instead
of the stack.

It appears to be successful for me on x86-64 GNU/Linux.

This rules out one possible cause of the error reported in #310: I was
worried that an address from the range occupied by the heap might
somehow be corrupted by the syscall variadic argument de-mangling, but
that looks like it is not the case.
2021-03-02 10:33:07 -05:00
Daniel Kahn Gillmor
a3f9410e51 Add clock_gettime_heap snippet
This invokes clock_gettime, but uses a timespec from the heap instead
of the stack.
2021-03-02 10:26:20 -05:00
Daniel Kahn Gillmor
a92d6ffe7c add snippet testing clock_gettime(CLOCK_REALTIME) 2021-03-02 10:23:11 -05:00
Daniel Kahn Gillmor
253774c8d8 added new simple snippet "time.c" 2021-03-01 21:47:18 -05:00
Daniel Kahn Gillmor
986e6e1cdc Clarify test/Makefile and snippet testing documentation
Hopefully this makes it easier for future development work to augment
the snippet-based testing.
2021-03-01 21:40:57 -05:00
Daniel Kahn Gillmor
0bfb72b627 tests: normalize "where" variable to include framework prefix and snippet name 2021-03-01 21:08:00 -05:00
Daniel Kahn Gillmor
5a1bd98979 parallelize library_contructors test 2021-03-01 21:05:22 -05:00
Daniel Kahn Gillmor
7e62881c8f Name "snippets" explicitly
Earlier, this code was conceived of to test a "function" specifically,
but some future snippet could test multiple function calls, or a
subset of a function call (e.g. snippets/syscall_clock_gettime.c
already only tests one particular syscall diversion number).

Normalizing on the name "snippet" should make it easier to understand
the code going forward.
2021-03-01 15:06:22 -05:00
Wolfgang Hommel
0e6b1b2460 Merge pull request #309 from dkg/faketime-pid
faketime: add -p option to wrapper for setting PID
2021-02-26 20:46:27 +01:00
Wolfgang Hommel
1297568caf Merge pull request #306 from dkg/cleanup-tests
Overhaul recently-added tests (new additional snippet-driven testing framework)
2021-02-26 20:28:38 +01:00
Daniel Kahn Gillmor
940502b3de Added snippet for syscall(__NR_clock_gettime)
Closes: #176
2021-02-25 23:33:30 -05:00
Daniel Kahn Gillmor
26b4b395e9 Include a check for getentropy interception
This snippet applies to both the library constructors and variable
data test frameworks.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
0b0cc29d2e test/randomtest.sh: avoid touching the filesystem 2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
a5885f1479 Drop more duplicative tests
Now that we have the snippet-driven test_variable_data suite, most of
the other longer hand-written tests are duplicative.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
0872c6c0c0 Add test_variable_data framework that reuses the snippets
Most of these snippets are likely to have some env var that causes the
data to hold constant, while the data will otherwise be likely to vary
over time.

This framework offers a way to test those snippets, by dropping the
variable and an example value in the test/snippets/FOO.variable
one-line file.

Note that the test/snippets/syscall.c snippet is *not* expected to
vary over time (or to differ when any given variable is set), so we
simply don't add any test/snippets/syscall.variable file to avoid it
being tested in this way.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
a51a38d0ae Handle when another library uses a syscall in a constructor
Without this fix, the test_library_constructors test was failing on
use_lib_syscall.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
f47223ff12 Include snippet for syscall() interception in library constructors 2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
7b1d0958b5 Drop duplicate library constructor preload tests
These tests are already taken care of with the snippet-driven library
constructor tests.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
17522c5ba1 Overhaul testing library constructors
We want to make it easier to test a bunch of different functions that
might be invoked in constructors of other libraries.

It seems conceivable that with these snippets, we could design other
tests that also work across a wide range of intercepted functions.
2021-02-25 23:17:25 -05:00
Daniel Kahn Gillmor
5e62eafcc2 faketime: add -p option to wrapper for setting PID
I had to decide what to do if FAKE_PID wasn't defined during the
build. I decided that since the wrapper can't be sure it is preloading
the same library that it was built with (someone could somehow mix and
match the library and the wrapper tool), it should just warn and pass
along the value anyway.

This reserves the option space, but shouldn't annoy people too much if
they are running it on a system that doesn't have FAKE_PID enabled.

I note that this happens regardless of whether it is a "direct"
invocation or not.  I don't fully understand all the tradeoffs here,
so I would appreciate another set of eyes reviewing this choice.

Closes: #308
2021-02-25 19:37:38 -05:00
Daniel Kahn Gillmor
01f6bc76c9 clean up after syscall_test properly 2021-02-25 18:12:04 -05:00
Daniel Kahn Gillmor
f329eee8c5 Send test output to stdout, not stderr
debian autopkgtest instances (and maybe other test systems) will
report a failure if messages are sent to stderr.

Since these messages are diagnostic messages for the test suite, and
not indicators of actual failure, they should go to stdout, not
stderr.
2021-02-25 18:11:52 -05:00
Wolfgang Hommel
c89582fc1f divert syscall() to clock_gettime() (#176 #302) 2021-02-25 21:22:41 +01:00
Wolfgang Hommel
9a38e5d775 Merge pull request #305 from dkg/fix-shm
Use real_getpid instead of getpid in ft_shm_create() under FAKE_PID
2021-02-25 19:29:11 +01:00
Daniel Kahn Gillmor
7f4e5c378a Use real_getpid instead of getpid in ft_shm_create() under FAKE_PID
This addresses part of the concerns raised in #297
2021-02-25 10:50:57 -05:00
Wolfgang Hommel
9337bccfcb Merge pull request #304 from dkg/cover-getentropy
better testing for interception of randomness from the kernel, including getentropy()
2021-02-25 06:27:35 +01:00
Wolfgang Hommel
3668fd9b0f Merge pull request #302 from dkg/syscall-interception
Intercept syscall
2021-02-25 06:15:42 +01:00
Daniel Kahn Gillmor
3a81c6becd if FAKE_RANDOM is present, try to intercept getentropy as well.
Closes: #303
2021-02-24 16:38:15 -05:00
Daniel Kahn Gillmor
3db9d20828 Test getentropy
We want to ensure that tools that call getentropy() are also
controlled appropriately.
2021-02-24 16:03:57 -05:00
Daniel Kahn Gillmor
20e74b1b02 clean up randomtest.sh, make more flexible 2021-02-24 15:58:54 -05:00
Daniel Kahn Gillmor
00d6edf90c Test repeated invocations of getrandom()
A single program that invokes getrandom() repeatedly should end up
with the same stream of bytes, regardless of how it chunks up the
reading from the entropy source.

This test already passses.  I'm including it because it seems
like a useful confirmation.
2021-02-24 15:24:45 -05:00
Daniel Kahn Gillmor
811283e683 Intercept syscall
This is an attempt at an implementation to address #301.

Some things worth noting:

 - I am not particularly confident in my reverse of the variadic C
   ABI. While the code appears to work for me on x86_64, I could
   imagine some variations between platforms that I'm not
   understanding.

 - This works to intercept the invocation of syscall as seen in
   test/syscalltest.sh, as long as it was compiled with -DFAKE_RANDOM

 - defining -DINTERCEPT_SYSCALL on non-Linux platforms should result
   in a compile-time error.

 - This does *not* work to intercept the syscall sent by `openssl
   rand`, for some reason I don't yet understand.  Perhaps openssl has
   some platform-specific syscall mechanism that doesn't route them
   through libc's syscall() shim?
2021-02-24 14:45:38 -05:00
Wolfgang Hommel
a8283c646d Merge pull request #300 from dkg/improve-tests
Test getpid() against a library that invokes getpid() in its constructor
2021-02-24 17:54:30 +01:00
Daniel Kahn Gillmor
2ca0b719e3 test getpid() against library with constructor that calls it
This is an attempt to ensure that an external library invocation of
getpid doesn't trigger a crash (e.g. #295) or an infinite loop
(e.g. #297).
2021-02-24 11:15:31 -05:00
Daniel Kahn Gillmor
f6ddc32695 Genericize build rules for testing external libraries with constructor
This paves the way for testing other interceptions like getpid() with
shared objects that do devious things in their consturctors.
2021-02-24 11:15:01 -05:00
Daniel Kahn Gillmor
8de66f799f randomtest.sh requires librandom.so to be present
In some configurations, GNU make might treat librandom.so as an
ephemeral/intermediate build artifact and destroy it before
randomtest.sh is run.  This ensures the shared object is present when
needed.
2021-02-24 11:14:37 -05:00
Wolfgang Hommel
63fe6f0be5 Merge pull request #298 from dkg/fakepid
Enable intercepting getpid()
2021-02-24 13:53:45 +01:00
Wolfgang Hommel
062abac575 Merge pull request #299 from dkg/fix-getrandom
Ensure that real_getrandom is initialized properly
2021-02-24 06:34:46 +01:00
Daniel Kahn Gillmor
004222585e Enable intercepting getpid()
I went with the runtime environment variable being FAKETIME_FAKEPID
since it seems less likely to collide with anything else.

Closes: #297
2021-02-23 22:19:08 -05:00