diff mbox series

[bpf,v2] selftests: bpf: Fix bind on used port

Message ID 551ee65533bb987a43f93d88eaf2368b416ccd32.1642518457.git.fmaurer@redhat.com (mailing list archive)
State Accepted
Commit 8c0be0631d81e48f77d0ebf0534c86e32bef5f89
Delegated to: BPF
Headers show
Series [bpf,v2] selftests: bpf: Fix bind on used port | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 9 maintainers not CCed: andrii@kernel.org linux-kselftest@vger.kernel.org kpsingh@kernel.org daniel@iogearbox.net john.fastabend@gmail.com shuah@kernel.org songliubraving@fb.com yhs@fb.com netdev@vger.kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 36 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf success VM_Test

Commit Message

Felix Maurer Jan. 18, 2022, 3:11 p.m. UTC
The bind_perm BPF selftest failed when port 111/tcp was already in use
during the test. To fix this, the test now runs in its own network name
space.

To use unshare, it is necessary to reorder the includes. The style of
the includes is adapted to be consistent with the other prog_tests.

v2: Replace deprecated CHECK macro with ASSERT_OK

Fixes: 8259fdeb30326 ("selftests/bpf: Verify that rebinding to port < 1024 from BPF works")
Signed-off-by: Felix Maurer <fmaurer@redhat.com>
---
 .../selftests/bpf/prog_tests/bind_perm.c      | 20 ++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

Comments

Jakub Sitnicki Jan. 20, 2022, 6:52 p.m. UTC | #1
On Tue, Jan 18, 2022 at 04:11 PM CET, Felix Maurer wrote:
> The bind_perm BPF selftest failed when port 111/tcp was already in use
> during the test. To fix this, the test now runs in its own network name
> space.
>
> To use unshare, it is necessary to reorder the includes. The style of
> the includes is adapted to be consistent with the other prog_tests.
>
> v2: Replace deprecated CHECK macro with ASSERT_OK
>
> Fixes: 8259fdeb30326 ("selftests/bpf: Verify that rebinding to port < 1024 from BPF works")
> Signed-off-by: Felix Maurer <fmaurer@redhat.com>
> ---

Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
patchwork-bot+netdevbpf@kernel.org Jan. 20, 2022, 10:40 p.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Tue, 18 Jan 2022 16:11:56 +0100 you wrote:
> The bind_perm BPF selftest failed when port 111/tcp was already in use
> during the test. To fix this, the test now runs in its own network name
> space.
> 
> To use unshare, it is necessary to reorder the includes. The style of
> the includes is adapted to be consistent with the other prog_tests.
> 
> [...]

Here is the summary with links:
  - [bpf,v2] selftests: bpf: Fix bind on used port
    https://git.kernel.org/bpf/bpf-next/c/8c0be0631d81

You are awesome, thank you!
Andrii Nakryiko Jan. 21, 2022, 11:12 p.m. UTC | #3
On Fri, Jan 21, 2022 at 2:32 PM Jakub Sitnicki <jakub@cloudflare.com> wrote:
>
> On Tue, Jan 18, 2022 at 04:11 PM CET, Felix Maurer wrote:
> > The bind_perm BPF selftest failed when port 111/tcp was already in use
> > during the test. To fix this, the test now runs in its own network name
> > space.
> >
> > To use unshare, it is necessary to reorder the includes. The style of
> > the includes is adapted to be consistent with the other prog_tests.
> >
> > v2: Replace deprecated CHECK macro with ASSERT_OK
> >
> > Fixes: 8259fdeb30326 ("selftests/bpf: Verify that rebinding to port < 1024 from BPF works")
> > Signed-off-by: Felix Maurer <fmaurer@redhat.com>
> > ---
>
> Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>

I've applied it to bpf-next yesterday, patchbot missed it and I forgot
to follow up to notify, sorry.
Andrii Nakryiko Jan. 22, 2022, 12:20 a.m. UTC | #4
On Fri, Jan 21, 2022 at 4:18 PM <patchwork-bot+netdevbpf@kernel.org> wrote:
>
> Hello:
>
> This patch was applied to bpf/bpf-next.git (master)
> by Andrii Nakryiko <andrii@kernel.org>:

Better late than never :)

>
> On Tue, 18 Jan 2022 16:11:56 +0100 you wrote:
> > The bind_perm BPF selftest failed when port 111/tcp was already in use
> > during the test. To fix this, the test now runs in its own network name
> > space.
> >
> > To use unshare, it is necessary to reorder the includes. The style of
> > the includes is adapted to be consistent with the other prog_tests.
> >
> > [...]
>
> Here is the summary with links:
>   - [bpf,v2] selftests: bpf: Fix bind on used port
>     https://git.kernel.org/bpf/bpf-next/c/8c0be0631d81
>
> You are awesome, thank you!
> --
> Deet-doot-dot, I am a bot.
> https://korg.docs.kernel.org/patchwork/pwbot.html
>
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/bind_perm.c b/tools/testing/selftests/bpf/prog_tests/bind_perm.c
index d0f06e40c16d..eac71fbb24ce 100644
--- a/tools/testing/selftests/bpf/prog_tests/bind_perm.c
+++ b/tools/testing/selftests/bpf/prog_tests/bind_perm.c
@@ -1,13 +1,24 @@ 
 // SPDX-License-Identifier: GPL-2.0
-#include <test_progs.h>
-#include "bind_perm.skel.h"
-
+#define _GNU_SOURCE
+#include <sched.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/capability.h>
 
+#include "test_progs.h"
+#include "bind_perm.skel.h"
+
 static int duration;
 
+static int create_netns(void)
+{
+	if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns"))
+		return -1;
+
+	return 0;
+}
+
 void try_bind(int family, int port, int expected_errno)
 {
 	struct sockaddr_storage addr = {};
@@ -75,6 +86,9 @@  void test_bind_perm(void)
 	struct bind_perm *skel;
 	int cgroup_fd;
 
+	if (create_netns())
+		return;
+
 	cgroup_fd = test__join_cgroup("/bind_perm");
 	if (CHECK(cgroup_fd < 0, "cg-join", "errno %d", errno))
 		return;