All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>
Cc: "Simon Horman" <horms@kernel.org>,
	"Kuniyuki Iwashima" <kuniyu@google.com>,
	"Kuniyuki Iwashima" <kuni1840@gmail.com>,
	netdev@vger.kernel.org, "Mickaël Salaün" <mic@digikod.net>,
	"Günther Noack" <gnoack@google.com>,
	linux-security-module@vger.kernel.org
Subject: [PATCH v1 net-next 1/4] selftests: landlock: Replace MSG_OOB with O_ASYNC+F_SETSIG.
Date: Mon, 16 Nov 2026 02:18:18 +0000	[thread overview]
Message-ID: <20261116021845.2533130-2-kuniyu@google.com> (raw)
In-Reply-To: <20261116021845.2533130-1-kuniyu@google.com>

AF_UNIX will drop MSG_OOB support.

scoped_signal_test.c uses MSG_OOB in fown.sigurg_socket and
trace_fown.deny_scope_fown to trigger SIGURG and exercise
security_file_send_sigiotask().

The same hook can be exercised via send_sigio() with a plain send()
by setting O_ASYNC and F_SETSIG with SIGURG on recv_socket.

Let's replace MSG_OOB with O_ASYNC and F_SETSIG so that the tests
do not depend on CONFIG_AF_UNIX_OOB.

Note that with O_ASYNC set on recv_socket, closing client_socket
while recv_socket is still open also triggers SIGURG for POLL_HUP
in unix_release_sock(), which would emit an extra
landlock_deny_scope_signal trace event in
trace_fown.deny_scope_fown.  Thus, the child waits for the parent
to close recv_socket via pipe_parent before closing client_socket.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Cc: "Mickaël Salaün" <mic@digikod.net>
Cc: "Günther Noack" <gnoack@google.com>
Cc: linux-security-module@vger.kernel.org
---
 tools/testing/selftests/landlock/config       |  1 -
 .../selftests/landlock/scoped_signal_test.c   | 55 ++++++++-----------
 2 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/tools/testing/selftests/landlock/config b/tools/testing/selftests/landlock/config
index 5568d7a4b2d7..fb617c1a4ce3 100644
--- a/tools/testing/selftests/landlock/config
+++ b/tools/testing/selftests/landlock/config
@@ -1,4 +1,3 @@
-CONFIG_AF_UNIX_OOB=y
 CONFIG_AUDIT=y
 CONFIG_CGROUPS=y
 CONFIG_CGROUP_SCHED=y
diff --git a/tools/testing/selftests/landlock/scoped_signal_test.c b/tools/testing/selftests/landlock/scoped_signal_test.c
index 259cdcc8aa5c..c4c365007370 100644
--- a/tools/testing/selftests/landlock/scoped_signal_test.c
+++ b/tools/testing/selftests/landlock/scoped_signal_test.c
@@ -405,24 +405,6 @@ static int setup_signal_handler(int signal)
 	return sigaction(SIGURG, &sa, NULL);
 }
 
-/*
- * MSG_OOB might be disabled in the kernel via the CONFIG_AF_UNIX_OOB
- * switch, so this function can be used for probing for its availability.
- */
-static bool has_af_unix_oob(void)
-{
-	bool available = false;
-	int sp[2];
-
-	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) == 0) {
-		available = (send(sp[0], ".", 1, MSG_OOB) == 1);
-		close(sp[0]);
-		close(sp[1]);
-	}
-
-	return available;
-}
-
 /* clang-format off */
 FIXTURE(fown) {};
 /* clang-format on */
