From 9cc9e3ddbb9c49b34bffe31fdbc8a3505145d508 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 30 May 2021 12:42:48 +0200 Subject: [PATCH] getty: if we cannot execute /bin/login, try sulogin before /bin/sh Basic security measure, don't bail to shell if we cannot find/exec login, instead try sulogin before falling back to plain shell. Signed-off-by: Joachim Wiberg --- src/Makefile.am | 2 +- src/finit.h | 1 + src/getty.c | 15 ++++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index bee9ae62..27200f87 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,7 @@ endif finit_pkglibdir = $(pkglibdir) finit_pkglib_SCRIPTS = rescue.conf sample.conf -getty_SOURCES = getty.c helpers.h logrotate.c stty.c utmp-api.c utmp-api.h +getty_SOURCES = finit.h getty.c helpers.h logrotate.c stty.c utmp-api.c utmp-api.h getty_CFLAGS = -W -Wall -Wextra -std=gnu99 getty_CFLAGS += $(lite_CFLAGS) getty_LDADD = $(lite_LIBS) diff --git a/src/finit.h b/src/finit.h index 86574dba..8c13aba5 100644 --- a/src/finit.h +++ b/src/finit.h @@ -50,6 +50,7 @@ #define FINIT_CGPATH "/sys/fs/cgroup" #endif +/* To use these, include config.h, or define FINIT_LIBPATH_ */ #define _PATH_LOGIT FINIT_LIBPATH_ "/logit" #define _PATH_SULOGIN FINIT_LIBPATH_ "/sulogin" #define _PATH_GETTY FINIT_LIBPATH_ "/getty" diff --git a/src/getty.c b/src/getty.c index e7c43a3c..4a88f5e2 100644 --- a/src/getty.c +++ b/src/getty.c @@ -21,6 +21,8 @@ * THE SOFTWARE. */ +#include "config.h" + #include #include #include @@ -32,6 +34,7 @@ #include /* Not included by default in musl libc */ #include +#include "finit.h" #include "helpers.h" #include "utmp-api.h" @@ -179,12 +182,14 @@ static int do_login(char *name) /* * Failed to exec login, should not happen on normal systems. * Try a starting a rescue shell instead. - * - * Note: Add /etc/securetty handling. */ - warnx("Failed exec %s, attempting fallback to %s ...", _PATH_LOGIN, _PATH_BSHELL); - if (fstat(0, &st) == 0 && S_ISCHR(st.st_mode)) - execl(_PATH_BSHELL, _PATH_BSHELL, NULL); /* XXX: run sulogin instead! */ + if (fstat(0, &st) == 0 && S_ISCHR(st.st_mode)) { + warnx("Failed exec %s, attempting fallback to %s ...", _PATH_LOGIN, _PATH_SULOGIN); + execl(_PATH_SULOGIN, _PATH_SULOGIN, NULL); + + warnx("Failed exec %s, attempting fallback to %s ...", _PATH_SULOGIN, _PATH_BSHELL); + execl(_PATH_BSHELL, _PATH_BSHELL, NULL); + } return 1; /* We shouldn't get here ... */ }