Skip to contentSkip to conversation

Secure login and sulogin on S390x

PATCH In review Werner Fink 3 participants 6 messages Apr 29 – May 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Secure login and sulogin on S390x

Some remarks: on S390x architecture of modern zSeries the hypervisor does log the console I/O. For both the 3215 half duplex line mode as well as the 3270 full-screen/block mode console type the I/O is logged on the hypervisor's side. To control this there are command send via /dev/vmcp to tell the z/VM control program of the hypervisor not to log during entering the password. For the 3215 console also automatic scroll is enabled which avoid to press CLEAR to get the password prompt if on the next block.

Beside this for the ttysclp0, the serial ASCII terminal accessed via a websocket has since ncurses 6.5-20250405 a new terminfo entry called "sclp" to support not only the vt220 like behaviour but also the colouring feature of ttysclp0.

---
 lib/ttyutils.c                 |   5 +-
 login-utils/Makemodule.am      |   6 +-
 login-utils/login.c            |  85 +++++++++++-
 login-utils/meson.build        |   5 +
 login-utils/sulogin-consoles.c |  14 ++
 login-utils/sulogin-consoles.h |   4 +
 login-utils/sulogin.c          |  64 +++++++--
 login-utils/vmcp.c             | 236 +++++++++++++++++++++++++++++++++
 login-utils/vmcp.h             |  29 ++++
 9 files changed, 436 insertions(+), 12 deletions(-)
 create mode 100644 login-utils/vmcp.c
 create mode 100644 login-utils/vmcp.h
lib/ttyutils.c +3 -2
index bacd73077..3085419bd 100644
@@ -21,7 +21,7 @@
 #  if defined (__s390__) || defined (__s390x__)
 #    define DEFAULT_TTYS0  "dumb"
 #    define DEFAULT_TTY32  "ibm327x"
-#    define DEFAULT_TTYS1  "vt220"
+#    define DEFAULT_TTYS1  "sclp"
 #  endif
 #  ifndef DEFAULT_STERM
 #    define DEFAULT_STERM  "vt102"
@@ -176,7 +176,8 @@ char *get_terminal_default_type(const char *ttyname, int is_serial)
 		 * Special terminal on first serial line on a S/390(x) which
 		 * is due legacy reasons a block terminal of type 3270 or
 		 * higher.  Whereas the second serial line on a S/390(x) is
-		 * a real character terminal which is compatible with VT220.
+		 * a real character terminal which is compatible with "sclp"
+		 * since ncurses 6.5-20250405 for e.g. color support.
 		 */
 		if (strcmp(ttyname, "ttyS0") == 0)		/* linux/drivers/s390/char/con3215.c */
 			return strdup(DEFAULT_TTYS0);
login-utils/Makemodule.am +5 -1
index d288a06c3..599547f7b 100644
@@ -33,7 +33,9 @@ dist_noinst_DATA += login-utils/sulogin.8.adoc
 sulogin_SOURCES = \
 	login-utils/sulogin.c \
 	login-utils/sulogin-consoles.c \
-	login-utils/sulogin-consoles.h
+	login-utils/sulogin-consoles.h \
+	login-utils/vmcp.c \
+	login-utils/vmcp.h
 if USE_PLYMOUTH_SUPPORT
 sulogin_SOURCES += lib/plymouth-ctrl.c
 endif
@@ -59,6 +61,8 @@ MANPAGES += login-utils/login.1
 dist_noinst_DATA += login-utils/login.1.adoc
 login_SOURCES = \
 	login-utils/login.c \
+	login-utils/vmcp.c \
+	login-utils/vmcp.h \
 	lib/logindefs.c
 login_LDADD = $(LDADD) libcommon.la -lpam
 if HAVE_LINUXPAM
login-utils/login.c +84 -1

104 lines not on this page · raw message

