[LTP] [PATCH 2/4] syscalls/mprotect01: Invoke the syscall directly instead of the libc wrapper

Cyril Hrubis chrubis@suse.cz
Wed Aug 17 16:29:48 CEST 2022


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


More information about the ltp mailing list