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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181026232409.16100-5-linux@rasmusvillemoes.dk>
Date:   Sat, 27 Oct 2018 01:24:06 +0200
From:   Rasmus Villemoes <linux@...musvillemoes.dk>
To:     Kees Cook <keescook@...omium.org>,
        Andrew Morton <akpm@...ux-foundation.org>
Cc:     linux-kernel@...r.kernel.org,
        Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: [RFC PATCH 4/7] lib/test_printf.c: add a few fmtcheck() test cases

It should be trivial to add more test cases, once we figure out the
exact rules for being compatible or not. Perhaps we'll have to extend
the struct test with a flags element if we add flags that affect the
return value.

Signed-off-by: Rasmus Villemoes <linux@...musvillemoes.dk>
---
 lib/test_printf.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/lib/test_printf.c b/lib/test_printf.c
index 53527ea822b5..5b6ba0e817d5 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -535,6 +535,47 @@ test_pointer(void)
 	flags();
 }
 
+static void __init
+test_fmtcheck(void)
+{
+#ifdef CONFIG_FMTCHECK
+	struct test { const char *fmt; const char *tmpl; };
+	static const struct test compatible[] __initconst = {
+		{"", ""},
+		{"wlan%d", "%d"},
+		{"aa%llxbb", "cc%Lxdd%%"},
+	};
+	static const struct test incompatible[] __initconst = {
+		{"a %d b %lx", "%d %x"},
+		{"%llo", "%Lx"},
+	};
+	unsigned i;
+	const struct test *t;
+	const char *ret;
+
+	for (i = 0; i < ARRAY_SIZE(compatible); ++i) {
+		total_tests++;
+		t = &compatible[i];
+		ret = _fmtcheck(t->fmt, t->tmpl, FMTCHECK_SILENT);
+		if (ret != t->fmt) {
+			failed_tests++;
+			pr_warn("'%s' and '%s' deemed incompatible by fmtcheck()",
+				t->fmt, t->tmpl);
+		}
+	}
+	for (i = 0; i < ARRAY_SIZE(incompatible); ++i) {
+		total_tests++;
+		t = &incompatible[i];
+		ret = _fmtcheck(t->fmt, t->tmpl, FMTCHECK_SILENT);
+		if (ret != t->tmpl) {
+			failed_tests++;
+			pr_warn("'%s' and '%s' deemed compatible by fmtcheck()",
+				t->fmt, t->tmpl);
+		}
+	}
+#endif
+}
+
 static int __init
 test_printf_init(void)
 {
@@ -548,6 +589,8 @@ test_printf_init(void)
 	test_string();
 	test_pointer();
 
+	test_fmtcheck();
+
 	kfree(alloced_buffer);
 
 	if (failed_tests == 0)
-- 
2.19.1.6.gbde171bbf5

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