@@ -473,8 +455,8 @@ FIXTURE_TEARDOWN(fown)
 }
 
 /*
- * Sending an out of bound message will trigger the SIGURG signal
- * through file_send_sigiotask.
+ * Sending a message to a socket with O_ASYNC will trigger
+ * the SIGURG signal through file_send_sigiotask.
  */
 TEST_F(fown, sigurg_socket)
 {
@@ -485,9 +467,6 @@ TEST_F(fown, sigurg_socket)
 	int pipe_parent[2], pipe_child[2];
 	pid_t child;
 
-	if (!has_af_unix_oob())
-		SKIP(return, "CONFIG_AF_UNIX_OOB / MSG_OOB not available");
-
 	memset(&server_address, 0, sizeof(server_address));
 	set_unix_address(&server_address, 0);
 
@@ -521,14 +500,14 @@ TEST_F(fown, sigurg_socket)
 		 */
 		ASSERT_EQ(1, read(pipe_parent[0], &buffer_child, 1));
 		/* May signal itself. */
-		ASSERT_EQ(1, send(client_socket, ".", 1, MSG_OOB));
-		EXPECT_EQ(0, close(client_socket));
+		ASSERT_EQ(1, send(client_socket, ".", 1, 0));
 		ASSERT_EQ(1, write(pipe_child[1], ".", 1));
 		EXPECT_EQ(0, close(pipe_child[1]));
 
 		/* Waits for the message to be received. */
 		ASSERT_EQ(1, read(pipe_parent[0], &buffer_child, 1));
 		EXPECT_EQ(0, close(pipe_parent[0]));
+		EXPECT_EQ(0, close(client_socket));
 
 		if (variant->sandbox_setown == SANDBOX_BEFORE_SETOWN) {
 			ASSERT_EQ(0, signal_received);
@@ -560,20 +539,22 @@ TEST_F(fown, sigurg_socket)
 		create_scoped_domain(_metadata, LANDLOCK_SCOPE_SIGNAL);
 
 	/*
-	 * Sets the child to receive SIGURG for MSG_OOB.  This uncommon use is
+	 * Sets the child to receive SIGURG.  This uncommon use is
 	 * a valid attack scenario which also simplifies this test.
 	 */
 	ASSERT_EQ(0, fcntl(recv_socket, F_SETOWN, child));
+	ASSERT_EQ(0, fcntl(recv_socket, F_SETSIG, SIGURG));
+	ASSERT_EQ(0, fcntl(recv_socket, F_SETFL, O_ASYNC));
 
 	if (variant->sandbox_setown == SANDBOX_AFTER_SETOWN)
 		create_scoped_domain(_metadata, LANDLOCK_SCOPE_SIGNAL);
 
 	ASSERT_EQ(1, write(pipe_parent[1], ".", 1));
 
-	/* Waits for the child to send MSG_OOB. */
+	/* Waits for the child to send data. */
 	ASSERT_EQ(1, read(pipe_child[0], &buffer_parent, 1));
 	EXPECT_EQ(0, close(pipe_child[0]));
-	ASSERT_EQ(1, recv(recv_socket, &buffer_parent, 1, MSG_OOB));
+	ASSERT_EQ(1, recv(recv_socket, &buffer_parent, 1, 0));
 	EXPECT_EQ(0, close(recv_socket));
 	EXPECT_EQ(0, close(server_socket));
 	ASSERT_EQ(1, write(pipe_parent[1], ".", 1));
@@ -1085,11 +1066,15 @@ TEST_F(trace_fown, deny_scope_fown)
 		 */
 		ASSERT_EQ(1, read(pipe_parent[0], &buffer_child, 1));
 		/* Triggers the asynchronous SIGURG to this file owner. */
-		ASSERT_EQ(1, send(client_socket, ".", 1, MSG_OOB));
-		EXPECT_EQ(0, close(client_socket));
+		ASSERT_EQ(1, send(client_socket, ".", 1, 0));
 		ASSERT_EQ(1, write(pipe_child[1], ".", 1));
 		EXPECT_EQ(0, close(pipe_child[1]));
 
+		/* Waits for the message to be received. */
+		ASSERT_EQ(1, read(pipe_parent[0], &buffer_child, 1));
+		EXPECT_EQ(0, close(pipe_parent[0]));
+		EXPECT_EQ(0, close(client_socket));
+
 		_exit(0);
 		return;
 	}
@@ -1114,19 +1099,23 @@ TEST_F(trace_fown, deny_scope_fown)
 		create_scoped_domain(_metadata, LANDLOCK_SCOPE_SIGNAL);
 
 	/*
-	 * Sets the child to receive SIGURG for MSG_OOB.  This uncommon use is a
+	 * Sets the child to receive SIGURG.  This uncommon use is a
 	 * valid attack scenario which also simplifies this test.
 	 */
 	ASSERT_EQ(0, fcntl(recv_socket, F_SETOWN, child));
+	ASSERT_EQ(0, fcntl(recv_socket, F_SETSIG, SIGURG));
+	ASSERT_EQ(0, fcntl(recv_socket, F_SETFL, O_ASYNC));
 
 	ASSERT_EQ(1, write(pipe_parent[1], ".", 1));
 
-	/* Waits for the child to send MSG_OOB. */
+	/* Waits for the child to send data. */
 	ASSERT_EQ(1, read(pipe_child[0], &buffer_parent, 1));
 	EXPECT_EQ(0, close(pipe_child[0]));
-	ASSERT_EQ(1, recv(recv_socket, &buffer_parent, 1, MSG_OOB));
+	ASSERT_EQ(1, recv(recv_socket, &buffer_parent, 1, 0));
 	EXPECT_EQ(0, close(recv_socket));
 	EXPECT_EQ(0, close(server_socket));
+	ASSERT_EQ(1, write(pipe_parent[1], ".", 1));
+	EXPECT_EQ(0, close(pipe_parent[1]));
 
 	ASSERT_EQ(child, waitpid(child, &status, 0));
 	ASSERT_TRUE(WIFEXITED(status));
-- 
2.56.0.611.g1030f0b940-goog


  reply	other threads:[~2026-11-16  2:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  2:18 [PATCH v1 net-next 0/4] af_unix: Drop MSG_OOB support Kuniyuki Iwashima
2026-11-16  2:18 ` Kuniyuki Iwashima [this message]
2026-11-17  2:19   ` [PATCH v1 net-next 1/4] selftests: landlock: Replace MSG_OOB with O_ASYNC+F_SETSIG sashiko-bot
2026-11-17 17:19   ` netdev-bot+sashiko
2026-11-18  1:37     ` Kuniyuki Iwashima
2026-11-16  2:18 ` [PATCH v1 net-next 2/4] selftests: bpf: sockmap: Remove AF_UNIX MSG_OOB test case Kuniyuki Iwashima
2026-11-17 17:19   ` netdev-bot+sashiko
2026-11-18  1:43     ` Kuniyuki Iwashima
2026-11-18  2:23   ` Jiayuan Chen
2026-11-16  2:18 ` [PATCH v1 net-next 3/4] selftests: af_unix: Remove MSG_OOB tests Kuniyuki Iwashima
2026-11-16  2:18 ` [PATCH v1 net-next 4/4] af_unix: Remove MSG_OOB Kuniyuki Iwashima
2026-11-17 17:19   ` netdev-bot+sashiko
2026-11-18  1:46     ` Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116021845.2533130-2-kuniyu@google.com \
    --to=kuniyu@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gnoack@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mic@digikod.net \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.