Skip to contentSkip to conversation

Improvements to port on various error conditions

PATCH New Glenn Washburn 1 participant 5 messages Mar 3, 2022 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

cover Improvements to port on various error conditions

This patch series was inspired by the various issues I ran into while trying login to a UML instance via telnet when using the ssl=port:XXXX option. The issue was that I started the UML instance with option "ssl1=port:12345" and when I tried to connect from the host using telnet, the telnet client connects and immediately the connection is closed. In the UML instance, the only message I was getting was a kernel log message "port_accept : port_connection returned 2". I had to dig in the kernel source to figure out what the "2" meant, which gave a clue as to what was going on.

The issue was that I didn't have in.telnetd installed and the "2" was the error code from exec, which is ENOENT, or "No such file or directory". Patch #4 provides a more user friendly error on exec failure, which should prevent users from needing to dig in the source to figure out what's going wrong.

The first patch allows exec to search for in.telnetd instead of having its path hard coded, which may be different on different systems. It also allows for the UML instance to be telneted into when the user is unprivileged and the host does not have in.telnetd installed. The user can install in.telnetd in to any path they can write to and set PATH accordingly. This is my actual use case.

The second patch allows the user to specify the location of the port-helper binary via the environment variable UML_PORT_HELPER. The use cause is the same as above. If the envvar is not set, fallback to the hardcoded path to port-helper.

The third patch checks if the port-helper path actually exists and is executable. This allows the UML instance to check and fail early if port-helper can't be run and to send and error message to the user via the kernel log letting the user know the issue and potentially how to fix it (eg. set the UML_PORT_HELPER envvar).

Glenn

Glenn Washburn (4):
um: port_user: Search for in.telnetd in PATH
um: port_user: Allow setting path to port-helper using UML_PORT_HELPER
envvar
um: port_user: Improve error handling when port-helper is not found
um: run_helper: Write error message to kernel log on exec failure on
host

 arch/um/drivers/port_user.c | 18 +++++++++++++++++-
 arch/um/os-Linux/helper.c   |  5 +++++
 2 files changed, 22 insertions(+), 1 deletion(-)
Signature · 7 lines
2.30.2


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#1 lore raw

PATCH 1/4 um: port_user: Search for in.telnetd in PATH

This allows in.telnetd to be run from non-standard installation locations and is especially useful when running a UML instance as an unprivileged user on a system where the administrator has not installed the in.telnetd binary.

---
 arch/um/drivers/port_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/um/drivers/port_user.c +1 -1
index 5b5b64cb1071..0625aa42041d 100644
@@ -167,7 +167,7 @@ static void port_pre_exec(void *arg)
 int port_connection(int fd, int *socket, int *pid_out)
 {
 	int new, err;
-	char *argv[] = { "/usr/sbin/in.telnetd", "-L",
+	char *argv[] = { "in.telnetd", "-L",
 			 OS_LIB_PATH "/uml/port-helper", NULL };
 	struct port_pre_exec_data data;
 
Signature · 7 lines
2.30.2


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#2 lore raw

PATCH 2/4 um: port_user: Allow setting path to port-helper using UML_PORT_HELPER envvar

In reply to Glenn Washburn

This is useful when the uml-utilities user-space package has not been installed by the administrator and an unprivileged user wants to be able to telnet into a UML instance. The user can install the port-helper binary to a writable path and set UML_PORT_HELPER. Fallback to using hardcoded path to port-helper if environment variable is not set.

---
 arch/um/drivers/port_user.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/um/drivers/port_user.c +4 -0
index 0625aa42041d..3e32351dadad 100644
@@ -167,10 +167,14 @@ static void port_pre_exec(void *arg)
 int port_connection(int fd, int *socket, int *pid_out)
 {
 	int new, err;
+	char *env;
 	char *argv[] = { "in.telnetd", "-L",
 			 OS_LIB_PATH "/uml/port-helper", NULL };
 	struct port_pre_exec_data data;
 
+	if ((env = getenv("UML_PORT_HELPER")))
+		argv[2] = env;
+
 	new = accept(fd, NULL, 0);
 	if (new < 0)
 		return -errno;
Signature · 7 lines
2.30.2


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#3 lore raw

PATCH 3/4 um: port_user: Improve error handling when port-helper is not found

In reply to Glenn Washburn

Check if port-helper exists and is executable. If not, write an error message to the kernel log with information to help the user diagnose the issue and exit with an error. If UML_PORT_HELPER was not set, write a message suggesting that the user set it. This makes it easier to understand why telneting to the UML instance is failing and what can be done to fix it.

---
 arch/um/drivers/port_user.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/um/drivers/port_user.c +12 -0
index 3e32351dadad..3c62ae81df62 100644
@@ -5,6 +5,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 #include <termios.h>
 #include <unistd.h>
@@ -179,6 +180,17 @@ int port_connection(int fd, int *socket, int *pid_out)
 	if (new < 0)
 		return -errno;
 
+	err = os_access(argv[2], X_OK);
+	if (err < 0) {
+		printk(UM_KERN_ERR "port_connection : error accessing port-helper "
+		       "executable at %s: %s\n", argv[2], strerror(-err));
+		if (env == NULL)
+			printk(UM_KERN_ERR "Set UML_PORT_HELPER environment "
+				"variable to path to uml-utilities port-helper "
+				"binary\n");
+		goto out_close;
+	}
+
 	err = os_pipe(socket, 0, 0);
 	if (err < 0)
 		goto out_close;
Signature · 7 lines
2.30.2


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#4 lore raw

PATCH 4/4 um: run_helper: Write error message to kernel log on exec failure on host

In reply to Glenn Washburn

The best place to log errors from the host side is in the kernel log within the UML guest. Letting the user now that exec() failed and why is very helpful when the user is trying to determine why some aspect of UML is not working. For instance, when telneting into the UML instance, if the connection is established and then immediately dropped, this may be due to exec() failing because in.telnetd is not found.

---
 arch/um/os-Linux/helper.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/um/os-Linux/helper.c +5 -0
index 32e88baf18dd..b459745f52e2 100644
@@ -4,6 +4,7 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <errno.h>
 #include <sched.h>
@@ -99,6 +100,10 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
 		CATCH_EINTR(waitpid(pid, NULL, __WALL));
 	}
 
+	if (ret < 0)
+		printk(UM_KERN_ERR "run_helper : failed to exec %s on host: %s\n",
+		       argv[0], strerror(-ret));
+
 out_free2:
 	kfree(data.buf);
 out_close:
Signature · 7 lines
2.30.2


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um