Compare commits

..

1 commit

Author SHA1 Message Date
Vitezslav Crhonek
628c7113c8 Fix openvt -u process matching to be more conservative (CVE-2026-72693) 2026-08-27 10:17:31 +02:00
4 changed files with 143 additions and 26 deletions

3
.gitignore vendored
View file

@ -9,5 +9,4 @@ terminus.tar.bz2
/fr-dvorak.tar.bz2
/kbd-latarcyrheb-32.tar.bz2
/kbdinfo.1
/kbd-2.9.0.tar.xz
/kbd-2.10.0.tar.xz
/kbd-2.8.0.tar.xz

View file

@ -0,0 +1,129 @@
diff --git a/docs/man/man1/openvt.1 b/docs/man/man1/openvt.1
index 8f1244f1..404e4a06 100644
--- a/docs/man/man1/openvt.1
+++ b/docs/man/man1/openvt.1
@@ -36,6 +36,8 @@ will be made the new current VT.
\fB\-u\fR, \fB\-\-user\fR
Figure out the owner of the current VT, and run login as that user.
Suitable to be called by init. Shouldn't be used with \fI\-c\fR or \fI\-l\fR.
+This option refuses to pre-authenticate root and requires a process owned by
+the VT owner whose controlling terminal is the current VT.
.TP
\fB\-l\fR, \fB\-\-login\fR
Make the command a login shell. A \- is prepended to the name of the command
@@ -64,6 +66,14 @@ If
is compiled with a getopt_long() and you wish to set
options to the command to be run, then you must supply
the end of options \-\- flag before the command.
+.PP
+The
+.B \-u
+option uses
+.BR "login -f"
+and therefore bypasses normal password authentication for the detected user.
+It is intended only for controlled init or keyboard-request configurations.
+Use a normal authenticated login command when authentication is required.
.SH EXAMPLES
.B openvt
can be used to start a shell on the next free VT, by using the command:
diff --git a/src/openvt.c b/src/openvt.c
index ed3ed18e..dab3dad8 100644
--- a/src/openvt.c
+++ b/src/openvt.c
@@ -57,6 +57,51 @@ usage(int rc, const struct kbd_help *options)
exit(rc);
}
+static int
+proc_pid_stat(const char *pid, uid_t *uid, dev_t *tty)
+{
+ char filename[NAME_MAX + 12];
+ char line[BUFSIZ];
+ char *lp, *rp;
+ FILE *fp;
+ struct stat st;
+ long tty_nr;
+
+ snprintf(filename, sizeof(filename), "/proc/%s/stat", pid);
+ fp = fopen(filename, "r");
+ if (!fp)
+ return -1;
+
+ if (fstat(fileno(fp), &st)) {
+ fclose(fp);
+ return -1;
+ }
+
+ if (!fgets(line, sizeof(line), fp)) {
+ fclose(fp);
+ return -1;
+ }
+ fclose(fp);
+
+ rp = strrchr(line, ')');
+ if (!rp)
+ return -1;
+
+ /*
+ * /proc/<pid>/stat fields after comm are:
+ * state ppid pgrp session tty_nr ...
+ */
+ if (!rp || sscanf(rp + 1, " %*c %*d %*d %*d %ld", &tty_nr) != 1)
+ return -1;
+
+ if (tty_nr <= 0)
+ return -1;
+
+ *uid = st.st_uid;
+ *tty = (dev_t) tty_nr;
+ return 0;
+}
+
/*
* Support for Spawn_Console: openvt running from init
* added by Joshua Spoerri, Thu Jul 18 21:13:16 EDT 1996
@@ -88,8 +133,7 @@ authenticate_user(int curvt)
DIR *dp;
struct dirent *dentp;
struct stat buf;
- dev_t console_dev;
- ino_t console_ino;
+ dev_t console_rdev;
uid_t console_uid;
char filename[NAME_MAX + 12];
struct passwd *pwnam;
@@ -109,10 +153,12 @@ authenticate_user(int curvt)
kbd_error(EXIT_FAILURE, errsv, "%s", filename);
}
}
- console_dev = buf.st_dev;
- console_ino = buf.st_ino;
+ console_rdev = buf.st_rdev;
console_uid = buf.st_uid;
+ if (console_uid == 0)
+ kbd_error(EXIT_FAILURE, 0, _("Refusing to pre-authenticate root on current tty."));
+
/* get the owner of current tty */
if (!(pwnam = getpwuid(console_uid)))
kbd_error(EXIT_FAILURE, errno, "getpwuid");
@@ -120,12 +166,16 @@ authenticate_user(int curvt)
/* check to make sure that user has a process on that tty */
/* this will fail for example when X is running on the tty */
while ((dentp = readdir(dp))) {
- sprintf(filename, "/proc/%s/fd/0", dentp->d_name);
+ uid_t proc_uid;
+ dev_t proc_tty;
+
+ if (dentp->d_name[0] < '0' || dentp->d_name[0] > '9')
+ continue;
- if (stat(filename, &buf))
+ if (proc_pid_stat(dentp->d_name, &proc_uid, &proc_tty) < 0)
continue;
- if (buf.st_dev == console_dev && buf.st_ino == console_ino && buf.st_uid == console_uid)
+ if (proc_uid == console_uid && proc_tty == console_rdev)
goto got_a_process;
}

