All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/bpf: only munmap the mmaped ringbuf pages
@ 2021-05-14  1:23 Thadeu Lima de Souza Cascardo
  2021-05-14 18:07 ` Andrii Nakryiko
  0 siblings, 1 reply; 2+ messages in thread
From: Thadeu Lima de Souza Cascardo @ 2021-05-14  1:23 UTC (permalink / raw)
  To: bpf; +Cc: linux-kselftest, andrii, daniel, ast, cascardo

One the mmap tests will map a single page, then try to extend the
mapping by use of mremap, which should fail. Right after that, it unmaps
the extended area, which may end up unmapping other valid mapped areas,
this causing a segfault.

Only unmap the area that is expected to be mapped.

Fixes: b2fb299c9aa4 ("selftests/bpf: test ringbuf mmap read-only and read-write restrictions")
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
---
 tools/testing/selftests/bpf/prog_tests/ringbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
index 197e30b83298..f9a8ae331963 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
@@ -146,7 +146,7 @@ void test_ringbuf(void)
 	ASSERT_ERR(mprotect(mmap_ptr, page_size, PROT_WRITE), "write_protect");
 	ASSERT_ERR(mprotect(mmap_ptr, page_size, PROT_EXEC), "exec_protect");
 	ASSERT_ERR_PTR(mremap(mmap_ptr, 0, 3 * page_size, MREMAP_MAYMOVE), "ro_remap");
-	ASSERT_OK(munmap(mmap_ptr, 3 * page_size), "unmap_ro");
+	ASSERT_OK(munmap(mmap_ptr, page_size), "unmap_ro");
 
 	/* only trigger BPF program for current process */
 	skel->bss->pid = getpid();
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests/bpf: only munmap the mmaped ringbuf pages
  2021-05-14  1:23 [PATCH] selftests/bpf: only munmap the mmaped ringbuf pages Thadeu Lima de Souza Cascardo
@ 2021-05-14 18:07 ` Andrii Nakryiko
  0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2021-05-14 18:07 UTC (permalink / raw)
  To: Thadeu Lima de Souza Cascardo
  Cc: bpf, open list:KERNEL SELFTEST FRAMEWORK, Andrii Nakryiko,
	Daniel Borkmann, Alexei Starovoitov

On Thu, May 13, 2021 at 6:23 PM Thadeu Lima de Souza Cascardo
<cascardo@canonical.com> wrote:
>
> One the mmap tests will map a single page, then try to extend the
> mapping by use of mremap, which should fail. Right after that, it unmaps
> the extended area, which may end up unmapping other valid mapped areas,
> this causing a segfault.
>
> Only unmap the area that is expected to be mapped.
>
> Fixes: b2fb299c9aa4 ("selftests/bpf: test ringbuf mmap read-only and read-write restrictions")

We backed out this patch because it was causing our CI to crash on the
ringbuf test. I think you found out why :)

I'm going to incorporate your fix into my patch and leave your and
mine Signed-off-by and post it upstream. Hope that works fine for
attribution? And thanks for catching this!


> Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/ringbuf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
> index 197e30b83298..f9a8ae331963 100644
> --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
> +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
> @@ -146,7 +146,7 @@ void test_ringbuf(void)
>         ASSERT_ERR(mprotect(mmap_ptr, page_size, PROT_WRITE), "write_protect");
>         ASSERT_ERR(mprotect(mmap_ptr, page_size, PROT_EXEC), "exec_protect");
>         ASSERT_ERR_PTR(mremap(mmap_ptr, 0, 3 * page_size, MREMAP_MAYMOVE), "ro_remap");
> -       ASSERT_OK(munmap(mmap_ptr, 3 * page_size), "unmap_ro");
> +       ASSERT_OK(munmap(mmap_ptr, page_size), "unmap_ro");
>
>         /* only trigger BPF program for current process */
>         skel->bss->pid = getpid();
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-14 18:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14  1:23 [PATCH] selftests/bpf: only munmap the mmaped ringbuf pages Thadeu Lima de Souza Cascardo
2021-05-14 18:07 ` Andrii Nakryiko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.