* [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
@ 2019-10-14 12:42 Jan Stancek
2019-10-14 12:50 ` Cyril Hrubis
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Jan Stancek @ 2019-10-14 12:42 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
2019-10-14 12:42 [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer Jan Stancek
@ 2019-10-14 12:50 ` Cyril Hrubis
2019-10-18 13:37 ` Petr Vorel
2021-01-20 3:10 ` Li Wang
2 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2019-10-14 12:50 UTC (permalink / raw)
To: ltp
Hi!
> 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__
^
Strictly speaking the double underscores are reserved for
low level code i.e. libc and related code so we should avoid
them.
> +#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);
> +}
Maybe it's worth of a comment what is the idea behind this code here.
> +#endif
> --
> 1.8.3.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
2019-10-14 12:42 [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer Jan Stancek
2019-10-14 12:50 ` Cyril Hrubis
@ 2019-10-18 13:37 ` Petr Vorel
2019-10-18 13:39 ` Jan Stancek
2021-01-20 3:10 ` Li Wang
2 siblings, 1 reply; 8+ messages in thread
From: Petr Vorel @ 2019-10-18 13:37 UTC (permalink / raw)
To: ltp
Hi Jan,
> 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>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Agree with Cyril points (double underscores at the beginning are reserved for
libc and putting very brief info at get_invalid_ptr(().
Kind regards,
Petr
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
2019-10-18 13:37 ` Petr Vorel
@ 2019-10-18 13:39 ` Jan Stancek
2019-10-18 13:46 ` Petr Vorel
0 siblings, 1 reply; 8+ messages in thread
From: Jan Stancek @ 2019-10-18 13:39 UTC (permalink / raw)
To: ltp
----- Original Message -----
> Hi Jan,
>
> > 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>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
Thanks, discussion in:
http://lists.linux.it/pipermail/ltp/2019-October/013993.html
is still going, so maybe this will be fixed on kernel side
after all.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
2019-10-18 13:39 ` Jan Stancek
@ 2019-10-18 13:46 ` Petr Vorel
0 siblings, 0 replies; 8+ messages in thread
From: Petr Vorel @ 2019-10-18 13:46 UTC (permalink / raw)
To: ltp
Hi Jan,
> > > 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>
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Thanks, discussion in:
> http://lists.linux.it/pipermail/ltp/2019-October/013993.html
> is still going, so maybe this will be fixed on kernel side
> after all.
Thanks for info, I didn't notice this is related to your patch.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
2019-10-14 12:42 [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer Jan Stancek
2019-10-14 12:50 ` Cyril Hrubis
2019-10-18 13:37 ` Petr Vorel
@ 2021-01-20 3:10 ` Li Wang
2021-01-20 9:32 ` Jan Stancek
2 siblings, 1 reply; 8+ messages in thread
From: Li Wang @ 2021-01-20 3:10 UTC (permalink / raw)
To: ltp
Hi Jan,
I propose to reorg this patch with review comments (maybe apply it after
the new release).
Any thought?
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210120/d2af51c0/attachment.htm>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
2021-01-20 3:10 ` Li Wang
@ 2021-01-20 9:32 ` Jan Stancek
2021-01-20 9:46 ` Li Wang
0 siblings, 1 reply; 8+ messages in thread
From: Jan Stancek @ 2021-01-20 9:32 UTC (permalink / raw)
To: ltp
----- Original Message -----
> Hi Jan,
>
> I propose to reorg this patch with review comments (maybe apply it after
> the new release).
>
> Any thought?
This has been fixed in kernel by:
597399d0cb91 ("arm64: tags: Preserve tags for addresses translated via TTBR1")
d0022c0ef29b ("arm64: memory: Add missing brackets to untagged_addr() macro")
I'd keep the test as is, maybe add comment with above commits as a hint for future.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
2021-01-20 9:32 ` Jan Stancek
@ 2021-01-20 9:46 ` Li Wang
0 siblings, 0 replies; 8+ messages in thread
From: Li Wang @ 2021-01-20 9:46 UTC (permalink / raw)
To: ltp
Jan Stancek <jstancek@redhat.com> wrote:
...
> > I propose to reorg this patch with review comments (maybe apply it after
> > the new release).
> >
> > Any thought?
>
> This has been fixed in kernel by:
> 597399d0cb91 ("arm64: tags: Preserve tags for addresses translated via
> TTBR1")
> d0022c0ef29b ("arm64: memory: Add missing brackets to untagged_addr()
> macro")
>
Thanks for the info, then we could filter this FAIL by kernel version.
>
> I'd keep the test as is, maybe add comment with above commits as a hint
> for future.
>
+1
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210120/74a48091/attachment.htm>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-01-20 9:46 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 12:42 [LTP] [PATCH] mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer Jan Stancek
2019-10-14 12:50 ` 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
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.