|
| 1 | +From 9aa712d586604fcb8f2d5abbffd9030c147525ed Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jan Rybar <jrybar@redhat.com> |
| 3 | +Date: Fri, 27 Mar 2026 15:57:01 +0100 |
| 4 | +Subject: [PATCH] CVE-2026-4897 - getline() string overflow |
| 5 | + |
| 6 | +Report and fix by Aisle.com |
| 7 | +Pavel Kohout, Aisle Research |
| 8 | + |
| 9 | +Signed-off-by: Jan Rybar jrybar@redhat.com |
| 10 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 11 | +Upstream-reference: https://github.com/polkit-org/polkit/commit/7e122c8a5120c2aae2d9d44a26796dc18f5b677c.patch |
| 12 | +--- |
| 13 | + src/polkitagent/polkitagenthelperprivate.c | 23 +++++++++++++--------- |
| 14 | + 1 file changed, 14 insertions(+), 9 deletions(-) |
| 15 | + |
| 16 | +diff --git a/src/polkitagent/polkitagenthelperprivate.c b/src/polkitagent/polkitagenthelperprivate.c |
| 17 | +index 1f32c0a..63333f6 100644 |
| 18 | +--- a/src/polkitagent/polkitagenthelperprivate.c |
| 19 | ++++ b/src/polkitagent/polkitagenthelperprivate.c |
| 20 | +@@ -25,6 +25,7 @@ |
| 21 | + #include <stdio.h> |
| 22 | + #include <string.h> |
| 23 | + #include <stdlib.h> |
| 24 | ++#include <errno.h> |
| 25 | + #include <unistd.h> |
| 26 | + |
| 27 | + #ifndef HAVE_CLEARENV |
| 28 | +@@ -60,21 +61,25 @@ read_cookie (int argc, char **argv) |
| 29 | + return strdup (argv[2]); |
| 30 | + else |
| 31 | + { |
| 32 | +- char *ret = NULL; |
| 33 | +- size_t n = 0; |
| 34 | +- ssize_t r = getline (&ret, &n, stdin); |
| 35 | +- if (r == -1) |
| 36 | ++ #define POLKIT_AGENT_MAX_COOKIE 4096 |
| 37 | ++ char buf[POLKIT_AGENT_MAX_COOKIE + 2]; /* +1 for newline, +1 for NUL */ |
| 38 | ++ if (fgets (buf, sizeof(buf), stdin) == NULL) |
| 39 | + { |
| 40 | + if (!feof (stdin)) |
| 41 | +- perror ("getline"); |
| 42 | +- free (ret); |
| 43 | ++ perror ("fgets"); |
| 44 | + return NULL; |
| 45 | + } |
| 46 | +- else |
| 47 | ++ if (buf[strlen (buf) - 1] != '\n') |
| 48 | + { |
| 49 | +- g_strchomp (ret); |
| 50 | +- return ret; |
| 51 | ++ /* Cookie too long - drain remaining input and reject */ |
| 52 | ++ int c; |
| 53 | ++ while ((c = getchar ()) != '\n' && c != EOF) |
| 54 | ++ ; |
| 55 | ++ errno = EOVERFLOW; |
| 56 | ++ return NULL; |
| 57 | + } |
| 58 | ++ g_strchomp (buf); |
| 59 | ++ return strdup (buf); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | +-- |
| 64 | +2.45.4 |
| 65 | + |
0 commit comments