Re: [PATCH] selftests: vDSO: ensure vgetrandom works in a time namespace
From: Jason A. Donenfeld
Date: Mon Sep 09 2024 - 08:57:21 EST
On Mon, Sep 09, 2024 at 12:42:01PM +0200, Christophe Leroy wrote:
> > + assert(unshare(CLONE_NEWUSER) == 0 && unshare(CLONE_NEWTIME) == 0);
>
> ~# ./vdso_test_getrandom
> TAP version 13
> 1..2
> ok 1 getrandom: PASS
> vdso_test_getrandom: vdso_test_getrandom.c:276: kselftest: Assertion
> `ret == 0' failed.
> Aborted
>
> That's too strong. When unshare() returns EINVAL it means the kernel is
> not built with CONFIG_TIME_NS. In that case the test should be SKIPPED.
>
> And when unshare() returns EPERM, it means the user is not authorised to
> use unshare(), that's an expected error that shouldn't lead to an assert
> either, instead it should gracefully says FAILED I think.
Generally those assertions are for when the test itself or the test
environment is broken, rather than the thing the test is testing for.
The CLONE_NEWUSER can be split into a separate unshare statement,
though, and then the return value can be ignored. The only point of it
is to make it less likely that the CLONE_NEWTIME will fail. I'll fix
that up.
Jason