Skip to content

Commit 2551a1e

Browse files
Flowdalicshuahkh
authored andcommitted
kunit: test_dev_action: Correctly cast 'priv' pointer to long*
The previous implementation incorrectly assumed the original type of 'priv' was void**, leading to an unnecessary and misleading cast. Correct the cast of the 'priv' pointer in test_dev_action() to its actual type, long*, removing an unnecessary cast. As an additional benefit, this fixes an out-of-bounds CHERI fault on hardware with architectural capabilities. The original implementation tried to store a capability-sized pointer using the priv pointer. However, the priv pointer's capability only granted access to the memory region of its original long type, leading to a bounds violation since the size of a long is smaller than the size of a capability. This change ensures that the pointer usage respects the capabilities' bounds. Link: https://lore.kernel.org/r/[email protected] Fixes: d03c720 ("kunit: Add APIs for managing devices") Reviewed-by: David Gow <[email protected]> Signed-off-by: Florian Schmaus <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 3a86608 commit 2551a1e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/kunit/kunit-test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ static struct kunit_case kunit_current_test_cases[] = {
739739

740740
static void test_dev_action(void *priv)
741741
{
742-
*(void **)priv = (void *)1;
742+
*(long *)priv = 1;
743743
}
744744

745745
static void kunit_device_test(struct kunit *test)

0 commit comments

Comments
 (0)