CVE-2026-4897: getline() string overflow via unsanitized input

Resolves: CVE-2026-4897
This commit is contained in:
Jan Rybar 2026-05-12 12:57:36 +02:00
parent 7751f09b8d
commit dd5058f68b
2 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,63 @@
From 6a8e2ef62f807bc155033c6cba506076f95e46df Mon Sep 17 00:00:00 2001
From: Jan Rybar <jrybar@redhat.com>
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
#include <unistd.h>
#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

View File

@ -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 <jrybar@redhat.com> - 125-5
- CVE-2026-4897: getline() string overflow via unsanitized input
- Resolves: CVE-2026-4897
* Tue Aug 12 2025 Jan Rybar <jrybar@redhat.com> - 125-4
- changing log level via dbus is now restricted to root
- backport of https://github.com/polkit-org/polkit/commit/5a4ba7dfdcc3f