login-utils/meson.build +5 -0
index 251d8de46..5f6310b01 100644
@@ -49,6 +49,7 @@ test_islocal_sources = files(
 
 test_consoles_sources = files(
   'sulogin-consoles.c',
+  'vmcp.c',
 )
 
 last_sources = files(
@@ -59,6 +60,8 @@ last_manadocs = files('last.1.adoc')
 
 login_sources = files(
   'login.c',
+  'vmcp.c',
+  'vmcp.h',
 )
 login_manadocs = files('login.1.adoc')
 
@@ -66,6 +69,8 @@ sulogin_sources = files(
   'sulogin.c',
   'sulogin-consoles.c',
   'sulogin-consoles.h',
+  'vmcp.c',
+  'vmcp.h',
 )
 sulogin_manadocs = files('sulogin.8.adoc')
 
login-utils/sulogin-consoles.c +14 -0
index c35922ff1..f09d90ece 100644
@@ -389,6 +389,20 @@ static int detect_consoles_from_proc(struct list_head *consoles)
 		free(name);
 		if (rc < 0)
 			goto done;
+		if (!list_empty(consoles)) {
+			struct console *last;
+			last = list_last_entry(consoles, struct console, entry);
+			if (!strchr(fbuf, 'C'))
+				last->flags |= CON_CONSDEV;
+#if defined(__s390__) || defined(__s390x__)
+			if (maj == 4 && min == 64)
+				last->flags |= CON_3215;
+			if (maj == 4 && min >= 65)
+				last->flags |= CON_SCLP;
+			else if (maj == 227 && min >= 1)
+				last->flags |= CON_3270;
+#endif
+		}
 	}
 
 	rc = list_empty(consoles) ? 1 : 0;
login-utils/sulogin-consoles.h +4 -0
index d3b4298e4..10fdf612c 100644
@@ -39,6 +39,10 @@ struct console {
 #define	CON_SERIAL	0x0001
 #define	CON_NOTTY	0x0002
 #define	CON_EIO		0x0004
+#define	CON_CONSDEV	0x0008	/* Last on the kernel command line */
+#define	CON_3215	0x0010	/* s390x 3215 halfduplex console */
+#define	CON_3270	0x0020  /* s390x 3270 console */
+#define	CON_SCLP	0x0040	/* s390x sclp terminals */
 	pid_t pid;
 	struct chardata cp;
 	struct termios tio;
login-utils/sulogin.c +56 -8

115 lines not on this page · raw message

login-utils/vmcp.c new file +236 -0

236 lines not on this page · raw message

login-utils/vmcp.h new file +29 -0
new file mode 100644
index 000000000..50ef1ba90
@@ -0,0 +1,29 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * vmcp.c - s390x 3215 console spool and terminal management
+ *
+ * Copyright 2026 Werner Fink, SUSE Software Solutions Germany GmbH
+ *
+ * Based on:
+ *
+ * Copyright IBM Corp. 2018
+ * s390-tools is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ *
+ */
+
+extern int isinteger(const char *str);
+#if defined(__s390__) || defined(__s390x__)
+extern int openvmcp(void);
+extern void clearvmcp(void);
+extern char* queryterm(int fd);
+extern char* queryspool(int fd);
+extern int setterm(int fd, char *tout);
+extern int stopspool(int fd);
+extern int restoreterm(int fd);
+extern int restorespool(int fd);
+extern void parseterm(char *msg);
+extern void parsespool(char *msg);
+extern void warning3215(int fd);
+#endif
Signature · 1 line
2.51.0
#1 lore raw

Hi,

just to extend the last patch with a further one ro catch all corner cases as well.

Werner

Signature · 2 lines
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr

From a6c23b4d8ad84fff4a58855b76b56a261ff8aa5e Mon Sep 17 00:00:00 2001
From: Werner Fink <[email protected]>
Date: Mon, 4 May 2026 13:20:13 +0200
Subject: [PATCH] Ensure to detect all special console case on S390x

---
 login-utils/sulogin-consoles.c | 46 ++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 16 deletions(-)
login-utils/sulogin-consoles.c +30 -16
index f09d90ece..4cce4f078 100644
@@ -312,7 +312,7 @@ static
 #ifdef __GNUC__
 __attribute__((__hot__))
 #endif
-int append_console(struct list_head *consoles, const char * const name)
+int append_console(struct list_head *consoles, const char * const name, dev_t dev)
 {
 	struct console *restrict tail;
 	const struct console *last = NULL;
@@ -343,7 +343,29 @@ int append_console(struct list_head *consoles, const char * const name)
 	tail->reset_tty_context = NULL;
 	tail->user_tty_context = NULL;
 #endif
-
+#if defined(__s390__) || defined(__s390x__)
+	/*
+	 * Stat the device path to determine its major/minor numbers. 
+	 * This ensures we detect s390x terminal types regardless of whether 
+	 * the console was found via /proc, /sys, cmdline, or a direct stdin 
+	 * fallback (e.g. sulogin < /dev/ttyS0).
+	 */
+	if (!dev) {
+		struct stat st;
+		if (stat(name, &st) == 0 && S_ISCHR(st.st_mode))
+			dev = st.st_rdev;
+	}
+	if (dev) {
+		unsigned int maj = major(dev);
+		unsigned int min = minor(dev);
+		if (maj == 4 && min == 64)
+			tail->flags |= CON_3215;
+		else if (maj == 4 && min >= 65)
+			tail->flags |= CON_SCLP;
+		else if (maj == 227 && min >= 1)
+			tail->flags |= CON_3270;
+	}
+#endif
 	return 0;
 }
 
@@ -385,7 +407,7 @@ static int detect_consoles_from_proc(struct list_head *consoles)
 		name = scandev(dir, comparedev);
 		if (!name)
 			continue;
-		rc = append_console(consoles, name);
+		rc = append_console(consoles, name, comparedev);
 		free(name);
 		if (rc < 0)
 			goto done;
@@ -394,14 +416,6 @@ static int detect_consoles_from_proc(struct list_head *consoles)
 			last = list_last_entry(consoles, struct console, entry);
 			if (!strchr(fbuf, 'C'))
 				last->flags |= CON_CONSDEV;
-#if defined(__s390__) || defined(__s390x__)
-			if (maj == 4 && min == 64)
-				last->flags |= CON_3215;
-			if (maj == 4 && min >= 65)
-				last->flags |= CON_SCLP;
-			else if (maj == 227 && min >= 1)
-				last->flags |= CON_3270;
-#endif
 		}
 	}
 
