From dd5058f68b834969ace7bdb5375aef18b1631a47 Mon Sep 17 00:00:00 2001 From: Jan Rybar Date: Tue, 12 May 2026 12:57:36 +0200 Subject: [PATCH] CVE-2026-4897: getline() string overflow via unsanitized input Resolves: CVE-2026-4897 --- cve-2026-4897-getline-overflow.patch | 63 ++++++++++++++++++++++++++++ polkit.spec | 7 +++- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 cve-2026-4897-getline-overflow.patch diff --git a/cve-2026-4897-getline-overflow.patch b/cve-2026-4897-getline-overflow.patch new file mode 100644 index 0000000..f3dfa98 --- /dev/null +++ b/cve-2026-4897-getline-overflow.patch @@ -0,0 +1,63 @@ +From 6a8e2ef62f807bc155033c6cba506076f95e46df Mon Sep 17 00:00:00 2001 +From: Jan Rybar +Date: Fri, 27 Mar 2026 15:57:01 +0100 +Subject: [PATCH] CVE-2026-4897 - getline() string overflow + +Report and fix by Aisle.com +Pavel Kohout, Aisle Research + +Signed-off-by: Jan Rybar jrybar@redhat.com +--- + src/polkitagent/polkitagenthelperprivate.c | 23 +++++++++++++--------- + 1 file changed, 14 insertions(+), 9 deletions(-) + +diff --git a/src/polkitagent/polkitagenthelperprivate.c b/src/polkitagent/polkitagenthelperprivate.c +index 35bca85..7e4f94e 100644 +--- a/src/polkitagent/polkitagenthelperprivate.c ++++ b/src/polkitagent/polkitagenthelperprivate.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include + + #ifndef HAVE_CLEARENV +@@ -59,21 +60,25 @@ read_cookie (int argc, char **argv) + return strdup (argv[2]); + else + { +- char *ret = NULL; +- size_t n = 0; +- ssize_t r = getline (&ret, &n, stdin); +- if (r == -1) ++ #define POLKIT_AGENT_MAX_COOKIE 4096 ++ char buf[POLKIT_AGENT_MAX_COOKIE + 2]; /* +1 for newline, +1 for NUL */ ++ if (fgets (buf, sizeof(buf), stdin) == NULL) + { + if (!feof (stdin)) +- perror ("getline"); +- free (ret); ++ perror ("fgets"); + return NULL; + } +- else ++ if (buf[strlen (buf) - 1] != '\n') + { +- g_strchomp (ret); +- return ret; ++ /* Cookie too long - drain remaining input and reject */ ++ int c; ++ while ((c = getchar ()) != '\n' && c != EOF) ++ ; ++ errno = EOVERFLOW; ++ return NULL; + } ++ g_strchomp (buf); ++ return strdup (buf); + } + } + +-- +2.53.0 + diff --git a/polkit.spec b/polkit.spec index 11b65a1..65ec430 100644 --- a/polkit.spec +++ b/polkit.spec @@ -4,7 +4,7 @@ Summary: An authorization framework Name: polkit Version: 125 -Release: 4%{?dist} +Release: 5%{?dist} License: LGPL-2.0-or-later URL: https://github.com/polkit-org/polkit Source0: https://github.com/polkit-org/polkit/archive/refs/tags/%{version}.tar.gz @@ -12,6 +12,7 @@ Source1: polkit.sysusers Patch1: pthread_condattr_loglevel.patch Patch2: loglevel_property_root_only.patch +Patch3: cve-2026-4897-getline-overflow.patch BuildRequires: gcc-c++ BuildRequires: glib2-devel >= 2.30.0 @@ -164,6 +165,10 @@ rm -f $RPM_BUILD_ROOT%{_libdir}/*.la %{_libdir}/girepository-1.0/*.typelib %changelog +* Tue May 12 2026 Jan Rybar - 125-5 +- CVE-2026-4897: getline() string overflow via unsanitized input +- Resolves: CVE-2026-4897 + * Tue Aug 12 2025 Jan Rybar - 125-4 - changing log level via dbus is now restricted to root - backport of https://github.com/polkit-org/polkit/commit/5a4ba7dfdcc3f