Skip to contentSkip to conversation

selftests: bpf: Fix bind on used port

PATCH Applied Felix Maurer 4 participants 5 messages Jan 18, 2022 – Jan 22, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests: bpf: Fix bind on used port

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")
---
 .../selftests/bpf/prog_tests/bind_perm.c      | 20 ++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/bind_perm.c +17 -3
index d0f06e40c16d..eac71fbb24ce 100644
@@ -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;
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Felix Maurer

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.

Quoted 8 lines

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")

---

#2 lore raw
Quoted 9 lines · Jakub Sitnicki
Quoted 7 lines · Felix Maurer

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.

Quoted 7 lines
Quoted 5 lines

v2: Replace deprecated CHECK macro with ASSERT_OK

Fixes 8259fdeb30326 ("selftests/bpf: Verify that rebinding to port < 1024 from BPF works")

---

I've applied it to bpf-next yesterday, patchbot missed it and I forgot to follow up to notify, sorry.

#3 lore raw
In reply to Felix Maurer
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 8 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#4 lore raw
Quoted 5 lines · On Fri, Jan 21, 2022 at 4:18 PM <[email protected]> wrote:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Better late than never :)

Quoted 21 lines · On Tue, 18 Jan 2022 16:11:56 +0100 you wrote:
Quoted 8 lines

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