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: <20250217-kunit-kselftests-v1-12-42b4524c3b0a@linutronix.de>
Date: Mon, 17 Feb 2025 11:59:32 +0100
From: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
To: Masahiro Yamada <masahiroy@...nel.org>, 
 Nathan Chancellor <nathan@...nel.org>, Nicolas Schier <nicolas@...sle.eu>, 
 Andrew Morton <akpm@...ux-foundation.org>, Willy Tarreau <w@....eu>, 
 Thomas Weißschuh <linux@...ssschuh.net>, 
 Brendan Higgins <brendan.higgins@...ux.dev>, 
 David Gow <davidgow@...gle.com>, Rae Moar <rmoar@...gle.com>, 
 Shuah Khan <shuah@...nel.org>, Jonathan Corbet <corbet@....net>
Cc: linux-kbuild@...r.kernel.org, linux-kernel@...r.kernel.org, 
 linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com, 
 linux-doc@...r.kernel.org, 
 Thomas Weißschuh <thomas.weissschuh@...utronix.de>
Subject: [PATCH 12/12] kunit: uapi: Validate usability of /proc

Show that the selftests are executed from a fairly "normal"
userspace context.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
---
 lib/kunit/kunit-uapi-example.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/lib/kunit/kunit-uapi-example.c b/lib/kunit/kunit-uapi-example.c
index 4ec4b924f29b089cce9ca5b2b08a6ee0117b8ae9..f7376e524b4c76a9c6d474e6ace80a8e2517b84b 100644
--- a/lib/kunit/kunit-uapi-example.c
+++ b/lib/kunit/kunit-uapi-example.c
@@ -6,13 +6,51 @@
  * Author: Thomas Weißschuh <thomas.weissschuh@...utronix.de>
  */
 
+#ifndef NOLIBC
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#endif
+
 #include "../../tools/testing/selftests/kselftest.h"
 
+static void test_procfs(void)
+{
+	char buf[256];
+	ssize_t r;
+	int fd;
+
+	fd = open("/proc/self/comm", O_RDONLY);
+	if (fd == -1) {
+		ksft_test_result_fail("procfs: open() failed: %s\n", strerror(errno));
+		return;
+	}
+
+	r = read(fd, buf, sizeof(buf));
+	if (r == -1) {
+		close(fd);
+		ksft_test_result_fail("procfs: read() failed: %s\n", strerror(errno));
+		return;
+	}
+
+	close(fd);
+
+	if (r > 0 && buf[r - 1] == '\n')
+		buf[r - 1] = '\0';
+
+	if (strncmp("kunit-uapi-exam", buf, sizeof(buf)) != 0) {
+		ksft_test_result_fail("procfs: incorrect comm: %s\n", buf);
+		return;
+	}
+
+	ksft_test_result_pass("procfs\n");
+}
+
 int main(void)
 {
 	ksft_print_header();
 	ksft_set_plan(4);
-	ksft_test_result_pass("userspace test 1\n");
+	test_procfs();
 	ksft_test_result_pass("userspace test 2\n");
 	ksft_test_result_skip("userspace test 3: some reason\n");
 	ksft_test_result_pass("userspace test 4\n");

-- 
2.48.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