Skip to contentSkip to conversation

selinux-testsuite: fix unix/inet socket tests

PATCH Superseded Stephen Smalley 1 participant 1 message Jun 23, 2015 SELinux security module

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selinux-testsuite: fix unix/inet socket tests

There was a bug in the unix and inet socket tests:
the server program would exit as soon as it finished responding to the legitimate client, so the unauthorized client tests were "succeeding" due to the server socket not even existing rather than a permission denial. Fix the server to stay around until it is explicitly killed by the test scripts. This fix then revealed a problem with the last inet_socket test: although the permission denial correctly prevents the server from receiving the datagram message, the client gets no notification of this failure and hangs on its subsequent attempt to read a reply from the server. Add a call to poll() with a timeout so that the client can handle this situation.

---
v2 fixes the last test by adding a call to poll() to the client rather than removing the test. This enables the test to pass but does make it dependent on timing; the authorized client could fail the test if the server does not reply within the specified timeout on a loaded system.

 tests/inet_socket/client.c |  19 +++++++
 tests/inet_socket/server.c | 134 +++++++++++++++++++++++----------------------
 tests/unix_socket/server.c | 132 ++++++++++++++++++++++----------------------
 3 files changed, 156 insertions(+), 129 deletions(-)
tests/inet_socket/client.c +19 -0
index ffc154c..a0273af 100644
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <poll.h>
 #include <selinux/selinux.h>
 
 void usage(char *progname)
@@ -76,6 +77,24 @@ main(int argc, char **argv)
 		close(sock);
 		exit(1);
 	}
+
+	if (type == SOCK_DGRAM) {
+		struct pollfd fds;
+		struct timespec timeout;
+
+		fds.fd = sock;
+		fds.events = POLLIN;
+		result = poll(&fds, 1, 1000);
+		if (result < 0) {
+			perror("poll");
+			close(sock);
+			exit(1);
+		} else if (result == 0) {
+			fprintf(stderr, "%s: no reply from server\n", argv[0]);
+			exit(1);
+		}
+	}
+
 	result = read(sock, label, sizeof(label));
 	if (result < 0) {
 		perror("read");
tests/inet_socket/server.c +69 -65

158 lines not on this page · raw message

tests/unix_socket/server.c +68 -64

156 lines not on this page · raw message

Signature · 1 line
2.1.0