All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>
Cc: "Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"Sergey Senozhatsky" <sergey.senozhatsky.work@gmail.com>,
	linux-kernel@vger.kernel.org,
	"Uwe Kleine-König" <uwe@kleine-koenig.org>,
	"Ilya Dryomov" <idryomov@gmail.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Tobin C . Harding" <me@tobin.cc>,
	"Petr Mladek" <pmladek@suse.com>
Subject: [PATCH 3/3] lib/test_printf: Clean up invalid pointer value testing
Date: Thu, 27 Feb 2020 14:01:23 +0100	[thread overview]
Message-ID: <20200227130123.32442-4-pmladek@suse.com> (raw)
In-Reply-To: <20200227130123.32442-1-pmladek@suse.com>

PTR_INVALID is a confusing name. It might mean any pointer value
that is not accessible. But check_pointer() function is able to
detect only the obviously invalid pointers: NULL pointer,
IS_ERR() range, and the first page.

Check all these three categories by better named values.

Use PTR_STR prefix for all expected output, including
the string used when crng has not been initialized yet.

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 lib/test_printf.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/test_printf.c b/lib/test_printf.c
index 1ee1bb703307..d640be78e3ae 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -206,13 +206,18 @@ test_string(void)
 }
 
 #define PLAIN_BUF_SIZE 64	/* leave some space so we don't oops */
+#define PTR_FIRST_PAGE ((void *)0x000000ab)
+#define PTR_STR_FIRST_PAGE "000000ab"
+#define PTR_ERROR ERR_PTR(-EFAULT)
+#define PTR_STR_ERROR "fffffff2"
 
 #if BITS_PER_LONG == 64
 
 #define PTR_WIDTH 16
 #define PTR ((void *)0xffff0123456789abUL)
 #define PTR_STR "ffff0123456789ab"
-#define PTR_VAL_NO_CRNG "(____ptrval____)"
+#define PTR_STR_NO_CRNG "(____ptrval____)"
+#define ONES "ffffffff"		/* hex 32 one bits */
 #define ZEROS "00000000"	/* hex 32 zero bits */
 
 #else
@@ -220,7 +225,8 @@ test_string(void)
 #define PTR_WIDTH 8
 #define PTR ((void *)0x456789ab)
 #define PTR_STR "456789ab"
-#define PTR_VAL_NO_CRNG "(ptrval)"
+#define PTR_STR_NO_CRNG "(ptrval)"
+#define ONES ""
 #define ZEROS ""
 
 #endif	/* BITS_PER_LONG == 64 */
@@ -248,7 +254,7 @@ test_hashed(const char *fmt, const void *p)
 		goto err;
 	}
 
-	if (strncmp(hash, PTR_VAL_NO_CRNG, PTR_WIDTH) == 0) {
+	if (strncmp(hash, PTR_STR_NO_CRNG, PTR_WIDTH) == 0) {
 		pr_warn_once("crng possibly not yet initialized. vsprinf(\"%s\", p) printed \"%s\"",
 			     fmt, hash);
 		total_tests--;
@@ -278,22 +284,22 @@ test_hashed(const char *fmt, const void *p)
 	failed_tests++;
 }
 
-#define PTR_INVALID ((void *)0x000000ab)
-
 static void __init
 plain_pointer(void)
 {
 	test_hashed("%p", PTR);
 	test_hashed("%p", NULL);
-	test_hashed("%p", PTR_INVALID);
+	test_hashed("%p", PTR_ERROR);
+	test_hashed("%p", PTR_FIRST_PAGE);
 }
 
 static void __init
 real_pointer(void)
 {
 	test(PTR_STR, "%px", PTR);
-	test(ZEROS "00000000", "%px", NULL);
-	test(ZEROS "000000ab", "%px", PTR_INVALID);
+	test(ZEROS ZEROS, "%px", NULL);
+	test(ONES PTR_STR_ERROR, "%px", PTR_ERROR);
+	test(ZEROS PTR_STR_FIRST_PAGE, "%px", PTR_FIRST_PAGE);
 }
 
 static void __init
@@ -321,7 +327,8 @@ static void __init
 escaped_str(void)
 {
 	test("(null)", "%pE", NULL);
-	test("(efault)", "%pE", PTR_INVALID);
+	test("(efault)", "%pE", PTR_ERROR);
+	test("(efault)", "%pE", PTR_FIRST_PAGE);
 }
 
 static void __init
@@ -408,9 +415,11 @@ dentry(void)
 	test("foo", "%pd2", &test_dentry[0]);
 
 	test("(null)", "%pd", NULL);
-	test("(efault)", "%pd", PTR_INVALID);
+	test("(efault)", "%pd", PTR_ERROR);
+	test("(efault)", "%pd", PTR_FIRST_PAGE);
 	test("(null)", "%pD", NULL);
-	test("(efault)", "%pD", PTR_INVALID);
+	test("(efault)", "%pD", PTR_ERROR);
+	test("(efault)", "%pD", PTR_FIRST_PAGE);
 
 	test("romeo", "%pd", &test_dentry[3]);
 	test("alfa/romeo", "%pd2", &test_dentry[3]);
-- 
2.16.4


  parent reply	other threads:[~2020-02-27 13:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-27 13:01 [PATCH 0/3] lib/test_printf: Clean up basic pointer testing Petr Mladek
2020-02-27 13:01 ` [PATCH 1/3] lib/test_printf: Clean up test of hashed pointers Petr Mladek
2020-02-27 14:30   ` Uwe Kleine-König
2020-03-02 10:24     ` Petr Mladek
2020-03-03 11:14   ` Rasmus Villemoes
2020-02-27 13:01 ` [PATCH 2/3] lib/test_printf: Fix structure of basic pointer tests Petr Mladek
2020-02-27 13:01 ` Petr Mladek [this message]
2020-03-03  7:24 ` [PATCH 0/3] lib/test_printf: Clean up basic pointer testing Sergey Senozhatsky
2020-03-03  9:22   ` Petr Mladek
2020-03-03 10:32     ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200227130123.32442-4-pmladek@suse.com \
    --to=pmladek@suse.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=idryomov@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=me@tobin.cc \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=uwe@kleine-koenig.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.