mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
PATCH 1/1 mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
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.
--- .../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
testcases/open_posix_testsuite/conformance/interfaces/mlock/8-1.c +2 -9
@@ -20,22 +20,15 @@#include <errno.h> #include <limits.h> #include "posixtest.h" +#include "invalid_helpers.h" #define BUFSIZE 8int 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 ) {
testcases/open_posix_testsuite/conformance/interfaces/munlock/10-1.c +2 -9
@@ -20,22 +20,15 @@#include <errno.h> #include <limits.h> #include "posixtest.h" +#include "invalid_helpers.h" #define BUFSIZE 8int 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 ) {
testcases/open_posix_testsuite/include/invalid_helpers.h new file +25 -0
@@ -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
Signature · 1 line
1.8.3.1
PATCH 1/1 mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
Hi!
Quoted 80 lines
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 <[email protected]>--- .../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.htestcases/open_posix_testsuite/conformance/interfaces/mlock/8-1.c +2
-9@@ -20,22 +20,15 @@#include <errno.h> #include <limits.h> #include "posixtest.h" +#include "invalid_helpers.h" #define BUFSIZE 8int 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 ) {testcases/open_posix_testsuite/conformance/interfaces/munlock/10-1.c +2
-9@@ -20,22 +20,15 @@#include <errno.h> #include <limits.h> #include "posixtest.h" +#include "invalid_helpers.h" #define BUFSIZE 8int 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 ) {testcases/open_posix_testsuite/include/invalid_helpers.h new file +0
-0
testcases/open_posix_testsuite/include/invalid_helpers.h line 6
Quoted 6 lines
testcases/open_posix_testsuite/include/invalid_helpers.h new file +6
-0@@ -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.
Quoted 6 lines
testcases/open_posix_testsuite/include/invalid_helpers.h new file +6
-0+#include <stdlib.h> +#include "safe_helpers.h" + +#define DISTANT_AREA_SIZE (128*1024*1024) + +static void *get_invalid_ptr (void )
testcases/open_posix_testsuite/include/invalid_helpers.h line 23
Quoted 10 lines
testcases/open_posix_testsuite/include/invalid_helpers.h new file +10
-0+{ +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.
Quoted 7 lines
testcases/open_posix_testsuite/include/invalid_helpers.h new file +1
-0+#endif Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
In reply to Jan StancekHi Jan,
Quoted 9 lines
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 <[email protected]>
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
PATCH 1/1 mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
----- Original Message -----
Quoted 7 lines
Hi Jan,
Quoted 4 lines
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).
Quoted 5 lines
Quoted 4 lines
Add a helper function which provides invalid/unused pointer from user address space.
Signed-off-by Jan Stancek <[email protected]>Reviewed-by Petr Vorel <[email protected]>
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.
PATCH 1/1 mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
Hi Jan,
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
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.
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
Signed-off-by Jan Stancek <[email protected]>Reviewed-by Petr Vorel <[email protected]>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
PATCH 1/1 mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
In reply to Jan StancekHi Jan,
I propose to reorg this patch with review comments (maybe apply it after the new release).
Any thought?
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210120/d2af51c0/attachment.htm>
PATCH 1/1 mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
----- Original Message -----
Quoted 6 lines
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.
PATCH 1/1 mlock_8-1, munlock_10-1: don't use LONG_MAX as invalid pointer
Jan Stancek <[email protected]> wrote:
...
Quoted 11 lines
Quoted 4 lines
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 tountagged_addr()
macro")
Thanks for the info, then we could filter this FAIL by kernel version.
Quoted 4 lines
I'd keep the test as is, maybe add comment with above commits as a hint for future.
+1
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210120/74a48091/attachment.htm>