[PATCH] selftests/harness: Fix TEST_F()'s vfork handling

Kees Cook keescook at chromium.org
Tue Mar 5 20:31:47 UTC 2024


On Tue, Mar 05, 2024 at 09:10:29PM +0100, Mickaël Salaün wrote:
> Always run fixture setup in the grandchild process, and by default also
> run the teardown in the same process.  However, this change makes it
> possible to run the teardown in a parent process when
> _metadata->teardown_parent is set to true (e.g. in fixture setup).
> 
> Fix TEST_SIGNAL() by forwarding grandchild's signal to its parent.  Fix
> seccomp tests by running the test setup in the parent of the test
> thread, as expected by the related test code.  Fix Landlock tests by
> waiting for the grandchild before processing _metadata.
> 
> Use of exit(3) in tests should be OK because the environment in which
> the vfork(2) call happen is already dedicated to the running test (with
> flushed stdio, setpgrp() call), see __run_test() and the call to fork(2)
> just before running the setup/test/teardown.  Even if the test
> configures its own exit handlers, they will not be run by the parent
> because it never calls exit(3), and the test function either ends with a
> call to _exit(2) or a signal.
> 
> Cc: David S. Miller <davem at davemloft.net>
> Cc: Günther Noack <gnoack at google.com>
> Cc: Jakub Kicinski <kuba at kernel.org>
> Cc: Kees Cook <keescook at chromium.org>
> Cc: Mark Brown <broonie at kernel.org>
> Cc: Shuah Khan <shuah at kernel.org>
> Cc: Will Drewry <wad at chromium.org>
> Fixes: 0710a1a73fb4 ("selftests/harness: Merge TEST_F_FORK() into TEST_F()")
> Link: https://lore.kernel.org/r/20240305201029.1331333-1-mic@digikod.net

Sanity-check run of seccomp tests before:

# # Totals: pass:70 fail:21 xfail:0 xpass:0 skip:5 error:0

After:

# # Totals: pass:91 fail:0 xfail:0 xpass:0 skip:5 error:0

Reviewed-by: Kees Cook <keescook at chromium.org>
Tested-by: Kees Cook <keescook at chromium.org>

Thanks for a quick fix!

-Kees

-- 
Kees Cook



More information about the Linux-security-module-archive mailing list