View file

@ -4,8 +4,8 @@
%global kbd_datadir %{_exec_prefix}/lib/kbd
Name: kbd
Version: 2.10.0
Release: 2%{?dist}
Version: 2.8.0
Release: 4%{?dist}
Summary: Tools for configuring the console (keyboard, virtual terminals, etc.)
License: GPL-2.0-or-later
URL: http://www.kbd-project.org/
@ -34,9 +34,13 @@ Patch5: kbd-2.0.2-unicode-start-font.patch
Patch6: kbd-2.4.0-covscan-fixes.patch
# Patch7: adds vlock option to issue prompt before invokation of pam stack
Patch7: kbd-2.0.4-vlock-add-prompt-option.patch
# Patch8: fixes CVE-2026-72693, backported from upstream
# https://github.com/legionus/kbd/commit/78d5ae119742e87baa7dbe0f5c4107e7533fd698
Patch8: kbd-2.9.0-CVE-2026-72693.patch
BuildRequires: gcc, bison, flex, gettext, pam-devel, check-devel, automake, make
BuildRequires: console-setup, xkeyboard-config, libxkbcommon-devel
BuildRequires: gcc, bison, flex, gettext, pam-devel, check-devel, automake
BuildRequires: console-setup, xkeyboard-config
BuildRequires: make
Requires: %{name}-misc = %{version}-%{release}
Requires: %{name}-legacy = %{version}-%{release}
# Be sure that system is after UsrMove
@ -101,8 +105,7 @@ iconv -f iso-8859-1 -t utf-8 < "ChangeLog" > "ChangeLog_"
mv "ChangeLog_" "ChangeLog"
%build
%configure --prefix=%{_prefix} --datadir=%{kbd_datadir} \
--mandir=%{_mandir} --localedir=%{_datadir}/locale --enable-nls --enable-xkb
%configure --prefix=%{_prefix} --datadir=%{kbd_datadir} --mandir=%{_mandir} --localedir=%{_datadir}/locale --enable-nls
%make_build
%install
@ -184,23 +187,9 @@ fi
%{kbd_datadir}/keymaps/legacy
%changelog
* Thu Jul 16 2026 Fedora Release Engineering <releng@fedoraproject.org> - 2.10.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_45_Mass_Rebuild
* Wed Jun 10 2026 Vitezslav Crhonek <vcrhonek@redhat.com> - 2.10.0-1
- Update to kbd-2.10.0
Resolves: #2481141
* Tue Mar 24 2026 Vitezslav Crhonek <vcrhonek@redhat.com> - 2.9.0-3
- Fix setfont segmentation fault when argument for option is missing
Resolves: #2447892
* Fri Jan 16 2026 Fedora Release Engineering <releng@fedoraproject.org> - 2.9.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_44_Mass_Rebuild
* Mon Sep 22 2025 Vitezslav Crhonek <vcrhonek@redhat.com> - 2.9.0-1
- Update to kbd-2.9.0
Resolves: #2393145
* Thu Aug 27 2026 Vitezslav Crhonek <vcrhonek@redhat.com> - 2.8.0-4
- Fix openvt -u process matching to be more conservative (CVE-2026-72693)
Resolves: #2513795
* Thu Jul 24 2025 Fedora Release Engineering <releng@fedoraproject.org> - 2.8.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild

View file

@ -1,4 +1,4 @@
SHA512 (kbd-latsun-fonts.tar.bz2) = b98da5df85017ef1bd297eb2255046d54dd805c84356db7533f24e49fb78c8e3999901a45a49cdf6a74c0002bba2e0aa8327469d78dd38b6e747103972c30584
SHA512 (kbd-latarcyrheb-32.tar.bz2) = 1870a708e16cf16f8343f02f7e97940e8404655078f92709a0b8a334be772faa99b4dbaca37e8d8c5b16d0d4d811fe6b102e4f76ae821148eb33075613dc95b8
SHA512 (kbdinfo.1) = 8696d55f6c15f0ee2c2936eca6180b18100a87b11f0efe809a9531bb1228c67cd096cbc8fa25d9ee496daab28892ee5f320cc4bc9c9d816ff666bb4f80271c99
SHA512 (kbd-2.10.0.tar.xz) = 1b7f55f0a1b34d9b6b4237a1ff3e10eedf4bdebe50e906a7acdea48f85b3c455e72737127491a0c494388b999797aa65411b20b44c3f5612fdeee4d8289f937c
SHA512 (kbd-2.8.0.tar.xz) = 66b532e782b6be3f53521a8d1c96f2ce895201dae48f8797c563be895dfdf4e9c03b9ccf39708d1b7dd1ffb13d526e499874e8e4ba74d22b507c1d32e4b410a3