]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
selftests: Fix errno checking in syscall_user_dispatch test
authorDmitry Vyukov <dvyukov@google.com>
Wed, 21 May 2025 15:04:28 +0000 (17:04 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 10:08:41 +0000 (12:08 +0200)
commit41917d9ce43a53f71088c6b274af0d8479b0befa
tree335fdec3ce388d68e360d58e0f9d47cc9d6528e1
parentaa771d2928fedd7fb10aa373601eeee0ed8ccfae
selftests: Fix errno checking in syscall_user_dispatch test

[ Upstream commit b89732c8c8357487185f260a723a060b3476144e ]

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.

Fixes: 179ef035992e ("selftests: Add kselftest for syscall user dispatch")
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/af6a04dbfef9af8570f5bab43e3ef1416b62699a.1747839857.git.dvyukov@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/syscall_user_dispatch/sud_test.c