<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 20, 2019 at 9:05 PM Jan Stancek <<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
----- Original Message -----<br>
> Signed-off-by: Li Wang <<a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a>><br>
> ---<br>
>  <a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a>                               |   1 +<br>
>  include/lapi/syscalls/<a href="http://aarch64.in" rel="noreferrer" target="_blank">aarch64.in</a>           |   3 +<br>
>  include/lapi/syscalls/<a href="http://arm.in" rel="noreferrer" target="_blank">arm.in</a>               |   3 +<br>
>  include/lapi/syscalls/<a href="http://i386.in" rel="noreferrer" target="_blank">i386.in</a>              |   3 +<br>
>  include/lapi/syscalls/<a href="http://ia64.in" rel="noreferrer" target="_blank">ia64.in</a>              |   3 +<br>
>  include/lapi/syscalls/<a href="http://powerpc.in" rel="noreferrer" target="_blank">powerpc.in</a>           |   3 +<br>
>  include/lapi/syscalls/<a href="http://powerpc64.in" rel="noreferrer" target="_blank">powerpc64.in</a>         |   3 +<br>
>  include/lapi/syscalls/<a href="http://s390.in" rel="noreferrer" target="_blank">s390.in</a>              |   3 +<br>
>  include/lapi/syscalls/<a href="http://s390x.in" rel="noreferrer" target="_blank">s390x.in</a>             |   3 +<br>
>  include/lapi/syscalls/<a href="http://sh.in" rel="noreferrer" target="_blank">sh.in</a>                |   3 +<br>
>  include/lapi/syscalls/<a href="http://sparc.in" rel="noreferrer" target="_blank">sparc.in</a>             |   3 +<br>
>  include/lapi/syscalls/<a href="http://sparc64.in" rel="noreferrer" target="_blank">sparc64.in</a>           |   3 +<br>
>  include/lapi/syscalls/<a href="http://x86_64.in" rel="noreferrer" target="_blank">x86_64.in</a>            |   3 +<br>
>  runtest/syscalls                           |   2 +<br>
>  testcases/kernel/syscalls/pkeys/.gitignore |   1 +<br>
>  testcases/kernel/syscalls/pkeys/Makefile   |   8 ++<br>
>  testcases/kernel/syscalls/pkeys/pkey.h     |  44 +++++++++<br>
>  testcases/kernel/syscalls/pkeys/pkey01.c   | 105 +++++++++++++++++++++<br>
>  18 files changed, 197 insertions(+)<br>
>  create mode 100644 testcases/kernel/syscalls/pkeys/.gitignore<br>
>  create mode 100644 testcases/kernel/syscalls/pkeys/Makefile<br>
>  create mode 100644 testcases/kernel/syscalls/pkeys/pkey.h<br>
>  create mode 100644 testcases/kernel/syscalls/pkeys/pkey01.c<br>
> <br>
> diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> index 5ecc92781..35997699f 100644<br>
> --- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> +++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> @@ -76,6 +76,7 @@ AC_CHECK_FUNCS([ \<br>
>      profil \<br>
>      pwritev \<br>
>      pwritev2 \<br>
> +    pkey_mprotect \<br>
>      readlinkat \<br>
>      renameat \<br>
>      renameat2 \<br>
> diff --git a/include/lapi/syscalls/<a href="http://aarch64.in" rel="noreferrer" target="_blank">aarch64.in</a><br>
> b/include/lapi/syscalls/<a href="http://aarch64.in" rel="noreferrer" target="_blank">aarch64.in</a><br>
> index 177dd0115..4232defbe 100644<br>
> --- a/include/lapi/syscalls/<a href="http://aarch64.in" rel="noreferrer" target="_blank">aarch64.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://aarch64.in" rel="noreferrer" target="_blank">aarch64.in</a><br>
> @@ -266,3 +266,6 @@ copy_file_range 285<br>
>  preadv2 286<br>
>  pwritev2 287<br>
>  _sysctl 1078<br>
> +pkey_mprotect 394<br>
> +pkey_alloc 395<br>
> +pkey_free 396<br>
<br>
288, 289, 290<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Good eyes.</div><div class="gmail_default" style="font-size:small"> <br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> diff --git a/include/lapi/syscalls/<a href="http://arm.in" rel="noreferrer" target="_blank">arm.in</a> b/include/lapi/syscalls/<a href="http://arm.in" rel="noreferrer" target="_blank">arm.in</a><br>
> index f4adedb2c..48b55b5ff 100644<br>
> --- a/include/lapi/syscalls/<a href="http://arm.in" rel="noreferrer" target="_blank">arm.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://arm.in" rel="noreferrer" target="_blank">arm.in</a><br>
> @@ -350,3 +350,6 @@ copy_file_range (__NR_SYSCALL_BASE+391)<br>
>  preadv2 (__NR_SYSCALL_BASE+392)<br>
>  pwritev2 (__NR_SYSCALL_BASE+393)<br>
>  statx (__NR_SYSCALL_BASE+397)<br>
> +pkey_mprotect (__NR_SYSCALL_BASE+394)<br>
> +pkey_alloc (__NR_SYSCALL_BASE+395)<br>
> +pkey_free (__NR_SYSCALL_BASE+396)<br>
> diff --git a/include/lapi/syscalls/<a href="http://i386.in" rel="noreferrer" target="_blank">i386.in</a> b/include/lapi/syscalls/<a href="http://i386.in" rel="noreferrer" target="_blank">i386.in</a><br>
> index af5254f77..c54573547 100644<br>
> --- a/include/lapi/syscalls/<a href="http://i386.in" rel="noreferrer" target="_blank">i386.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://i386.in" rel="noreferrer" target="_blank">i386.in</a><br>
> @@ -348,3 +348,6 @@ copy_file_range 377<br>
>  preadv2 378<br>
>  pwritev2 379<br>
>  statx 383<br>
> +pkey_mprotect 380<br>
> +pkey_alloc 381<br>
> +pkey_free 382<br>
> diff --git a/include/lapi/syscalls/<a href="http://ia64.in" rel="noreferrer" target="_blank">ia64.in</a> b/include/lapi/syscalls/<a href="http://ia64.in" rel="noreferrer" target="_blank">ia64.in</a><br>
> index c0aeed08b..56bfd7928 100644<br>
> --- a/include/lapi/syscalls/<a href="http://ia64.in" rel="noreferrer" target="_blank">ia64.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://ia64.in" rel="noreferrer" target="_blank">ia64.in</a><br>
> @@ -305,3 +305,6 @@ mlock2 1346<br>
>  copy_file_range 1347<br>
>  preadv2 1348<br>
>  pwritev2 1349<br>
> +pkey_mprotect 330<br>
> +pkey_alloc 331<br>
> +pkey_free 332<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">And here should be: </div><span class="gmail_default" style="font-size:small">    </span>pkey_mprotect 1354<br><span class="gmail_default" style="font-size:small">    </span>pkey_alloc 1355<br><span class="gmail_default" style="font-size:small">    </span>pkey_free 1356<br><div class="gmail_default" style="font-size:small"><br></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> diff --git a/include/lapi/syscalls/<a href="http://powerpc.in" rel="noreferrer" target="_blank">powerpc.in</a><br>
> b/include/lapi/syscalls/<a href="http://powerpc.in" rel="noreferrer" target="_blank">powerpc.in</a><br>
> index 6b6be58a7..eaf8d45ed 100644<br>
> --- a/include/lapi/syscalls/<a href="http://powerpc.in" rel="noreferrer" target="_blank">powerpc.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://powerpc.in" rel="noreferrer" target="_blank">powerpc.in</a><br>
> @@ -355,3 +355,6 @@ copy_file_range 379<br>
>  preadv2 380<br>
>  pwritev2 381<br>
>  statx 383<br>
> +pkey_mprotect 386<br>
> +pkey_alloc 384<br>
> +pkey_free 385<br>
> diff --git a/include/lapi/syscalls/<a href="http://powerpc64.in" rel="noreferrer" target="_blank">powerpc64.in</a><br>
> b/include/lapi/syscalls/<a href="http://powerpc64.in" rel="noreferrer" target="_blank">powerpc64.in</a><br>
> index 6b6be58a7..eaf8d45ed 100644<br>
> --- a/include/lapi/syscalls/<a href="http://powerpc64.in" rel="noreferrer" target="_blank">powerpc64.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://powerpc64.in" rel="noreferrer" target="_blank">powerpc64.in</a><br>
> @@ -355,3 +355,6 @@ copy_file_range 379<br>
>  preadv2 380<br>
>  pwritev2 381<br>
>  statx 383<br>
> +pkey_mprotect 386<br>
> +pkey_alloc 384<br>
> +pkey_free 385<br>
> diff --git a/include/lapi/syscalls/<a href="http://s390.in" rel="noreferrer" target="_blank">s390.in</a> b/include/lapi/syscalls/<a href="http://s390.in" rel="noreferrer" target="_blank">s390.in</a><br>
> index 2a2ffe223..3ee5547f1 100644<br>
> --- a/include/lapi/syscalls/<a href="http://s390.in" rel="noreferrer" target="_blank">s390.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://s390.in" rel="noreferrer" target="_blank">s390.in</a><br>
> @@ -338,3 +338,6 @@ mlock2 374<br>
>  copy_file_range 375<br>
>  preadv2 376<br>
>  pwritev2 377<br>
> +pkey_mprotect 384<br>
> +pkey_alloc 385<br>
> +pkey_free 386<br>
> diff --git a/include/lapi/syscalls/<a href="http://s390x.in" rel="noreferrer" target="_blank">s390x.in</a> b/include/lapi/syscalls/<a href="http://s390x.in" rel="noreferrer" target="_blank">s390x.in</a><br>
> index 4c36ce17c..92e882aae 100644<br>
> --- a/include/lapi/syscalls/<a href="http://s390x.in" rel="noreferrer" target="_blank">s390x.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://s390x.in" rel="noreferrer" target="_blank">s390x.in</a><br>
> @@ -337,3 +337,6 @@ mlock2 374<br>
>  copy_file_range 375<br>
>  preadv2 376<br>
>  pwritev2 377<br>
> +pkey_mprotect 384<br>
> +pkey_alloc 385<br>
> +pkey_free 386<br>
> diff --git a/include/lapi/syscalls/<a href="http://sh.in" rel="noreferrer" target="_blank">sh.in</a> b/include/lapi/syscalls/<a href="http://sh.in" rel="noreferrer" target="_blank">sh.in</a><br>
> index a942fb506..00726c1cc 100644<br>
> --- a/include/lapi/syscalls/<a href="http://sh.in" rel="noreferrer" target="_blank">sh.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://sh.in" rel="noreferrer" target="_blank">sh.in</a><br>
> @@ -369,3 +369,6 @@ mlock2 390<br>
>  copy_file_range 391<br>
>  preadv2 392<br>
>  pwritev2 393<br>
> +pkey_mprotect 384<br>
> +pkey_alloc 385<br>
> +pkey_free 386<br>
> diff --git a/include/lapi/syscalls/<a href="http://sparc.in" rel="noreferrer" target="_blank">sparc.in</a> b/include/lapi/syscalls/<a href="http://sparc.in" rel="noreferrer" target="_blank">sparc.in</a><br>
> index 20dc37b01..1b34ab489 100644<br>
> --- a/include/lapi/syscalls/<a href="http://sparc.in" rel="noreferrer" target="_blank">sparc.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://sparc.in" rel="noreferrer" target="_blank">sparc.in</a><br>
> @@ -343,3 +343,6 @@ mlock2 356<br>
>  copy_file_range 357<br>
>  preadv2 358<br>
>  pwritev2 359<br>
> +pkey_mprotect 362<br>
> +pkey_alloc 363<br>
> +pkey_free 364<br>
> diff --git a/include/lapi/syscalls/<a href="http://sparc64.in" rel="noreferrer" target="_blank">sparc64.in</a><br>
> b/include/lapi/syscalls/<a href="http://sparc64.in" rel="noreferrer" target="_blank">sparc64.in</a><br>
> index c100b8e3e..f3142fbdd 100644<br>
> --- a/include/lapi/syscalls/<a href="http://sparc64.in" rel="noreferrer" target="_blank">sparc64.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://sparc64.in" rel="noreferrer" target="_blank">sparc64.in</a><br>
> @@ -319,3 +319,6 @@ mlock2 356<br>
>  copy_file_range 357<br>
>  preadv2 358<br>
>  pwritev2 359<br>
> +pkey_mprotect 362<br>
> +pkey_alloc 363<br>
> +pkey_free 364<br>
> diff --git a/include/lapi/syscalls/<a href="http://x86_64.in" rel="noreferrer" target="_blank">x86_64.in</a><br>
> b/include/lapi/syscalls/<a href="http://x86_64.in" rel="noreferrer" target="_blank">x86_64.in</a><br>
> index 87849e5c0..9c77f1c67 100644<br>
> --- a/include/lapi/syscalls/<a href="http://x86_64.in" rel="noreferrer" target="_blank">x86_64.in</a><br>
> +++ b/include/lapi/syscalls/<a href="http://x86_64.in" rel="noreferrer" target="_blank">x86_64.in</a><br>
> @@ -315,3 +315,6 @@ copy_file_range 326<br>
>  preadv2 327<br>
>  pwritev2 328<br>
>  statx 332<br>
> +pkey_mprotect 329<br>
> +pkey_alloc 330<br>
> +pkey_free 331<br>
> diff --git a/runtest/syscalls b/runtest/syscalls<br>
> index a1106fb84..a236fce09 100644<br>
> --- a/runtest/syscalls<br>
> +++ b/runtest/syscalls<br>
> @@ -723,6 +723,8 @@ mprotect02 mprotect02<br>
>  mprotect03 mprotect03<br>
>  mprotect04 mprotect04<br>
>  <br>
> +pkey01 pkey01<br>
> +<br>
>  mq_notify01 mq_notify01<br>
>  mq_notify02 mq_notify02<br>
>  mq_open01 mq_open01<br>
> diff --git a/testcases/kernel/syscalls/pkeys/.gitignore<br>
> b/testcases/kernel/syscalls/pkeys/.gitignore<br>
> new file mode 100644<br>
> index 000000000..6fd5addb8<br>
> --- /dev/null<br>
> +++ b/testcases/kernel/syscalls/pkeys/.gitignore<br>
> @@ -0,0 +1 @@<br>
> +/pkey01<br>
> diff --git a/testcases/kernel/syscalls/pkeys/Makefile<br>
> b/testcases/kernel/syscalls/pkeys/Makefile<br>
> new file mode 100644<br>
> index 000000000..9ee2c2ea5<br>
> --- /dev/null<br>
> +++ b/testcases/kernel/syscalls/pkeys/Makefile<br>
> @@ -0,0 +1,8 @@<br>
> +# SPDX-License-Identifier: GPL-2.0-or-later<br>
> +# Copyright (c) 2019 Red Hat, Inc.<br>
> +<br>
> +top_srcdir           ?= ../../../..<br>
> +<br>
> +include $(top_srcdir)/include/mk/<a href="http://testcases.mk" rel="noreferrer" target="_blank">testcases.mk</a><br>
> +<br>
> +include $(top_srcdir)/include/mk/<a href="http://generic_leaf_target.mk" rel="noreferrer" target="_blank">generic_leaf_target.mk</a><br>
> diff --git a/testcases/kernel/syscalls/pkeys/pkey.h<br>
> b/testcases/kernel/syscalls/pkeys/pkey.h<br>
> new file mode 100644<br>
> index 000000000..bd86bebcc<br>
> --- /dev/null<br>
> +++ b/testcases/kernel/syscalls/pkeys/pkey.h<br>
> @@ -0,0 +1,44 @@<br>
> +// SPDX-License-Identifier: GPL-2.0-or-later<br>
> +/*<br>
> + * Copyright (c) 2019 Red Hat, Inc.<br>
> + */<br>
> +<br>
> +#ifndef PKEYS_H<br>
> +#define PKEYS_H<br>
> +<br>
> +#include "tst_test.h"<br>
> +#include "lapi/syscalls.h"<br>
> +<br>
> +#ifndef PKEY_DISABLE_ACCESS<br>
> +# define PKEY_DISABLE_ACCESS 0x1<br>
> +# define PKEY_DISABLE_WRITE  0x2<br>
> +#endif<br>
> +<br>
> +#ifndef HAVE_PKEY_MPROTECT<br>
> +static inline int pkey_mprotect(void *addr, size_t len, int prot, int pkey)<br>
> +{<br>
> +     return tst_syscall(SYS_pkey_mprotect, addr, len, prot, pkey);<br>
> +}<br>
> +<br>
> +static inline int pkey_alloc(unsigned int flags, unsigned int access_rights)<br>
> +{<br>
> +     return tst_syscall(SYS_pkey_alloc, flags, access_rights);<br>
> +}<br>
> +<br>
> +static inline int pkey_free(int pkey)<br>
> +{<br>
> +     return tst_syscall(SYS_pkey_free, pkey);<br>
> +}<br>
> +#endif /* HAVE_PKEY_MPROTECT */<br>
> +<br>
> +static inline void check_pkey_support(void)<br>
> +{<br>
> +     int pkey = pkey_alloc(0, 0);<br>
> +<br>
> +     if ((pkey == -1) && (errno == EINVAL))<br>
<br>
Shouldn't this handle also ENOSPC?<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Yes, if all pkeys have been allocated on a system, then we will get this error in allocating a new pkey.</div></div><div class="gmail_default" style="font-size:small">I will handle this in v2.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
      ENOSPC (pkey_alloc()) All protection keys available for the current process have been allocated.  The number of keys available is<br>
              architecture-specific  and  implementation-specific  and may be reduced by kernel-internal use of certain keys.  There are<br>
              currently 15 keys available to user programs on x86.<br>
<br>
              This error will also be returned if the processor or operating system does  not  support  protection  keys.   Applications<br>
              should  always  be prepared to handle this error, since factors outside of the application's control can reduce the number<br>
              of available pkeys.<br>
<br>
> +             tst_brk(TCONF, "pkey_alloc is not supported");<br>
> +     else<br>
> +             pkey_free(pkey);<br>
> +}<br>
> +<br>
> +#endif /* PKEYS_H */<br>
> diff --git a/testcases/kernel/syscalls/pkeys/pkey01.c<br>
> b/testcases/kernel/syscalls/pkeys/pkey01.c<br>
> new file mode 100644<br>
> index 000000000..8faa4be4c<br>
> --- /dev/null<br>
> +++ b/testcases/kernel/syscalls/pkeys/pkey01.c<br>
> @@ -0,0 +1,105 @@<br>
> +// SPDX-License-Identifier: GPL-2.0-or-later<br>
> +/*<br>
> + * Copyright (c) 2019 Red Hat, Inc.<br>
> + *<br>
> + * Test for Memory Protection Keys<br>
> + * Reference: <a href="https://lwn.net/Articles/689395/" rel="noreferrer" target="_blank">https://lwn.net/Articles/689395/</a><br>
> + */<br>
> +<br>
> +#define _GNU_SOURCE<br>
> +#include <stdio.h><br>
> +#include <unistd.h><br>
> +#include <errno.h><br>
> +#include <stdlib.h><br>
> +#include <sys/syscall.h><br>
> +#include <sys/mman.h><br>
> +#include <sys/wait.h><br>
> +<br>
> +#include "pkey.h"<br>
> +<br>
> +static int psize;<br>
> +static char *buffer;<br>
> +<br>
> +static struct tcase {<br>
> +     unsigned long flags;<br>
> +     unsigned long access_rights;<br>
> +     char *name;<br>
> +} tcases[] = {<br>
> +     {0, PKEY_DISABLE_ACCESS, "PKEY_DISABLE_ACCESS"},<br>
> +     {0, PKEY_DISABLE_WRITE, "PKEY_DISABLE_WRITE"},<br>
> +};<br>
> +<br>
> +static void setup(void)<br>
> +{<br>
> +     check_pkey_support();<br>
> +<br>
> +     psize = getpagesize();<br>
> +     buffer = SAFE_MMAP(NULL, psize, PROT_READ | PROT_WRITE,<br>
> +                     MAP_ANONYMOUS | MAP_SHARED, -1, 0);<br>
> +     memset(buffer, 'a', psize);<br>
> +}<br>
> +<br>
> +static void verify_pkey(unsigned int i)<br>
> +{<br>
> +     int pkey, status;<br>
> +     pid_t pid;<br>
> +<br>
> +     struct tcase *tc = &tcases[i];<br>
> +<br>
> +     pkey = pkey_alloc(tc->flags, tc->access_rights);<br>
> +     if (pkey == -1)<br>
> +             tst_brk(TBROK, "pkey_alloc failed");<br>
> +<br>
> +     tst_res(TINFO, "Set %s on buffer", tc->name);<br>
> +     if (pkey_mprotect(buffer, psize, PROT_READ | PROT_WRITE, pkey) == -1)<br>
> +             tst_brk(TBROK, "pkey_mprotect failed");<br>
> +<br>
> +     pid = SAFE_FORK();<br>
> +     if (pid == 0) {<br>
<br>
I'd suggest something like:<br>
                struct rlimit r;                                                                                                            <br>
<br>
                r.rlim_cur = 1;                                                                                                             <br>
                r.rlim_max = 1;                                                                                                             <br>
                SAFE_SETRLIMIT(RLIMIT_CORE, &r); <br>
<br>
to avoid getting cores from this child - since it is expected to segfault.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Good advice.</div></div><div class="gmail_default" style="font-size:small"> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +             switch (tc->access_rights) {<br>
> +             case PKEY_DISABLE_ACCESS:<br>
> +                     tst_res(TFAIL, "Read buffer success, buffer[0] = %d", *buffer);<br>
> +             break;<br>
> +             case PKEY_DISABLE_WRITE:<br>
> +                     *buffer = 'b';<br>
> +             break;<br>
> +             }<br>
> +             exit(0);<br>
> +     }<br>
> +<br>
> +     SAFE_WAITPID(pid, &status, 0);<br>
> +     if (WIFSIGNALED(status)) {<br>
> +             if (WTERMSIG(status) == SIGSEGV) {<br>
> +                     tst_res(TPASS, "Child ended by %s as expected",<br>
> +                             tst_strsig(SIGSEGV));<br>
> +             } else {<br>
> +                     tst_res(TFAIL, "Child ended by %s unexpected" ,<br>
> +                             tst_strsig(WTERMSIG(status)));<br>
> +             }<br>
> +     } else {<br>
> +             tst_res(TFAIL, "Child unexpectedly ended");<br>
> +     }<br>
> +<br>
> +     tst_res(TINFO, "Remove %s from buffer", tc->name);<br>
> +     if (pkey_mprotect(buffer, psize, PROT_READ | PROT_WRITE, 0x0) == -1)<br>
> +             tst_brk(TBROK, "pkey_mprotect failed");<br>
> +     *buffer = i;<br>
> +     tst_res(TPASS, "Write buffer success, buffer[0] = %d", *buffer);<br>
> +<br>
> +     if (pkey_free(pkey) == -1)<br>
> +             tst_brk(TBROK, "pkey_free failed");<br>
> +}<br>
> +<br>
> +static void cleanup(void)<br>
> +{<br>
> +     if (buffer)<br>
> +             SAFE_MUNMAP(buffer, psize);<br>
> +}<br>
> +<br>
> +static struct tst_test test = {<br>
> +     .tcnt = ARRAY_SIZE(tcases),<br>
> +     .forks_child = 1,<br>
> +     .test = verify_pkey,<br>
> +     .setup = setup,<br>
> +     .cleanup = cleanup,<br>
> +};<br>
> --<br>
> 2.20.1<br>
> <br>
> <br>
> --<br>
> Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
> <br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_7944904958832786292gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>