Thread (64 messages) 64 messages, 2 authors, 2022-10-12

Re: [PATCH v7 13/18] seltests/landlock: add AF_UNSPEC family test

From: Konstantin Meskhidze (A) <hidden>
Date: 2022-09-10 20:48:16
Also in: linux-security-module, netfilter-devel


9/6/2022 11:09 AM, Mickaël Salaün пишет:
On 29/08/2022 19:03, Konstantin Meskhidze wrote:
quoted
Adds two selftests for connect() action with AF_UNSPEC family flag.
The one is with no landlock restrictions allows to disconnect already
connected socket with connect(..., AF_UNSPEC, ...):
     - connect_afunspec_no_restictions;
Typo: "restrictions" (everywhere)
   My mistake. Thanks.
quoted
The second one refuses landlocked process to disconnect already
connected socket:
     - connect_afunspec_with_restictions;

Signed-off-by: Konstantin Meskhidze <redacted>
---

Changes since v6:
* None.

Changes since v5:
* Formats code with clang-format-14.

Changes since v4:
* Refactors code with self->port, self->addr4 variables.
* Adds bind() hook check for with AF_UNSPEC family.

Changes since v3:
* Adds connect_afunspec_no_restictions test.
* Adds connect_afunspec_with_restictions test.

---
  tools/testing/selftests/landlock/net_test.c | 113 ++++++++++++++++++++
  1 file changed, 113 insertions(+)
diff --git a/tools/testing/selftests/landlock/net_test.c b/tools/testing/selftests/landlock/net_test.c
index 9c3d1e425439..40aef7c683af 100644
--- a/tools/testing/selftests/landlock/net_test.c
+++ b/tools/testing/selftests/landlock/net_test.c
@@ -351,4 +351,117 @@ TEST_F(socket, connect_with_restrictions)
  	ASSERT_EQ(1, WIFEXITED(status));
  	ASSERT_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
  }
+
+TEST_F(socket, connect_afunspec_no_restictions)
+{
+	int sockfd;
+	pid_t child;
+	int status;
+
+	/* Creates a server socket 1. */
+	sockfd = create_socket_variant(variant, SOCK_STREAM);
+	ASSERT_LE(0, sockfd);
+
+	/* Binds the socket 1 to address with port[0]. */
+	ASSERT_EQ(0, bind_variant(variant, sockfd, self, 0));
+
+	/* Makes connection to the socket with port[0]. */
+	ASSERT_EQ(0, connect_variant(variant, sockfd, self, 0));
+
+	child = fork();
+	ASSERT_LE(0, child);
+	if (child == 0) {
+		struct sockaddr addr_unspec = { .sa_family = AF_UNSPEC };
You can constify several variable like this one (in all tests).
   Got it. thanks.
.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help