From: Cyril Hrubis <chrubis@suse.cz>
To: Tudor Cretu <tudor.cretu@arm.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 2/4] syscalls/mprotect01: Invoke the syscall directly instead of the libc wrapper
Date: Wed, 17 Aug 2022 16:29:48 +0200 [thread overview]
Message-ID: <Yvz7XPqVb/acIi6P@yuki> (raw)
In-Reply-To: <20220817133946.234985-3-tudor.cretu@arm.com>
Hi!
> per POSIX: The mprotect() function shall change the access protections
> to be that specified by prot for those whole pages containing any part
> of the address space of the process starting at address addr and
> continuing for len bytes.
>
> Issue 6 of POSIX introduces: The implementation may require that addr
> be a multiple of the page size as returned by sysconf().
>
> Therefore it's not strictly required that addr is a multiple of the page
> size. Some libcs (e.g. Musl) indeed don't have this requirement, so calling
> the C standard library function doesn't fail in their case. As the
> testsuite focuses on mprotect(2), the testcases should call the syscall
> directly instead of the libc function.
So Musl mproctect() does clear a few bits of the start and rounds the
len. That sounds like a dangerous thing to do to be honest, since you
end up with a different region than you requested.
I guess that this patch is reasonable solution since the glibc
mprotect() seems to be just wrapper for the syscall.
> Signed-off-by: Tudor Cretu <tudor.cretu@arm.com>
> ---
> testcases/kernel/syscalls/mprotect/mprotect01.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/mprotect/mprotect01.c b/testcases/kernel/syscalls/mprotect/mprotect01.c
> index be4d982ea..aa4685258 100644
> --- a/testcases/kernel/syscalls/mprotect/mprotect01.c
> +++ b/testcases/kernel/syscalls/mprotect/mprotect01.c
> @@ -43,6 +43,7 @@
> #include <stdlib.h>
> #include <unistd.h>
> #include "test.h"
> +#include "lapi/syscalls.h"
> #include "safe_macros.h"
>
> char *TCID = "mprotect01";
> @@ -97,7 +98,7 @@ int main(int ac, char **av)
> if (TC[i].setupfunc != NULL)
> TC[i].setupfunc(&TC[i]);
>
> - TEST(mprotect(TC[i].addr, TC[i].len, TC[i].prot));
> + TEST(tst_syscall(__NR_mprotect, TC[i].addr, TC[i].len, TC[i].prot));
>
> if (TEST_RETURN != -1) {
> tst_resm(TFAIL, "call succeeded unexpectedly");
> --
> 2.25.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-08-17 14:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-17 13:39 [LTP] [PATCH 0/4] syscalls: Fix various syscalls tests when compiled with Musl Tudor Cretu
2022-08-17 13:39 ` [LTP] [PATCH 1/4] lib: Fix initialization of recursive mutex Tudor Cretu
2022-08-17 14:13 ` Cyril Hrubis
2022-08-17 13:39 ` [LTP] [PATCH 2/4] syscalls/mprotect01: Invoke the syscall directly instead of the libc wrapper Tudor Cretu
2022-08-17 14:29 ` Cyril Hrubis [this message]
2022-08-17 13:39 ` [LTP] [PATCH 3/4] syscalls/prctl04: Allow rt_sigprocmask in the syscall filter Tudor Cretu
2022-08-17 14:42 ` Cyril Hrubis
2022-08-17 13:39 ` [LTP] [PATCH 4/4] syscalls/statfs: Avoid dereferencing invalid buf in libc Tudor Cretu
2022-08-17 14:40 ` Cyril Hrubis
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=Yvz7XPqVb/acIi6P@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=tudor.cretu@arm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox