All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Improvements to port on various error conditions
@ 2022-03-03  7:53 Glenn Washburn
  2022-03-03  7:53 ` [PATCH 1/4] um: port_user: Search for in.telnetd in PATH Glenn Washburn
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Glenn Washburn @ 2022-03-03  7:53 UTC (permalink / raw)
  To: linux-um; +Cc: Glenn Washburn

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(-)

-- 
2.30.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] um: port_user: Search for in.telnetd in PATH
  2022-03-03  7:53 [PATCH 0/4] Improvements to port on various error conditions Glenn Washburn
@ 2022-03-03  7:53 ` Glenn Washburn
  2022-03-03  7:53 ` [PATCH 2/4] um: port_user: Allow setting path to port-helper using UML_PORT_HELPER envvar Glenn Washburn
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Glenn Washburn @ 2022-03-03  7:53 UTC (permalink / raw)
  To: linux-um; +Cc: Glenn Washburn

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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 arch/um/drivers/port_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/um/drivers/port_user.c b/arch/um/drivers/port_user.c
index 5b5b64cb1071..0625aa42041d 100644
--- a/arch/um/drivers/port_user.c
+++ b/arch/um/drivers/port_user.c
@@ -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;
 
-- 
2.30.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] um: port_user: Allow setting path to port-helper using UML_PORT_HELPER envvar
  2022-03-03  7:53 [PATCH 0/4] Improvements to port on various error conditions Glenn Washburn
  2022-03-03  7:53 ` [PATCH 1/4] um: port_user: Search for in.telnetd in PATH Glenn Washburn
@ 2022-03-03  7:53 ` Glenn Washburn
  2022-03-03  7:53 ` [PATCH 3/4] um: port_user: Improve error handling when port-helper is not found Glenn Washburn
  2022-03-03  7:53 ` [PATCH 4/4] um: run_helper: Write error message to kernel log on exec failure on host Glenn Washburn
  3 siblings, 0 replies; 5+ messages in thread
From: Glenn Washburn @ 2022-03-03  7:53 UTC (permalink / raw)
  To: linux-um; +Cc: 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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 arch/um/drivers/port_user.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/um/drivers/port_user.c b/arch/um/drivers/port_user.c
index 0625aa42041d..3e32351dadad 100644
--- a/arch/um/drivers/port_user.c
+++ b/arch/um/drivers/port_user.c
@@ -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;
-- 
2.30.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] um: port_user: Improve error handling when port-helper is not found
  2022-03-03  7:53 [PATCH 0/4] Improvements to port on various error conditions Glenn Washburn
  2022-03-03  7:53 ` [PATCH 1/4] um: port_user: Search for in.telnetd in PATH Glenn Washburn
  2022-03-03  7:53 ` [PATCH 2/4] um: port_user: Allow setting path to port-helper using UML_PORT_HELPER envvar Glenn Washburn
@ 2022-03-03  7:53 ` Glenn Washburn
  2022-03-03  7:53 ` [PATCH 4/4] um: run_helper: Write error message to kernel log on exec failure on host Glenn Washburn
  3 siblings, 0 replies; 5+ messages in thread
From: Glenn Washburn @ 2022-03-03  7:53 UTC (permalink / raw)
  To: linux-um; +Cc: 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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 arch/um/drivers/port_user.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/um/drivers/port_user.c b/arch/um/drivers/port_user.c
index 3e32351dadad..3c62ae81df62 100644
--- a/arch/um/drivers/port_user.c
+++ b/arch/um/drivers/port_user.c
@@ -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;
-- 
2.30.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] um: run_helper: Write error message to kernel log on exec failure on host
  2022-03-03  7:53 [PATCH 0/4] Improvements to port on various error conditions Glenn Washburn
                   ` (2 preceding siblings ...)
  2022-03-03  7:53 ` [PATCH 3/4] um: port_user: Improve error handling when port-helper is not found Glenn Washburn
@ 2022-03-03  7:53 ` Glenn Washburn
  3 siblings, 0 replies; 5+ messages in thread
From: Glenn Washburn @ 2022-03-03  7:53 UTC (permalink / raw)
  To: linux-um; +Cc: 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.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 arch/um/os-Linux/helper.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/um/os-Linux/helper.c b/arch/um/os-Linux/helper.c
index 32e88baf18dd..b459745f52e2 100644
--- a/arch/um/os-Linux/helper.c
+++ b/arch/um/os-Linux/helper.c
@@ -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:
-- 
2.30.2


_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-03  7:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-03  7:53 [PATCH 0/4] Improvements to port on various error conditions Glenn Washburn
2022-03-03  7:53 ` [PATCH 1/4] um: port_user: Search for in.telnetd in PATH Glenn Washburn
2022-03-03  7:53 ` [PATCH 2/4] um: port_user: Allow setting path to port-helper using UML_PORT_HELPER envvar Glenn Washburn
2022-03-03  7:53 ` [PATCH 3/4] um: port_user: Improve error handling when port-helper is not found Glenn Washburn
2022-03-03  7:53 ` [PATCH 4/4] um: run_helper: Write error message to kernel log on exec failure on host Glenn Washburn

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.