lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 13 Jan 2023 14:07:18 -0800
From:   Daniel Latypov <dlatypov@...gle.com>
To:     brendanhiggins@...gle.com, davidgow@...gle.com
Cc:     rmoar@...gle.com, linux-kernel@...r.kernel.org,
        kunit-dev@...glegroups.com, linux-kselftest@...r.kernel.org,
        skhan@...uxfoundation.org, Daniel Latypov <dlatypov@...gle.com>
Subject: [PATCH] kunit: kunit_skip() should not overwrite KUNIT_FAIL()

Currently, kunit_skip() and kunit_mark_skipped() will overwrite the
current test's status even if it was already marked FAILED.

E.g. a test that just contains this
 KUNIT_FAIL(test, "FAIL REASON");
 kunit_skip(test, "SKIP REASON");
will be marked "SKIPPED" in the end.

Now, tests like the above don't and shouldn't exist.
But what happens if non-test code (e.g. KASAN) calls kunit_fail_current_test()?

E.g. if we have
  if (do_some_invalid_memory_accesses())
    kunit_skip(");
then the KASAN failures will get masked!

This patch: make it so kunit_mark_skipped() does not modify the status
if it's already set to something (either already to SKIPPED or FAILURE).

Before this change, the KTAP output would look like
    # example_simple_test: EXPECTATION FAILED at lib/kunit/kunit-example-test.c:23
FAIL REASON
    ok 1 example_simple_test # SKIP SKIP REASON

After this change:
    # example_simple_test: EXPECTATION FAILED at lib/kunit/kunit-example-test.c:23
FAIL REASON
    # example_simple_test: status already changed, not marking skipped: SKIP REASON
    not ok 1 example_simple_test

Signed-off-by: Daniel Latypov <dlatypov@...gle.com>
---
 include/kunit/test.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/kunit/test.h b/include/kunit/test.h
index 87ea90576b50..39936463dde5 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -386,11 +386,18 @@ void __printf(2, 3) kunit_log_append(char *log, const char *fmt, ...);
  *
  * Marks the test as skipped. @fmt is given output as the test status
  * comment, typically the reason the test was skipped.
+ * This has no effect if the test has already been marked skipped or failed.
  *
  * Test execution continues after kunit_mark_skipped() is called.
  */
 #define kunit_mark_skipped(test_or_suite, fmt, ...)			\
 	do {								\
+		if (READ_ONCE((test_or_suite)->status) != KUNIT_SUCCESS) {\
+			kunit_warn(test_or_suite, "status already "	\
+				   "changed, not marking skipped: " fmt,\
+				   ##__VA_ARGS__);			\
+			break;						\
+		}							\
 		WRITE_ONCE((test_or_suite)->status, KUNIT_SKIPPED);	\
 		scnprintf((test_or_suite)->status_comment,		\
 			  KUNIT_STATUS_COMMENT_SIZE,			\

base-commit: 7dd4b804e08041ff56c88bdd8da742d14b17ed25
-- 
2.39.0.314.g84b9a713c41-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