<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 Wed, Dec 18, 2019 at 12:02 PM Yang Xu <<a href="mailto:xuyang2018.jy@cn.fujitsu.com">xuyang2018.jy@cn.fujitsu.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">Since commit cefdca0a86be ("userfaultfd/sysctl: add vm.unprivileged_userfaultfd").<br>
, it adds a global sysctl knob "vm.unprivileged_userfaultfd" to control whether<br>
unprivileged users can use the userfaultfd system calls. Set this to 1 to allow<br>
unprivileged users to use the userfaultfd system calls, or set this to 0 to<br>
restrict userfaultfd to only privileged users (with SYS_CAP_PTRACE capability). The<br>
default value is 1. Add hint about it.<br></blockquote><div><br></div>Can we do the <span class="gmail_default" style="font-size:small">"</span>vm.unprivileged_userfaultfd<span class="gmail_default" style="font-size:small">"</span> check in the setup() and do set to 1 if it exists?<br>And <span class="gmail_default" style="font-size:small">maybe</span> we need <span class="gmail_default" style="font-size:small">more</span> tests for the global sysctl knob "vm.unprivileged_userfaultfd".<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>
Signed-off-by: Yang Xu <<a href="mailto:xuyang2018.jy@cn.fujitsu.com" target="_blank">xuyang2018.jy@cn.fujitsu.com</a>><br>
---<br>
 .../syscalls/userfaultfd/userfaultfd01.c      | 19 +++++++++++++------<br>
 1 file changed, 13 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c<br>
index a5e142209..4e178b4f8 100644<br>
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c<br>
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c<br>
@@ -82,12 +82,19 @@ static void run(void)<br>
<br>
        set_pages();<br>
<br>
-       uffd = sys_userfaultfd(O_CLOEXEC | O_NONBLOCK);<br>
-<br>
-       if (uffd == -1)<br>
-               tst_brk(TBROK | TERRNO,<br>
-                       "Could not create userfault file descriptor");<br>
-<br>
+       TEST(sys_userfaultfd(O_CLOEXEC | O_NONBLOCK));<br>
+<br>
+       if (TST_RET == -1) {<br>
+               if (TST_ERR == EPERM) {<br>
+                       tst_res(TCONF, "Hint: check /proc/sys/vm/unprivileged_userfaultfd");<br>
+                       tst_brk(TCONF | TTERRNO,<br>
+                               "userfaultfd() requires CAP_SYS_PTRACE on this system");<br>
+               } else<br>
+                       tst_brk(TBROK | TTERRNO,<br>
+                               "Could not create userfault file descriptor");<br>
+       }<br>
+<br>
+       uffd = TST_RET;<br>
        uffdio_api.api = UFFD_API;<br>
        uffdio_api.features = 0;<br>
        SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);<br>
-- <br>
2.18.0<br>
<br>
<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="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>