All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
Date: Mon, 14 Oct 2019 14:42:37 +0200	[thread overview]
Message-ID: <2e51e5453562001b5b6992ccc897d9177e6673ca.1571053661.git.jstancek@redhat.com> (raw)

arm64 kernel with commit 057d3389108e ("mm: untag user pointers passed to
memory syscalls") will assume this is tagged user pointer and will
attempt to clear first byte. This leads to test hitting different error
(EINVAL instead of ENOMEM).

Add a helper function which provides invalid/unused pointer from user
address space.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .../conformance/interfaces/mlock/8-1.c             | 11 ++--------
 .../conformance/interfaces/munlock/10-1.c          | 11 ++--------
 .../open_posix_testsuite/include/invalid_helpers.h | 25 ++++++++++++++++++++++
 3 files changed, 29 insertions(+), 18 deletions(-)
 create mode 100644 testcases/open_posix_testsuite/include/invalid_helpers.h

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mlock/8-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mlock/8-1.c
index d9569008b82b..5883ff8ec162 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mlock/8-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mlock/8-1.c
@@ -20,22 +20,15 @@
 #include <errno.h>
 #include <limits.h>
 #include "posixtest.h"
+#include "invalid_helpers.h"
 
 #define BUFSIZE 8
 
 int main(void)
 {
 	int result;
-	long page_size;
-	void *page_ptr;
+	void *page_ptr = get_invalid_ptr();
 
-	page_size = sysconf(_SC_PAGESIZE);
-	if (errno) {
-		perror("An error occurs when calling sysconf()");
-		return PTS_UNRESOLVED;
-	}
-
-	page_ptr = (void *)(LONG_MAX - (LONG_MAX % page_size));
 	result = mlock(page_ptr, BUFSIZE);
 
 	if (result == -1 && errno == ENOMEM) {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/munlock/10-1.c b/testcases/open_posix_testsuite/conformance/interfaces/munlock/10-1.c
index cf870289b512..1bc3d8015808 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/munlock/10-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/munlock/10-1.c
@@ -20,22 +20,15 @@
 #include <errno.h>
 #include <limits.h>
 #include "posixtest.h"
+#include "invalid_helpers.h"
 
 #define BUFSIZE 8
 
 int main(void)
 {
 	int result;
-	long page_size;
-	void *page_ptr;
+	void *page_ptr = get_invalid_ptr();
 
-	page_size = sysconf(_SC_PAGESIZE);
-	if (errno) {
-		perror("An error occurs when calling sysconf()");
-		return PTS_UNRESOLVED;
-	}
-
-	page_ptr = (void *)(LONG_MAX - (LONG_MAX % page_size));
 	result = munlock(page_ptr, BUFSIZE);
 
 	if (result == -1 && errno == ENOMEM) {
diff --git a/testcases/open_posix_testsuite/include/invalid_helpers.h b/testcases/open_posix_testsuite/include/invalid_helpers.h
new file mode 100644
index 000000000000..7882c783abf6
--- /dev/null
+++ b/testcases/open_posix_testsuite/include/invalid_helpers.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2019 Linux Test Project
+ */
+
+#ifndef __INVALID_HELPERS_H__
+#define __INVALID_HELPERS_H__
+
+#include <stdlib.h>
+#include "safe_helpers.h"
+
+#define DISTANT_AREA_SIZE (128*1024*1024)
+
+static void *get_invalid_ptr(void)
+{
+	int page_size;
+	void *ptr;
+
+	page_size = sysconf(_SC_PAGESIZE);
+	SAFE_PFUNC(posix_memalign(&ptr, page_size, DISTANT_AREA_SIZE));
+	free(ptr);
+
+	return (char *)ptr + (DISTANT_AREA_SIZE / 2);
+}
+
+#endif
-- 
1.8.3.1


             reply	other threads:[~2019-10-14 12:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 12:42 Jan Stancek [this message]
2019-10-14 12:50 ` [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer Cyril Hrubis
2019-10-18 13:37 ` Petr Vorel
2019-10-18 13:39   ` Jan Stancek
2019-10-18 13:46     ` Petr Vorel
2021-01-20  3:10 ` Li Wang
2021-01-20  9:32   ` Jan Stancek
2021-01-20  9:46     ` Li Wang

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=2e51e5453562001b5b6992ccc897d9177e6673ca.1571053661.git.jstancek@redhat.com \
    --to=jstancek@redhat.com \
    --cc=ltp@lists.linux.it \
    /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.