lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250912195339.20635-12-yana2bsh@gmail.com>
Date: Fri, 12 Sep 2025 22:53:34 +0300
From: Yana Bashlykova <yana2bsh@...il.com>
To: "David S. Miller" <davem@...emloft.net>
Cc: Yana Bashlykova <yana2bsh@...il.com>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	Shuah Khan <shuah@...nel.org>,
	netdev@...r.kernel.org,
	linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	lvc-project@...uxtesting.org
Subject: [PATCH 6.1 11/15] selftests: net: genetlink: add /proc/net/netlink test

Add test case to verify proper handling of Netlink sockets in procfs:

- Tests /proc/net/netlink file accessibility
- Validates socket count changes on creation/deletion
- Uses kernel's netlink_seq_ops mechanism

Checks that socket entries are correctly added/removed from procfs.

Signed-off-by: Yana Bashlykova <yana2bsh@...il.com>
---
 tools/testing/selftests/net/genetlink.c | 74 +++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/tools/testing/selftests/net/genetlink.c b/tools/testing/selftests/net/genetlink.c
index 5be9ca68accd..f8231a302c36 100644
--- a/tools/testing/selftests/net/genetlink.c
+++ b/tools/testing/selftests/net/genetlink.c
@@ -81,6 +81,25 @@
 
 #define LARGE_GENL_FAMILY_NAME "LARGE_GENL"
 
+struct nl_sock *socket_alloc_and_conn(void)
+{
+	struct nl_sock *socket;
+
+	socket = nl_socket_alloc();
+	if (!socket) {
+		fprintf(stderr, "Failed to allocate socket\n");
+		return NULL;
+	}
+
+	if (genl_connect(socket)) {
+		fprintf(stderr,
+			"Failed to connect to generic netlink through socket\n");
+		nl_socket_free(socket);
+		return NULL;
+	}
+	return socket;
+}
+
 /*
  * Test cases
  */
@@ -143,6 +162,61 @@ TEST(capture_start)
 	printf("Starting Netlink tests...\n");
 }
 
+/**
+ * TEST(open_netlink_file) - Verifies correct reading of Netlink socket information
+ *
+ * Tests the /proc/net/netlink interface by:
+ * 1. Creating a test Netlink socket
+ * 2. Reading the proc file before and after socket creation
+ * 3. Verifying the socket count changes as expected
+ *
+ * The test checks that:
+ * - /proc/net/netlink is accessible
+ * - Entries are properly added/removed
+ * - Uses kernel's netlink_seq_ops mechanism
+ */
+
+TEST(open_netlink_file)
+{
+	FILE *file;
+	char line[256];
+	int cnt = 0;
+
+	printf("Running Test: opening and reading /proc/net/netlink file...\n");
+
+	struct nl_sock *sock;
+
+	sock = socket_alloc_and_conn();
+
+	file = fopen("/proc/net/netlink", "r");
+	ASSERT_NE(NULL, file);
+	if (file == NULL) {
+		perror("fopen");
+		return;
+	}
+
+	while (fgets(line, sizeof(line), file) != NULL)
+		cnt++;
+
+	nl_socket_free(sock);
+
+	fclose(file);
+
+	file = fopen("/proc/net/netlink", "r");
+	ASSERT_NE(NULL, file);
+	if (file == NULL) {
+		perror("fopen");
+		return;
+	}
+
+	while (fgets(line, sizeof(line), file) != NULL)
+		cnt--;
+
+	EXPECT_EQ(cnt, 1);
+
+	fclose(file);
+}
+
 /**
  * TEST(capture_end) - Terminates Netlink traffic monitoring session
  *
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