Skip to contentSkip to conversation

kunit: Always print actual pointer values in asserts

PATCH In review David Gow 3 participants 5 messages Nov 21, 2019 – Mar 25, 2020

Subsystems (2)
lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH 1/1 kunit: Always print actual pointer values in asserts

KUnit assertions and expectations will print the values being tested. If these are pointers (e.g., KUNIT_EXPECT_PTR_EQ(test, a, b)), these pointers are currently printed with the %pK format specifier, which -- to prevent information leaks which may compromise, e.g., ASLR -- are often either hashed or replaced with ____ptrval____ or similar, making debugging tests difficult.

By replacing %pK with %px as Documentation/core-api/printk-formats.rst suggests, we disable this security feature for KUnit assertions and expectations, allowing the actual pointer values to be printed. Given that KUnit is not intended for use in production kernels, and the pointers are only printed on failing tests, this seems like a worthwhile tradeoff.

---
This seems like the best way of solving this problem to me, but if anyone has a better solution I'd love to hear it.

Note also that this does trigger two checkpatch.pl warnings, which warn that the change will potentially cause the kernel memory layout to be exposed. Since that's the whole point of the change, they probably sohuld stay there.

 lib/kunit/assert.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/kunit/assert.c +2 -2
index 86013d4cf891..a87960409bd4 100644
@@ -110,10 +110,10 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
 			 binary_assert->left_text,
 			 binary_assert->operation,
 			 binary_assert->right_text);
-	string_stream_add(stream, "\t\t%s == %pK\n",
+	string_stream_add(stream, "\t\t%s == %px\n",
 			 binary_assert->left_text,
 			 binary_assert->left_value);
-	string_stream_add(stream, "\t\t%s == %pK",
+	string_stream_add(stream, "\t\t%s == %px",
 			 binary_assert->right_text,
 			 binary_assert->right_value);
 	kunit_assert_print_msg(assert, stream);
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · David Gow

KUnit assertions and expectations will print the values being tested. If these are pointers (e.g., KUNIT_EXPECT_PTR_EQ(test, a, b)), these pointers are currently printed with the %pK format specifier, which -- to prevent information leaks which may compromise, e.g., ASLR -- are often either hashed or replaced with ____ptrval____ or similar, making debugging tests difficult.

Quoted 6 lines

By replacing %pK with %px as Documentation/core-api/printk-formats.rst suggests, we disable this security feature for KUnit assertions and expectations, allowing the actual pointer values to be printed. Given that KUnit is not intended for use in production kernels, and the pointers are only printed on failing tests, this seems like a worthwhile tradeoff.

I agree. However, I also remember that others in the past yelled at me for assuming that KUnit would not be built into production kernels.

I feel like +Kees Cook would have a good opinion on this (or will at least CC the right people).

Quoted 2 lines

Thanks!

author
#2 lore raw
Quoted 17 lines · Brendan Higgins
Quoted 8 lines · David Gow

KUnit assertions and expectations will print the values being tested. If these are pointers (e.g., KUNIT_EXPECT_PTR_EQ(test, a, b)), these pointers are currently printed with the %pK format specifier, which -- to prevent information leaks which may compromise, e.g., ASLR -- are often either hashed or replaced with ____ptrval____ or similar, making debugging tests difficult.

Quoted 6 lines

By replacing %pK with %px as Documentation/core-api/printk-formats.rst suggests, we disable this security feature for KUnit assertions and expectations, allowing the actual pointer values to be printed. Given that KUnit is not intended for use in production kernels, and the pointers are only printed on failing tests, this seems like a worthwhile tradeoff.

Quoted 6 lines

I agree. However, I also remember that others in the past yelled at me for assuming that KUnit would not be built into production kernels.

I feel like +Kees Cook would have a good opinion on this (or will at least CC the right people).

I'm tempted to take the silence as a sign that no-one is upset by this. Otherwise, consider this a gentle reminder to file any objections you may have. :-)

Otherwise, I've confirmed that this still applies cleanly to the latest linux-kselftest/kunit branch, so -- assuming there are no last-minute objections -- this ought to be ready to go.

Cheers,
-- David

#3 lore raw
Quoted 27 lines · David Gow
Quoted 17 lines · Brendan Higgins
Quoted 8 lines · David Gow

KUnit assertions and expectations will print the values being tested. If these are pointers (e.g., KUNIT_EXPECT_PTR_EQ(test, a, b)), these pointers are currently printed with the %pK format specifier, which -- to prevent information leaks which may compromise, e.g., ASLR -- are often either hashed or replaced with ____ptrval____ or similar, making debugging tests difficult.

Quoted 6 lines

By replacing %pK with %px as Documentation/core-api/printk-formats.rst suggests, we disable this security feature for KUnit assertions and expectations, allowing the actual pointer values to be printed. Given that KUnit is not intended for use in production kernels, and the pointers are only printed on failing tests, this seems like a worthwhile tradeoff.

Quoted 6 lines

I agree. However, I also remember that others in the past yelled at me for assuming that KUnit would not be built into production kernels.

I feel like +Kees Cook would have a good opinion on this (or will at least CC the right people).

Quoted 7 lines

I'm tempted to take the silence as a sign that no-one is upset by this. Otherwise, consider this a gentle reminder to file any objections you may have. :-)

Otherwise, I've confirmed that this still applies cleanly to the latest linux-kselftest/kunit branch, so -- assuming there are no last-minute objections -- this ought to be ready to go.

Shuah, can you pick this up for 5.7?

maintainer
#4 lore raw
Quoted 32 lines · Brendan Higgins
Quoted 31 lines · David Gow
Quoted 17 lines · Brendan Higgins
Quoted 8 lines · David Gow

KUnit assertions and expectations will print the values being tested. If these are pointers (e.g., KUNIT_EXPECT_PTR_EQ(test, a, b)), these pointers are currently printed with the %pK format specifier, which -- to prevent information leaks which may compromise, e.g., ASLR -- are often either hashed or replaced with ____ptrval____ or similar, making debugging tests difficult.

Quoted 6 lines

By replacing %pK with %px as Documentation/core-api/printk-formats.rst suggests, we disable this security feature for KUnit assertions and expectations, allowing the actual pointer values to be printed. Given that KUnit is not intended for use in production kernels, and the pointers are only printed on failing tests, this seems like a worthwhile tradeoff.

Quoted 6 lines

I agree. However, I also remember that others in the past yelled at me for assuming that KUnit would not be built into production kernels.

I feel like +Kees Cook would have a good opinion on this (or will at least CC the right people).

I'm tempted to take the silence as a sign that no-one is upset by this. Otherwise, consider this a gentle reminder to file any objections you may have. :-)

Quoted 6 lines
Quoted 3 lines

Otherwise, I've confirmed that this still applies cleanly to the latest linux-kselftest/kunit branch, so -- assuming there are no last-minute objections -- this ought to be ready to go.

Shuah, can you pick this up for 5.7?

Yes. I will pick this up.

thanks,
-- Shuah