public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/python3-rpm] epel9: CVE-2026-84837: Prevent command injection via rpmbuild -t filename
@ 2026-11-13 18:33 Michal Domonkos
0 siblings, 0 replies; only message in thread
From: Michal Domonkos @ 2026-11-13 18:33 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/python3-rpm
Branch : epel9
Commit : f176dc4b3745cf529af0bd1c8d9b29c2434828db
Author : Michal Domonkos <mdomonko@redhat.com>
Date : 2026-10-26T13:00:16+01:00
Stats : +419/-1 in 4 file(s)
URL : https://src.fedoraproject.org/rpms/python3-rpm/c/f176dc4b3745cf529af0bd1c8d9b29c2434828db?branch=epel9
Log:
CVE-2026-84837: Prevent command injection via rpmbuild -t filename
Resolves: RHEL-288157
---
diff --git a/0001-Extract-archiver-detection-out-of-doUncompress.patch b/0001-Extract-archiver-detection-out-of-doUncompress.patch
new file mode 100644
index 0000000..ad499b0
--- /dev/null
+++ b/0001-Extract-archiver-detection-out-of-doUncompress.patch
@@ -0,0 +1,143 @@
+From 7aabd4c44b5cf015ac3854cc16fc23e23a87f224 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Fri, 23 Oct 2026 14:01:04 +0200
+Subject: [PATCH 1/3] Extract archiver detection out of doUncompress()
+
+Move the logic to determine the command line string to an internal macro
+API function called rpmGetArchiver(). This will be needed in the
+subsequent commit.
+
+No functional change.
+---
+ rpmio/macro.c | 82 +++++++++++++++++++++++----------------
+ rpmio/rpmmacro_internal.h | 8 ++++
+ 2 files changed, 57 insertions(+), 33 deletions(-)
+
+diff --git a/rpmio/macro.c b/rpmio/macro.c
+index 490bf9a6a..6eef3cd2f 100644
+--- a/rpmio/macro.c
++++ b/rpmio/macro.c
+@@ -1107,7 +1107,7 @@ doSP(MacroBuf mb, int chkexist, int negate,
+ static void doUncompress(MacroBuf mb, int chkexist, int negate,
+ const char * f, size_t fn, const char * g, size_t gn)
+ {
+- rpmCompressedMagic compressed = COMPRESSED_OTHER;
++ const char *cmd = NULL;
+ char *b, *be, *buf = NULL;
+ int c;
+
+@@ -1123,40 +1123,10 @@ static void doUncompress(MacroBuf mb, int chkexist, int negate,
+ if (gn == 0 || *b == '\0')
+ goto exit;
+
+- if (rpmFileIsCompressed(b, &compressed))
++ if (rpmGetArchiver(b, &cmd))
+ mb->error = 1;
+
+- switch (compressed) {
+- default:
+- case COMPRESSED_NOT:
+- expandMacro(mb, "%__cat ", 0);
+- break;
+- case COMPRESSED_OTHER:
+- expandMacro(mb, "%__gzip -dc ", 0);
+- break;
+- case COMPRESSED_BZIP2:
+- expandMacro(mb, "%__bzip2 -dc ", 0);
+- break;
+- case COMPRESSED_ZIP:
+- expandMacro(mb, "%__unzip ", 0);
+- break;
+- case COMPRESSED_LZMA:
+- case COMPRESSED_XZ:
+- expandMacro(mb, "%__xz -dc ", 0);
+- break;
+- case COMPRESSED_LZIP:
+- expandMacro(mb, "%__lzip -dc ", 0);
+- break;
+- case COMPRESSED_LRZIP:
+- expandMacro(mb, "%__lrzip -dqo- ", 0);
+- break;
+- case COMPRESSED_7ZIP:
+- expandMacro(mb, "%__7zip x ", 0);
+- break;
+- case COMPRESSED_ZSTD:
+- expandMacro(mb, "%__zstd -dc ", 0);
+- break;
+- }
++ expandMacro(mb, cmd, 0);
+ mbAppendStr(mb, buf);
+
+ exit:
+@@ -2004,3 +1974,49 @@ rpmExpandNumeric(const char *arg)
+
+ return rc;
+ }
++
++int
++rpmGetArchiver(const char *fn, const char **cmd)
++{
++ int rc = 0;
++ rpmCompressedMagic compressed = COMPRESSED_OTHER;
++ const char *s = NULL;
++
++ if (rpmFileIsCompressed(fn, &compressed))
++ rc = 1;
++
++ switch (compressed) {
++ default:
++ case COMPRESSED_NOT:
++ s = "%__cat ";
++ break;
++ case COMPRESSED_OTHER:
++ s = "%__gzip -dc ";
++ break;
++ case COMPRESSED_BZIP2:
++ s = "%__bzip2 -dc ";
++ break;
++ case COMPRESSED_ZIP:
++ s = "%__unzip ";
++ break;
++ case COMPRESSED_LZMA:
++ case COMPRESSED_XZ:
++ s = "%__xz -dc ";
++ break;
++ case COMPRESSED_LZIP:
++ s = "%__lzip -dc ";
++ break;
++ case COMPRESSED_LRZIP:
++ s = "%__lrzip -dqo- ";
++ break;
++ case COMPRESSED_7ZIP:
++ s = "%__7zip x ";
++ break;
++ case COMPRESSED_ZSTD:
++ s = "%__zstd -dc ";
++ break;
++ }
++
++ *cmd = s;
++ return rc;
++}
+diff --git a/rpmio/rpmmacro_internal.h b/rpmio/rpmmacro_internal.h
+index a59671be8..eca7511da 100644
+--- a/rpmio/rpmmacro_internal.h
++++ b/rpmio/rpmmacro_internal.h
+@@ -19,6 +19,14 @@ extern "C" {
+ RPM_GNUC_INTERNAL
+ const char *findMacroEnd(const char *str);
+
++/** \ingroup rpmmacro
++ * Return a command line (without fn) for extracting the archive fn.
++ * Always returns a command line, even on failure.
++ * @param fn filename of the archive
++ * @retval cmd command line (with a trailing space)
++ * @return 0 on success, 1 on failure
++ */
++int rpmGetArchiver(const char *fn, const char **cmd);
+
+ #ifdef __cplusplus
+ }
+--
+2.56.0
+
diff --git a/0002-Prevent-command-injection-via-rpmbuild-t-filename.patch b/0002-Prevent-command-injection-via-rpmbuild-t-filename.patch
new file mode 100644
index 0000000..09a6b8c
--- /dev/null
+++ b/0002-Prevent-command-injection-via-rpmbuild-t-filename.patch
@@ -0,0 +1,187 @@
+From b51759c2ec195c3eaab2b0de0b7a60a4512a984e Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Mon, 7 Sep 2026 14:41:39 +0200
+Subject: [PATCH 2/3] Prevent command injection via rpmbuild -t filename
+
+Commit 2a11eb3e4e51094082e0123aebd797ec051dc094 fixed command injection
+via spec file entries, but there's another case where we pass some data
+controlled by the tarball through macro or shell expansion: the filename
+argument itself.
+
+This happens in three places during tarball decompression: the first two
+are in getTarSpec() where we construct and execute the shell command for
+spec file extraction using rpmExpand() and popen(3), respectively, which
+leads to the third one where we execute the actual decompression utility
+using popen(3) in rpmuncompress. The filename gets passed through all of
+these steps, and can cause arbitrary shell code execution in each one.
+
+Fix that by passing the filename as a positional argument when invoking
+the shell so that the command can reference it through the hardcoded $1
+parameter instead of the filename directly. Add our own popen(3) version
+for this purpose that takes an additional argument to be passed as $1 to
+the shell, to preserve the surrounding logic and keep the patch minimal.
+Hardcode /bin/sh as the shell since that's what popen(3) claims to do.
+
+Don't bother with write mode support like the original function, though,
+it can always be added later if this new version turns out to be useful
+elsewhere. Add also a pclose(3) equivalent, just for consistency, since
+the original call would probably work fine when passed the FILE stream
+created by us.
+
+Adjust the rpmuncompress output when in verbose/dry mode so that it is
+preserved exactly. That means, generate the shell command again but this
+time with the actual filename (enclosed in single quotes), and use that
+for printing. Note that this has to happen in *addition* to the default
+command that uses $1 since we need both variants when in verbose mode.
+
+Enable the tests added in the previous commit as they are now expected
+to pass.
+
+Long-term, a better solution would be to split the shell commands such
+that the simple program invocations that need the filename can be done
+with a plain fork-exec instead of popen(3), or better yet, to just port
+the internals to libarchive. But either is much more complex and would
+make the patch more difficult to backport, so let's just stick with the
+uglier fix for now.
+
+Fixes: CVE-2026-84837, CVE-2026-84838
+
+Backported from commit 7a4111bc5db4053e5381b65306903837763e7f11:
+
+- This codebase is only affected by CVE-2026-84837 (rpmbuild -ts), that
+ is, in the getTarSpec() function, since the rpmuncompress utility
+ isn't present yet.
+
+- Obtain the uncompress command line separately by using the newly added
+ rpmGetArchiver() function. This is needed in order to prevent the
+ macro injection flaw since the %{uncompress} macro also does the
+ detection (and thus requires an actual filename on disk to open),
+ unlike in the later versions where it merely expands to the
+ rpmuncompress path.
+
+- Log a warning (but don't fail) if the archiver couldn't be detected:
+ this would have previously generated an empty command when using the
+ %{uncompress} macro, so it's a nice bonus.
+---
+ cliutils.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
+ cliutils.h | 7 +++++++
+ rpmbuild.c | 12 +++++++++---
+ 3 files changed, 64 insertions(+), 3 deletions(-)
+
+diff --git a/cliutils.c b/cliutils.c
+index 772a105ec..2231ed1f1 100644
+--- a/cliutils.c
++++ b/cliutils.c
+@@ -86,3 +86,51 @@ int finishPipe(void)
+ }
+ return rc;
+ }
++
++FILE* rpopen(const char *cmd, const char *arg)
++{
++ FILE *stream = NULL;
++ ARGV_t argv = NULL;
++ int pipefd[2];
++ pid_t pid;
++
++ if (pipe(pipefd) < 0)
++ goto exit;
++
++ argvAdd(&argv, "/bin/sh");
++ argvAdd(&argv, "-c");
++ argvAdd(&argv, cmd);
++ argvAdd(&argv, "sh");
++ argvAdd(&argv, arg);
++
++ if ((pid = fork()) == 0) {
++ dup2(pipefd[1], STDOUT_FILENO);
++ close(pipefd[0]);
++ execv(argv[0], argv);
++ _exit(EXIT_FAILURE);
++ } else if (pid == -1) {
++ goto exit;
++ }
++
++ close(pipefd[1]);
++ stream = fdopen(pipefd[0], "r");
++
++exit:
++ argvFree(argv);
++ return stream;
++}
++
++int rpclose(FILE *stream)
++{
++ int rc = -1;
++ int status;
++
++ if ((waitpid(-1, &status, 0) == -1) || !WIFEXITED(status))
++ goto exit;
++
++ rc = WEXITSTATUS(status);
++
++exit:
++ fclose(stream);
++ return rc;
++}
+diff --git a/cliutils.h b/cliutils.h
+index b5deee1ba..cda4bebdf 100644
+--- a/cliutils.h
++++ b/cliutils.h
+@@ -22,4 +22,11 @@ int initPipe(void);
+
+ int finishPipe(void);
+
++/*
++ * A safe, read-only variant of popen(3) that passes untrusted input (arg) as a
++ * positional argument to sh(1) where the command (cmd) can read it via $1.
++ */
++FILE *rpopen(const char *cmd, const char *arg);
++int rpclose(FILE *stream);
++
+ #endif /* _CLIUTIL_H */
+diff --git a/rpmbuild.c b/rpmbuild.c
+index 8dbd06d5f..ddc1e0750 100644
+--- a/rpmbuild.c
++++ b/rpmbuild.c
+@@ -15,6 +15,7 @@
+ #include "lib/signature.h"
+ #include "cliutils.h"
+
++#include "rpmio/rpmmacro_internal.h"
+ #include "debug.h"
+
+ static struct rpmBuildArguments_s rpmBTArgs;
+@@ -353,13 +354,18 @@ static char * getTarSpec(const char *arg)
+ for (spec = tryspec; *spec != NULL; spec++) {
+ FILE *fp;
+ char *cmd;
++ const char *uncmd = NULL;
+ int specfiles = 0;
+
+- cmd = rpmExpand("%{uncompress: ", arg, "} | ",
++ if (rpmGetArchiver(arg, &uncmd))
++ rpmlog(RPMLOG_WARNING,
++ _("Failed to detect archive type: %s\n"), arg);
++
++ cmd = rpmExpand(uncmd, "\"$1\" | ",
+ "%{__tar} xOvof - --wildcards ", *spec,
+ " 2>&1 > ", specFile, NULL);
+
+- if (!(fp = popen(cmd, "r"))) {
++ if (!(fp = rpopen(cmd, arg))) {
+ rpmlog(RPMLOG_ERR, _("Failed to open tar pipe: %m\n"));
+ } else {
+ char *fok;
+@@ -372,7 +378,7 @@ static char * getTarSpec(const char *arg)
+ }
+ specfiles++;
+ }
+- pclose(fp);
++ rpclose(fp);
+ gotspec = (specfiles == 1) && isSpecFile(specFile);
+ if (specfiles > 1) {
+ rpmlog(RPMLOG_ERR, _("Found more than one spec file in %s\n"), arg);
+--
+2.56.0
+
diff --git a/0003-Add-a-variable-argument-list-to-rpopen.patch b/0003-Add-a-variable-argument-list-to-rpopen.patch
new file mode 100644
index 0000000..19a5b98
--- /dev/null
+++ b/0003-Add-a-variable-argument-list-to-rpopen.patch
@@ -0,0 +1,82 @@
+From b0ed834235f910a5b7ebe56daa6e0e034bb41349 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Thu, 22 Oct 2026 09:11:51 +0200
+Subject: [PATCH 3/3] Add a variable argument list to rpopen()
+
+Accept multiple positional arguments for the shell instead of just one.
+This will be needed in the next commits.
+
+No functional change.
+
+Backported from commit e7a086a8e203f123fbd37ead9b52188d1302ce0e.
+---
+ cliutils.c | 9 +++++++--
+ cliutils.h | 7 ++++---
+ rpmbuild.c | 2 +-
+ 3 files changed, 12 insertions(+), 6 deletions(-)
+
+diff --git a/cliutils.c b/cliutils.c
+index 2231ed1f1..6547e7bdb 100644
+--- a/cliutils.c
++++ b/cliutils.c
+@@ -87,10 +87,11 @@ int finishPipe(void)
+ return rc;
+ }
+
+-FILE* rpopen(const char *cmd, const char *arg)
++FILE* rpopen(const char *cmd, const char *arg, ...)
+ {
+ FILE *stream = NULL;
+ ARGV_t argv = NULL;
++ va_list ap;
+ int pipefd[2];
+ pid_t pid;
+
+@@ -101,7 +102,11 @@ FILE* rpopen(const char *cmd, const char *arg)
+ argvAdd(&argv, "-c");
+ argvAdd(&argv, cmd);
+ argvAdd(&argv, "sh");
+- argvAdd(&argv, arg);
++
++ va_start(ap, arg);
++ for (const char *s = arg; s != NULL; s = va_arg(ap, const char *))
++ argvAdd(&argv, s);
++ va_end(ap);
+
+ if ((pid = fork()) == 0) {
+ dup2(pipefd[1], STDOUT_FILENO);
+diff --git a/cliutils.h b/cliutils.h
+index cda4bebdf..4aee1ae72 100644
+--- a/cliutils.h
++++ b/cliutils.h
+@@ -23,10 +23,11 @@ int initPipe(void);
+ int finishPipe(void);
+
+ /*
+- * A safe, read-only variant of popen(3) that passes untrusted input (arg) as a
+- * positional argument to sh(1) where the command (cmd) can read it via $1.
++ * A safe, read-only variant of popen(3) that passes untrusted input (args) as
++ * positional arguments to sh(1) where the command (cmd) can read them via $1,
++ * $2, and so on.
+ */
+-FILE *rpopen(const char *cmd, const char *arg);
++FILE *rpopen(const char *cmd, const char *arg, ...) RPM_GNUC_NULL_TERMINATED;
+ int rpclose(FILE *stream);
+
+ #endif /* _CLIUTIL_H */
+diff --git a/rpmbuild.c b/rpmbuild.c
+index ddc1e0750..63872325d 100644
+--- a/rpmbuild.c
++++ b/rpmbuild.c
+@@ -365,7 +365,7 @@ static char * getTarSpec(const char *arg)
+ "%{__tar} xOvof - --wildcards ", *spec,
+ " 2>&1 > ", specFile, NULL);
+
+- if (!(fp = rpopen(cmd, arg))) {
++ if (!(fp = rpopen(cmd, arg, NULL))) {
+ rpmlog(RPMLOG_ERR, _("Failed to open tar pipe: %m\n"));
+ } else {
+ char *fok;
+--
+2.56.0
+
diff --git a/rpm.spec b/rpm.spec
index 759c8f1..4425a73 100644
--- a/rpm.spec
+++ b/rpm.spec
@@ -32,7 +32,7 @@
%global rpmver 4.16.1.3
#global snapver rc1
-%global rel 41
+%global rel 42
%global sover 9
%global srcver %{rpmver}%{?snapver:-%{snapver}}
@@ -124,6 +124,9 @@ Patch155: 0001-Allow-an-optional-override-clock-for-deterministic-t.patch
Patch156: 0001-Improve-error-handling-on-keystore-load.patch
Patch157: 0001-Sort-files-before-passing-to-file-attribute-dependen.patch
Patch158: 0001-Prevent-command-injection-via-rpmbuild-t.patch
+Patch159: 0001-Extract-archiver-detection-out-of-doUncompress.patch
+Patch160: 0002-Prevent-command-injection-via-rpmbuild-t-filename.patch
+Patch161: 0003-Add-a-variable-argument-list-to-rpopen.patch
# These are not yet upstream
Patch906: rpm-4.7.1-geode-i686.patch
@@ -676,6 +679,9 @@ fi
%doc doc/librpm/html/*
%changelog
+* Mon Oct 26 2026 Michal Domonkos <mdomonko@redhat.com> - 4.16.1.3-42
+- CVE-2026-84837: Prevent command injection via rpmbuild -t filename (RHEL-288157)
+
* Tue Oct 13 2026 Michal Domonkos <mdomonko@redhat.com> - 4.16.1.3-41
- CVE-2026-78367: Prevent command injection via rpmbuild -t (RHEL-282745)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-13 18:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 18:33 [rpms/python3-rpm] epel9: CVE-2026-84837: Prevent command injection via rpmbuild -t filename Michal Domonkos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox