Re: [PATCH 2/3] selftests: Fix errno checking in syscall_user_dispatch test

From: Kees Cook
Date: Wed Feb 19 2025 - 12:20:02 EST


On Tue, Feb 18, 2025 at 05:04:35PM +0100, Dmitry Vyukov wrote:
> Successful syscalls don't change errno, so checking errno is wrong
> to ensure that a syscall has failed. For example for the following
> sequence:
>
> prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x0, 0xff, 0);
> EXPECT_EQ(EINVAL, errno);
> prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0x0, 0x0, &sel);
> EXPECT_EQ(EINVAL, errno);
>
> only the first syscall may fail and set errno, but the second may succeed
> and keep errno intact, and the check will falsely pass.
> Or if errno happened to be EINVAL before, even the first check may falsely
> pass.
>
> Also use EXPECT/ASSERT consistently. Currently there is an inconsistent mix
> without obvious reasons for usage of one or another.
>
> Signed-off-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx>

Reviewed-by: Kees Cook <kees@xxxxxxxxxx>

Yeah, these all look good to me.

--
Kees Cook