kunit: Fix race condition in try-catch completion
authorDavid Gow <davidgow@google.com>
Fri, 12 Apr 2024 02:59:01 +0000 (10:59 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 6 May 2024 20:22:02 +0000 (14:22 -0600)
commit1eb69ded805103ce3ddc8b1a207abd8c24ca9e63
tree9e8afefdc5a53cb728cb11881ce3f8786d024f64
parent170c31737cf31770916c6cbadab04c5134f0d961
kunit: Fix race condition in try-catch completion

KUnit's try-catch infrastructure now uses vfork_done, which is always
set to a valid completion when a kthread is created, but which is set to
NULL once the thread terminates. This creates a race condition, where
the kthread exits before we can wait on it.

Keep a copy of vfork_done, which is taken before we wake_up_process()
and so valid, and wait on that instead.

Fixes: 93533996100c ("kunit: Handle test faults")
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Closes: https://lore.kernel.org/lkml/20240410102710.35911-1-naresh.kamboju@linaro.org/
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Acked-by: Mickaël Salaün <mic@digikod.net>
Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Rae Moar <rmoar@google.com>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/kunit/try-catch.c