From b214c5305bd86f79f0a92d0a5175d0257e980128 Mon Sep 17 00:00:00 2001 From: Iker Pedrosa Date: Mon, 12 Feb 2024 15:43:10 +0100 Subject: [PATCH] pam_namespace: protect_dir(): use O_DIRECTORY to prevent local DoS situations. CVE-2024-22365 Resolves: RHEL-21242 Signed-off-by: Iker Pedrosa --- pam-1.3.1-namespace-protect-dir.patch | 58 +++++++++++++++++++++++++++ pam.spec | 9 ++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 pam-1.3.1-namespace-protect-dir.patch diff --git a/pam-1.3.1-namespace-protect-dir.patch b/pam-1.3.1-namespace-protect-dir.patch new file mode 100644 index 0000000..39e2b5e --- /dev/null +++ b/pam-1.3.1-namespace-protect-dir.patch @@ -0,0 +1,58 @@ +From 031bb5a5d0d950253b68138b498dc93be69a64cb Mon Sep 17 00:00:00 2001 +From: Matthias Gerstner +Date: Wed, 27 Dec 2023 14:01:59 +0100 +Subject: [PATCH] pam_namespace: protect_dir(): use O_DIRECTORY to prevent + local DoS situations + +Without O_DIRECTORY the path crawling logic is subject to e.g. FIFOs +being placed in user controlled directories, causing the PAM module to +block indefinitely during `openat()`. + +Pass O_DIRECTORY to cause the `openat()` to fail if the path does not +refer to a directory. + +With this the check whether the final path element is a directory +becomes unnecessary, drop it. +--- + modules/pam_namespace/pam_namespace.c | 18 +----------------- + 1 file changed, 1 insertion(+), 17 deletions(-) + +diff --git a/modules/pam_namespace/pam_namespace.c b/modules/pam_namespace/pam_namespace.c +index 2528cff8..f72d6718 100644 +--- a/modules/pam_namespace/pam_namespace.c ++++ b/modules/pam_namespace/pam_namespace.c +@@ -1201,7 +1201,7 @@ static int protect_dir(const char *path, mode_t mode, int do_mkdir, + int dfd = AT_FDCWD; + int dfd_next; + int save_errno; +- int flags = O_RDONLY; ++ int flags = O_RDONLY | O_DIRECTORY; + int rv = -1; + struct stat st; + +@@ -1255,22 +1255,6 @@ static int protect_dir(const char *path, mode_t mode, int do_mkdir, + rv = openat(dfd, dir, flags); + } + +- if (rv != -1) { +- if (fstat(rv, &st) != 0) { +- save_errno = errno; +- close(rv); +- rv = -1; +- errno = save_errno; +- goto error; +- } +- if (!S_ISDIR(st.st_mode)) { +- close(rv); +- errno = ENOTDIR; +- rv = -1; +- goto error; +- } +- } +- + if (flags & O_NOFOLLOW) { + /* we are inside user-owned dir - protect */ + if (protect_mount(rv, p, idata) == -1) { +-- +2.43.0 + diff --git a/pam.spec b/pam.spec index e833cda..d9c2250 100644 --- a/pam.spec +++ b/pam.spec @@ -3,7 +3,7 @@ Summary: An extensible library which provides authentication for applications Name: pam Version: 1.3.1 -Release: 32%{?dist} +Release: 33%{?dist} # The library is BSD licensed with option to relicense as GPLv2+ # - this option is redundant as the BSD license allows that anyway. # pam_timestamp, pam_loginuid, and pam_console modules are GPLv2+. @@ -108,6 +108,8 @@ Patch67: pam-1.3.1-unix-default-rounds.patch Patch68: pam-1.3.1-faillock-create-tallydir.patch # https://github.com/linux-pam/linux-pam/commit/23393bef92c1e768eda329813d7af55481c6ca9f Patch69: pam-1.3.1-access-handle-hostnames.patch +# https://github.com/linux-pam/linux-pam/commit/031bb5a5d0d950253b68138b498dc93be69a64cb +Patch70: pam-1.3.1-namespace-protect-dir.patch %define _pamlibdir %{_libdir} %define _moduledir %{_libdir}/security @@ -225,6 +227,7 @@ cp %{SOURCE18} . %patch67 -p1 -b .unix-default-rounds %patch68 -p1 -b .faillock-create-tallydir %patch69 -p1 -b .access-handle-hostnames +%patch70 -p1 -b .namespace-protect-dir autoreconf -i @@ -478,6 +481,10 @@ done %doc doc/specs/rfc86.0.txt %changelog +* Mon Feb 12 2024 Iker Pedrosa - 1.3.1-33 +- pam_namespace: protect_dir(): use O_DIRECTORY to prevent local DoS + situations. CVE-2024-22365. Resolves: RHEL-21242 + * Fri Jan 26 2024 Iker Pedrosa - 1.3.1-32 - pam_access: handle hostnames in access.conf. Resolves: RHEL-3374