@@ -461,7 +475,7 @@ static int detect_consoles_from_sysfs(struct list_head *consoles)
 		name = scandev(dir, comparedev);
 		if (!name)
 			continue;
-		rc = append_console(consoles, name);
+		rc = append_console(consoles, name, comparedev);
 		free(name);
 		if (rc < 0)
 			goto done;
@@ -549,7 +563,7 @@ static int detect_consoles_from_cmdline(struct list_head *consoles)
 		name = scandev(dir, comparedev);
 		if (!name)
 			continue;
-		rc = append_console(consoles, name);
+		rc = append_console(consoles, name, comparedev);
 		free(name);
 		if (rc < 0)
 			goto done;
@@ -607,7 +621,7 @@ static int detect_consoles_from_tiocgdev(struct list_head *consoles,
 			goto done;
 		}
 	}
-	rc = append_console(consoles, name);
+	rc = append_console(consoles, name, comparedev);
 	free(name);
 	if (rc < 0)
 		goto done;
@@ -721,7 +735,7 @@ int detect_consoles(const char *device, const int fallback, struct list_head *co
 		closedir(dir);
 
 		if (name) {
-			rc = append_console(consoles, name);
+			rc = append_console(consoles, name, comparedev);
 			free(name);
 			if (rc < 0)
 				return rc;
@@ -798,7 +812,7 @@ fallback:
 		n = strdup(name);
 		if (!n)
 			return -ENOMEM;
-		rc = append_console(consoles, n);
+		rc = append_console(consoles, n, 0);
 		free(n);
 		if (rc < 0)
 			return rc;
Signature · 1 line
2.51.0
#2 lore raw
In reply to Werner Fink
Quoted 8 lines · Werner Fink

Some remarks: on S390x architecture of modern zSeries the hypervisor does log the console I/O. For both the 3215 half duplex line mode as well as the 3270 full-screen/block mode console type the I/O is logged on the hypervisor's side. To control this there are command send via /dev/vmcp to tell the z/VM control program of the hypervisor not to log during entering the password. For the 3215 console also automatic scroll is enabled which avoid to press CLEAR to get the password prompt if on the next block.

[..]

Quoted 1 line
9 files changed, 436 insertions(+), 12 deletions(-)

This seems to add a lot of code to util-linux. I was wondering if sulogin is the only place that needs this log filtering. What about su, sudo, doas and so on? Note that there are different su (and probably doas) versions in use across distributions.

Wouldn't it be better if the hypervisor would not log input if the terminal output was disabled? That seems like behaviour commonly found in other virtual terminal emulators.

Best,
Chris

#3 lore raw
Quoted 18 lines · Chris Hofstaedtler
Quoted 8 lines · Werner Fink

Some remarks: on S390x architecture of modern zSeries the hypervisor does log the console I/O. For both the 3215 half duplex line mode as well as the 3270 full-screen/block mode console type the I/O is logged on the hypervisor's side. To control this there are command send via /dev/vmcp to tell the z/VM control program of the hypervisor not to log during entering the password. For the 3215 console also automatic scroll is enabled which avoid to press CLEAR to get the password prompt if on the next block.

[..]

Quoted 1 line
9 files changed, 436 insertions(+), 12 deletions(-)

This seems to add a lot of code to util-linux. I was wondering if sulogin is the only place that needs this log filtering. What about su, sudo, doas and so on? Note that there are different su (and probably doas) versions in use across distributions.

Quoted 6 lines

Wouldn't it be better if the hypervisor would not log input if the terminal output was disabled? That seems like behaviour commonly found in other virtual terminal emulators.

Best,
Chris

Maybe other hypervisors have the same behaviour. Nevertheless the 3215 console is half duplex printer like a punchcard based teletypewriter running within the hypervisor of an zSystem firmware. Means every zOS and Linux instances are VMs on such zSystem. The 3270 console type is a bit better as it understands escape sequences and is a block mode console type, but still you have primitiv local prompt within the hypervisor and not on
the linux side its self. You can compare this with qemu within virt-manager,
but AFAIK qemu does not log keystrokes.

The vmcp.c is a copy of the version I use for my blogd in the showconsole project at https://github.com/bitstreamout/showconsole

Werner

Signature · 2 lines
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr
#4 lore raw

Repost: [PATCH] Secure login and sulogin on S390x

Hi,

just to be sure that this change for s390x does not fall down behind. Are there some changes required?

Werner

Signature · 2 lines
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr

From e307759459f58a5d36d879bdf838e8319580a7bd Mon Sep 17 00:00:00 2001
From: Werner Fink <[email protected]>
Date: Thu, 21 May 2026 10:46:13 +0200
Subject: [PATCH] Secure login and sulogin on S390x

Some remarks: on S390x architecture of modern zSeries the hypervisor does log the console I/O. For both the 3215 half duplex line mode as well as the 3270 full-screen/block mode console type the I/O is logged on the hypervisor's side. To control this there are command send via /dev/vmcp to tell the z/VM control program of the hypervisor not to log during entering the password. For the 3215 console also automatic scroll is enabled which avoid to press CLEAR to get the password prompt if on the next block.

Beside this for the ttysclp0, the serial ASCII terminal accessed via a websocket has since ncurses 6.5-20250405 a new terminfo entry called "sclp" to support not only the vt220 like behaviour but also the colouring feature of ttysclp0.

Ensure to detect all special console case on S390x

---
 lib/ttyutils.c                 |   5 +-
 login-utils/Makemodule.am      |   9 +-
 login-utils/login.c            |  85 +++++++++++-
 login-utils/meson.build        |   5 +
 login-utils/sulogin-consoles.c |  44 ++++--
 login-utils/sulogin-consoles.h |   4 +
 login-utils/sulogin.c          |  64 +++++++--
 login-utils/vmcp.c             | 236 +++++++++++++++++++++++++++++++++
 login-utils/vmcp.h             |  29 ++++
 9 files changed, 460 insertions(+), 21 deletions(-)
 create mode 100644 login-utils/vmcp.c
 create mode 100644 login-utils/vmcp.h
lib/ttyutils.c +3 -2
index bacd73077..3085419bd 100644
@@ -21,7 +21,7 @@
 #  if defined (__s390__) || defined (__s390x__)
 #    define DEFAULT_TTYS0  "dumb"
 #    define DEFAULT_TTY32  "ibm327x"
-#    define DEFAULT_TTYS1  "vt220"
+#    define DEFAULT_TTYS1  "sclp"
 #  endif
 #  ifndef DEFAULT_STERM
 #    define DEFAULT_STERM  "vt102"
@@ -176,7 +176,8 @@ char *get_terminal_default_type(const char *ttyname, int is_serial)
 		 * Special terminal on first serial line on a S/390(x) which
 		 * is due legacy reasons a block terminal of type 3270 or
 		 * higher.  Whereas the second serial line on a S/390(x) is
-		 * a real character terminal which is compatible with VT220.
+		 * a real character terminal which is compatible with "sclp"
+		 * since ncurses 6.5-20250405 for e.g. color support.
 		 */
 		if (strcmp(ttyname, "ttyS0") == 0)		/* linux/drivers/s390/char/con3215.c */
 			return strdup(DEFAULT_TTYS0);
login-utils/Makemodule.am +7 -2
index a82e4b70f..4e3205577 100644
@@ -33,7 +33,9 @@ dist_noinst_DATA += login-utils/sulogin.8.adoc
 sulogin_SOURCES = \
 	login-utils/sulogin.c \
 	login-utils/sulogin-consoles.c \
-	login-utils/sulogin-consoles.h
+	login-utils/sulogin-consoles.h \
+	login-utils/vmcp.c \
+	login-utils/vmcp.h
 if USE_PLYMOUTH_SUPPORT
 sulogin_SOURCES += lib/plymouth-ctrl.c
 endif
@@ -58,7 +60,10 @@ bin_PROGRAMS += login
 MANPAGES += login-utils/login.1
 dist_noinst_DATA += login-utils/login.1.adoc
 login_SOURCES = \
-	login-utils/login.c
+	login-utils/login.c \
+	login-utils/vmcp.c \
+	login-utils/vmcp.h \
+	lib/logindefs.c
 login_LDADD = $(LDADD) libcommon.la libcommon_logindefs.la libcommon_shells.la -lpam
 if HAVE_LINUXPAM
 login_LDADD += -lpam_misc
login-utils/login.c +84 -1

104 lines not on this page · raw message

login-utils/meson.build +5 -0
index 251d8de46..5f6310b01 100644
@@ -49,6 +49,7 @@ test_islocal_sources = files(
 
 test_consoles_sources = files(
   'sulogin-consoles.c',
+  'vmcp.c',
 )
 
 last_sources = files(
@@ -59,6 +60,8 @@ last_manadocs = files('last.1.adoc')
 
 login_sources = files(
   'login.c',
+  'vmcp.c',
+  'vmcp.h',
 )
 login_manadocs = files('login.1.adoc')
 
@@ -66,6 +69,8 @@ sulogin_sources = files(
   'sulogin.c',
   'sulogin-consoles.c',
   'sulogin-consoles.h',
+  'vmcp.c',
+  'vmcp.h',
 )
 sulogin_manadocs = files('sulogin.8.adoc')
 
login-utils/sulogin-consoles.c +36 -8

95 lines not on this page · raw message

login-utils/sulogin-consoles.h +4 -0
index d3b4298e4..10fdf612c 100644
@@ -39,6 +39,10 @@ struct console {
 #define	CON_SERIAL	0x0001
 #define	CON_NOTTY	0x0002
 #define	CON_EIO		0x0004
+#define	CON_CONSDEV	0x0008	/* Last on the kernel command line */
+#define	CON_3215	0x0010	/* s390x 3215 halfduplex console */
+#define	CON_3270	0x0020  /* s390x 3270 console */
+#define	CON_SCLP	0x0040	/* s390x sclp terminals */
 	pid_t pid;
 	struct chardata cp;
 	struct termios tio;
login-utils/sulogin.c +56 -8

115 lines not on this page · raw message

login-utils/vmcp.c new file +236 -0

236 lines not on this page · raw message

login-utils/vmcp.h new file +29 -0
new file mode 100644
index 000000000..50ef1ba90
@@ -0,0 +1,29 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * vmcp.c - s390x 3215 console spool and terminal management
+ *
+ * Copyright 2026 Werner Fink, SUSE Software Solutions Germany GmbH
+ *
+ * Based on:
+ *
+ * Copyright IBM Corp. 2018
+ * s390-tools is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ *
+ */
+
+extern int isinteger(const char *str);
+#if defined(__s390__) || defined(__s390x__)
+extern int openvmcp(void);
+extern void clearvmcp(void);
+extern char* queryterm(int fd);
+extern char* queryspool(int fd);
+extern int setterm(int fd, char *tout);
+extern int stopspool(int fd);
+extern int restoreterm(int fd);
+extern int restorespool(int fd);
+extern void parseterm(char *msg);
+extern void parsespool(char *msg);
+extern void warning3215(int fd);
+#endif
Signature · 1 line
2.51.0
maintainer
#5 lore raw

Re: Repost: [PATCH] Secure login and sulogin on S390x

Hi Werner,

Quoted 2 lines · Dr. Werner Fink

just to be sure that this change for s390x does not fall down behind. Are there some changes required?

Sorry for the delay. I have pushed it to GitHub for CI to check:
https://github.com/util-linux/util-linux/pull/4325. I haven't had time to work on it further.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com