public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/python3-rpm] epel10.3: Prevent cmd injection via rpmbuild/rpmuncompress
@ 2026-11-16 11:10 Michal Domonkos
  0 siblings, 0 replies; only message in thread
From: Michal Domonkos @ 2026-11-16 11:10 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : rpms/python3-rpm
            Branch : epel10.3
            Commit : 830592b71a7e377a21c26015ea0c9172d36b4fc0
            Author : Michal Domonkos <mdomonko@redhat.com>
            Date   : 2026-10-22T18:05:12+02:00
            Stats  : +978/-1 in 11 file(s)
            URL    : https://src.fedoraproject.org/rpms/python3-rpm/c/830592b71a7e377a21c26015ea0c9172d36b4fc0?branch=epel10.3

            Log:
            Prevent cmd injection via rpmbuild/rpmuncompress

This fixes the following three CVEs:
- CVE-2026-84233
- CVE-2026-84837
- CVE-2026-84838

Resolves: RHEL-288155 RHEL-288156 RHEL-288158

---
diff --git a/0001-Add-a-variable-argument-list-to-rpopen.patch b/0001-Add-a-variable-argument-list-to-rpopen.patch
new file mode 100644
index 0000000..0710ea0
--- /dev/null
+++ b/0001-Add-a-variable-argument-list-to-rpopen.patch
@@ -0,0 +1,96 @@
+From 6edebd240f546525762887df73f4e1e05a896ede Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Thu, 22 Oct 2026 09:11:51 +0200
+Subject: [PATCH 1/5] 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.
+
+(cherry picked from commit e7a086a8e203f123fbd37ead9b52188d1302ce0e)
+---
+ tools/cliutils.c      | 9 +++++++--
+ tools/cliutils.h      | 7 ++++---
+ tools/rpmbuild.c      | 2 +-
+ tools/rpmuncompress.c | 2 +-
+ 4 files changed, 13 insertions(+), 7 deletions(-)
+
+diff --git a/tools/cliutils.c b/tools/cliutils.c
+index 3be9b7233..bf135ba40 100644
+--- a/tools/cliutils.c
++++ b/tools/cliutils.c
+@@ -84,10 +84,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;
+ 
+@@ -98,7 +99,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/tools/cliutils.h b/tools/cliutils.h
+index cda4bebdf..4aee1ae72 100644
+--- a/tools/cliutils.h
++++ b/tools/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/tools/rpmbuild.c b/tools/rpmbuild.c
+index c5fbb085b..5074d61a7 100644
+--- a/tools/rpmbuild.c
++++ b/tools/rpmbuild.c
+@@ -388,7 +388,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;
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index c0a4908ea..8b60c718d 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -280,7 +280,7 @@ int main(int argc, char *argv[])
+ 	    goto exit;
+ 	}
+ 
+-	inp = rpopen(cmd, arg);
++	inp = rpopen(cmd, arg, NULL);
+ 	if (inp) {
+ 	    int status, c;
+ 	    while ((c = fgetc(inp)) != EOF)
+-- 
+2.56.0
+

diff --git a/0001-Fix-missing-quotes-in-doUncompress.patch b/0001-Fix-missing-quotes-in-doUncompress.patch
new file mode 100644
index 0000000..8e16482
--- /dev/null
+++ b/0001-Fix-missing-quotes-in-doUncompress.patch
@@ -0,0 +1,33 @@
+From 6486089ef52a3734aa81a833bfcb5ee367d52231 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Mon, 14 Sep 2026 16:58:04 +0200
+Subject: [PATCH 1/4] Fix missing quotes in doUncompress()
+
+Escape the filename in single quotes like we already do in doUntar(), to
+fix the default (non-extraction) mode of operation in rpmuncompress for
+filenames with spaces and/or metacharacters in them.
+
+Add a test, and adjust the existing ones that use --dry-run since the
+output now contains a quoted argument.
+
+(backported from commit 503f4c9fcafb1999b1d200613425087ef40ad548)
+---
+ tools/rpmuncompress.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index 7233e4bb9..245d86ed9 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -82,7 +82,7 @@ static char *doUncompress(const char *fn)
+ 	cmd = rpmExpand(at->setTZ ? "TZ=UTC " : "",
+ 			at->cmd, " ", at->unpack, NULL);
+ 	/* path must not be expanded */
+-	cmd = rstrscat(&cmd, " ", fn, NULL);
++	cmd = rstrscat(&cmd, " '", fn, "'", NULL);
+     }
+     return cmd;
+ }
+-- 
+2.56.0
+

diff --git a/0001-Prevent-macro-injection-via-.gem-filenames.patch b/0001-Prevent-macro-injection-via-.gem-filenames.patch
new file mode 100644
index 0000000..7f64116
--- /dev/null
+++ b/0001-Prevent-macro-injection-via-.gem-filenames.patch
@@ -0,0 +1,45 @@
+From b2882f8d603b4f3dc34add68eeff296d3d0a1c3a Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Wed, 21 Oct 2026 13:43:03 +0200
+Subject: [PATCH] Prevent macro injection via .gem filenames
+
+When unpacking a GEM archive, its basename gets macro-expanded via
+rpmGetPath(), which allows for RPM macro injection via a crafted
+filename.
+
+Fix that by appending the .gemspec suffix in the subsequent rasprintf()
+call instead of using rpmGetPath() for it.
+
+Enable the respective test as well.
+
+Fixes: CVE-2026-84233
+---
+ tools/rpmuncompress.c | 7 ++-----
+ 1 file changed, 2 insertions(+), 5 deletions(-)
+
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index e555e0dd7..c0a4908ea 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -211,16 +211,13 @@ static char *doUntar(archiveType *at, int sr, const char *fn, const char *arg)
+ 	    const char *bn = basename(tmp);
+ 	    size_t nvlen = strlen(bn) - 3;
+ 	    char *gem = rpmGetPath("%{__gem}", NULL);
+-	    char *gemspec = NULL;
+ 	    char gemnameversion[nvlen];
+ 
+ 	    rstrlcpy(gemnameversion, bn, nvlen);
+-	    gemspec = rpmGetPath("", gemnameversion, ".gemspec", NULL);
+ 
+-	    rasprintf(&buf, "%s %s && %s spec %s --ruby > '%s'",
+-			zipper, arg, gem, arg, gemspec);
++	    rasprintf(&buf, "%s %s && %s spec %s --ruby > '%s.gemspec'",
++			zipper, arg, gem, arg, gemnameversion);
+ 
+-	    free(gemspec);
+ 	    free(gem);
+ 	    free(tmp);
+ 	} else {
+-- 
+2.56.0
+

diff --git a/0002-Define-a-nicer-alias-for-the-archiveType-struct.patch b/0002-Define-a-nicer-alias-for-the-archiveType-struct.patch
new file mode 100644
index 0000000..9b55bfc
--- /dev/null
+++ b/0002-Define-a-nicer-alias-for-the-archiveType-struct.patch
@@ -0,0 +1,77 @@
+From f2fe515e29b97cdcf7f03b06220982171105dd30 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Fri, 25 Sep 2026 13:16:13 +0200
+Subject: [PATCH 2/4] Define a nicer alias for the archiveType struct
+
+We are going to use this type in a quite bit more places in the next
+commits, so make it shorter.
+
+No functional change.
+
+(cherry picked from commit 8d532fe23f37d23cff30b514ca40ff232410787a)
+---
+ tools/rpmuncompress.c | 16 +++++++++-------
+ 1 file changed, 9 insertions(+), 7 deletions(-)
+
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index 245d86ed9..d355b736d 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -34,7 +34,7 @@ static struct poptOption optionsTable[] = {
+     POPT_TABLEEND
+ };
+ 
+-struct archiveType_s {
++typedef const struct archiveType_s {
+     int compressed;
+     int extractable;
+     const char *cmd;
+@@ -42,7 +42,9 @@ struct archiveType_s {
+     const char *quiet;
+     const char *dest;
+     int setTZ;
+-} archiveTypes[] = {
++} archiveType;
++
++static archiveType const archiveTypes[] = {
+     { COMPRESSED_NOT,	0,	"%{__cat}" ,	"",		"", "", 0 },
+     { COMPRESSED_OTHER,	0,	"%{__gzip}",	"-dc",		"", "", 0 },
+     { COMPRESSED_BZIP2,	0,	"%{__bzip2}",	"-dc",		"", "", 0 },
+@@ -57,13 +59,13 @@ struct archiveType_s {
+     { -1,		0,	NULL,		NULL,		NULL, 0 },
+ };
+ 
+-static const struct archiveType_s *getArchiver(const char *fn)
++static archiveType *getArchiver(const char *fn)
+ {
+-    const struct archiveType_s *archiver = NULL;
++    archiveType *archiver = NULL;
+     rpmCompressedMagic compressed = COMPRESSED_NOT;
+ 
+     if (rpmFileIsCompressed(fn, &compressed) == 0) {
+-	for (const struct archiveType_s *at = archiveTypes; at->cmd; at++) {
++	for (archiveType *at = archiveTypes; at->cmd; at++) {
+ 	    if (compressed == at->compressed) {
+ 		archiver = at;
+ 		break;
+@@ -77,7 +79,7 @@ static const struct archiveType_s *getArchiver(const char *fn)
+ static char *doUncompress(const char *fn)
+ {
+     char *cmd = NULL;
+-    const struct archiveType_s *at = getArchiver(fn);
++    archiveType *at = getArchiver(fn);
+     if (at) {
+ 	cmd = rpmExpand(at->setTZ ? "TZ=UTC " : "",
+ 			at->cmd, " ", at->unpack, NULL);
+@@ -152,7 +154,7 @@ afree:
+ 
+ static char *doUntar(const char *fn)
+ {
+-    const struct archiveType_s *at = NULL;
++    archiveType *at = NULL;
+     char *buf = NULL;
+     char *tar = NULL;
+     const char *taropts = verbose ? "-xvvof" : "-xof";
+-- 
+2.56.0
+

diff --git a/0002-Let-callers-pass-the-basename-to-doUntar.patch b/0002-Let-callers-pass-the-basename-to-doUntar.patch
new file mode 100644
index 0000000..49572d3
--- /dev/null
+++ b/0002-Let-callers-pass-the-basename-to-doUntar.patch
@@ -0,0 +1,110 @@
+From 254716f8dbf1200bc75133417cc704efdc55f0d6 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Thu, 22 Oct 2026 09:53:55 +0200
+Subject: [PATCH 2/5] Let callers pass the basename to doUntar()
+
+No functional change, just preparing the ground for the next commits.
+
+Backported from commit 41f53717ec4c3e16ab6fb18d032d17fcfcb97781:
+
+Add a plain C variant of std::filesystem::path::stem() that allocates
+the basename on the heap, for consistency with the surrounding code.
+---
+ tools/rpmuncompress.c | 32 +++++++++++++++++++++-----------
+ 1 file changed, 21 insertions(+), 11 deletions(-)
+
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index 8b60c718d..923e66db2 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -152,7 +152,7 @@ afree:
+ 	return ret;
+ }
+ 
+-static char *doUntar(archiveType *at, int sr, const char *fn, const char *arg)
++static char *doUntar(archiveType *at, int sr, const char *bn, const char *arg)
+ {
+     char *buf = NULL;
+     char *tar = NULL;
+@@ -207,19 +207,12 @@ static char *doUntar(archiveType *at, int sr, const char *fn, const char *arg)
+ 	if (needtar) {
+ 	    rasprintf(&buf, "%s %s %s | %s %s - %s", mkdir, zipper, arg, tar, taropts, stripcd);
+ 	} else if (at->compressed == COMPRESSED_GEM) {
+-	    char *tmp = xstrdup(fn);
+-	    const char *bn = basename(tmp);
+-	    size_t nvlen = strlen(bn) - 3;
+ 	    char *gem = rpmGetPath("%{__gem}", NULL);
+-	    char gemnameversion[nvlen];
+-
+-	    rstrlcpy(gemnameversion, bn, nvlen);
+ 
+ 	    rasprintf(&buf, "%s %s && %s spec %s --ruby > '%s.gemspec'",
+-			zipper, arg, gem, arg, gemnameversion);
++			zipper, arg, gem, arg, bn);
+ 
+ 	    free(gem);
+-	    free(tmp);
+ 	} else {
+ 	    rasprintf(&buf, "%s%s %s %s", mkdir, zipper, arg, stripcd);
+ 	}
+@@ -235,12 +228,27 @@ exit:
+     return buf;
+ }
+ 
++/* Return the basename of the given filename, stripped of its suffix. */
++static char *getStem(const char *fn)
++{
++    char *tmp = xstrdup(fn);
++    const char *bn = basename(tmp);
++    size_t stemlen = strlen(bn) - 3;
++    char *stem = xmalloc(stemlen);
++
++    rstrlcpy(stem, bn, stemlen);
++    free(tmp);
++
++    return stem;
++}
++
+ int main(int argc, char *argv[])
+ {
+     int ec = EXIT_FAILURE;
+     poptContext optCon = NULL;
+     const char *arg = NULL;
+     const char *fnarg = "\"$1\"";
++    char *bn = NULL;
+     char *cmd = NULL;
+     archiveType *at = NULL;
+     int sr = 0;
+@@ -253,10 +261,11 @@ int main(int argc, char *argv[])
+     }
+ 
+     at = getArchiver(arg);
++    bn = getStem(arg);
+     if (extract) {
+ 	if (dstpath)
+ 	    sr = singleRoot(arg);
+-	cmd = doUntar(at, sr, arg, fnarg);
++	cmd = doUntar(at, sr, bn, fnarg);
+     } else {
+ 	cmd = doUncompress(at, arg, fnarg);
+     }
+@@ -268,7 +277,7 @@ int main(int argc, char *argv[])
+ 	    char *dryarg = NULL;
+ 	    char *drycmd = NULL;
+ 	    rasprintf(&dryarg, "'%s'", arg);
+-	    drycmd = extract ? doUntar(at, sr, arg, dryarg) :
++	    drycmd = extract ? doUntar(at, sr, bn, dryarg) :
+ 			       doUncompress(at, arg, dryarg);
+ 	    fprintf(stderr, "%s\n", drycmd);
+ 	    free(drycmd);
+@@ -292,6 +301,7 @@ int main(int argc, char *argv[])
+     }
+ 
+ exit:
++    free(bn);
+     free(cmd);
+     rpmcliFini(optCon);
+     return ec;
+-- 
+2.56.0
+

diff --git a/0003-Drop-leftover-filename-arg-from-doUncompress.patch b/0003-Drop-leftover-filename-arg-from-doUncompress.patch
new file mode 100644
index 0000000..0f52174
--- /dev/null
+++ b/0003-Drop-leftover-filename-arg-from-doUncompress.patch
@@ -0,0 +1,49 @@
+From cc53ddd42c3255f4beb5bb514869c78b8147411f Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Thu, 22 Oct 2026 13:55:57 +0200
+Subject: [PATCH 3/5] Drop leftover filename arg from doUncompress()
+
+This should've been part of commit
+7a4111bc5db4053e5381b65306903837763e7f11.
+
+No functional change.
+
+Backported from commit 32c6dc786e09a3ea47a35f3657ca51e807ad0b20.
+---
+ tools/rpmuncompress.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index 923e66db2..decf7d792 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -77,7 +77,7 @@ static archiveType *getArchiver(const char *fn)
+     return archiver;
+ }
+ 
+-static char *doUncompress(archiveType *at, const char *fn, const char *arg)
++static char *doUncompress(archiveType *at, const char *arg)
+ {
+     char *cmd = NULL;
+     if (at) {
+@@ -267,7 +267,7 @@ int main(int argc, char *argv[])
+ 	    sr = singleRoot(arg);
+ 	cmd = doUntar(at, sr, bn, fnarg);
+     } else {
+-	cmd = doUncompress(at, arg, fnarg);
++	cmd = doUncompress(at, fnarg);
+     }
+ 
+     if (cmd) {
+@@ -278,7 +278,7 @@ int main(int argc, char *argv[])
+ 	    char *drycmd = NULL;
+ 	    rasprintf(&dryarg, "'%s'", arg);
+ 	    drycmd = extract ? doUntar(at, sr, bn, dryarg) :
+-			       doUncompress(at, arg, dryarg);
++			       doUncompress(at, dryarg);
+ 	    fprintf(stderr, "%s\n", drycmd);
+ 	    free(drycmd);
+ 	    free(dryarg);
+-- 
+2.56.0
+

diff --git a/0003-Split-out-archiver-and-singleroot-in-rpmuncompress.patch b/0003-Split-out-archiver-and-singleroot-in-rpmuncompress.patch
new file mode 100644
index 0000000..e795a44
--- /dev/null
+++ b/0003-Split-out-archiver-and-singleroot-in-rpmuncompress.patch
@@ -0,0 +1,90 @@
+From 7513fd71e1ce84e1f64b3d29e6de8089f0fd01d9 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Mon, 14 Sep 2026 16:42:13 +0200
+Subject: [PATCH 3/4] Split out archiver and singleroot in rpmuncompress
+
+Do the archiver and singleroot detection in main(), before calling the
+doUncompress() or doUntar() functions, and pass both instances to them
+instead. This will allow us to re-run these two functions more cheaply,
+which will be done in the next commits.
+
+No functional change.
+
+(backported from commit 799bb0cc898b85b0cbb5048fde4dd66bccdcf0de)
+---
+ tools/rpmuncompress.c | 23 +++++++++++++++--------
+ 1 file changed, 15 insertions(+), 8 deletions(-)
+
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index d355b736d..249bcfa3a 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -76,10 +76,9 @@ static archiveType *getArchiver(const char *fn)
+     return archiver;
+ }
+ 
+-static char *doUncompress(const char *fn)
++static char *doUncompress(archiveType *at, const char *fn)
+ {
+     char *cmd = NULL;
+-    archiveType *at = getArchiver(fn);
+     if (at) {
+ 	cmd = rpmExpand(at->setTZ ? "TZ=UTC " : "",
+ 			at->cmd, " ", at->unpack, NULL);
+@@ -152,9 +151,8 @@ afree:
+ 	return ret;
+ }
+ 
+-static char *doUntar(const char *fn)
++static char *doUntar(archiveType *at, int sr, const char *fn)
+ {
+-    archiveType *at = NULL;
+     char *buf = NULL;
+     char *tar = NULL;
+     const char *taropts = verbose ? "-xvvof" : "-xof";
+@@ -162,14 +160,12 @@ static char *doUntar(const char *fn)
+     char *stripcd = NULL;
+     int needtar = 0;
+ 
+-    if ((at = getArchiver(fn)) == NULL)
++    if (at == NULL)
+ 	goto exit;
+ 
+     needtar = (at->extractable == 0);
+ 
+     if (dstpath) {
+-	int sr = singleRoot(fn);
+-
+ 	/* if the archive has multiple entries, just extract it into the
+ 	 * specified destination path, otherwise also strip the first path
+ 	 * entry
+@@ -246,6 +242,9 @@ int main(int argc, char *argv[])
+     int ec = EXIT_FAILURE;
+     poptContext optCon = NULL;
+     const char *arg = NULL;
++    char *cmd = NULL;
++    archiveType *at = NULL;
++    int sr = 0;
+ 
+     optCon = rpmcliInit(argc, argv, optionsTable);
+ 
+@@ -254,7 +253,15 @@ int main(int argc, char *argv[])
+ 	goto exit;
+     }
+ 
+-    char *cmd = extract ? doUntar(arg) : doUncompress(arg);
++    at = getArchiver(arg);
++    if (extract) {
++	if (dstpath)
++	    sr = singleRoot(arg);
++	cmd = doUntar(at, sr, arg);
++    } else {
++	cmd = doUncompress(at, arg);
++    }
++
+     if (cmd) {
+ 	FILE *inp = NULL;
+ 
+-- 
+2.56.0
+

diff --git a/0004-Prevent-command-injection-via-rpmbuild-t-filename.patch b/0004-Prevent-command-injection-via-rpmbuild-t-filename.patch
new file mode 100644
index 0000000..97de12d
--- /dev/null
+++ b/0004-Prevent-command-injection-via-rpmbuild-t-filename.patch
@@ -0,0 +1,292 @@
+From c98ecba7245ab622cddcc1810246a2ed1c963239 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Mon, 7 Sep 2026 14:41:39 +0200
+Subject: [PATCH 4/4] 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)
+---
+ tools/CMakeLists.txt  |  2 +-
+ tools/cliutils.c      | 48 +++++++++++++++++++++++++++++++++++++++++++
+ tools/cliutils.h      |  7 +++++++
+ tools/rpmbuild.c      |  6 +++---
+ tools/rpmuncompress.c | 38 +++++++++++++++++++++-------------
+ 5 files changed, 83 insertions(+), 18 deletions(-)
+
+diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
+index ea452e738..ba2d1706f 100644
+--- a/tools/CMakeLists.txt
++++ b/tools/CMakeLists.txt
+@@ -11,7 +11,7 @@ add_executable(rpmspec rpmspec.c cliutils)
+ add_executable(rpmdeps rpmdeps.c)
+ add_executable(rpmgraph rpmgraph.c)
+ add_executable(rpmlua rpmlua.c)
+-add_executable(rpmuncompress rpmuncompress.c)
++add_executable(rpmuncompress rpmuncompress.c cliutils)
+ add_executable(rpmdump rpmdump.c)
+ 
+ target_link_libraries(rpmsign PRIVATE librpmsign)
+diff --git a/tools/cliutils.c b/tools/cliutils.c
+index dc630bc8d..3be9b7233 100644
+--- a/tools/cliutils.c
++++ b/tools/cliutils.c
+@@ -83,3 +83,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/tools/cliutils.h b/tools/cliutils.h
+index b5deee1ba..cda4bebdf 100644
+--- a/tools/cliutils.h
++++ b/tools/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/tools/rpmbuild.c b/tools/rpmbuild.c
+index c86a3ab23..c5fbb085b 100644
+--- a/tools/rpmbuild.c
++++ b/tools/rpmbuild.c
+@@ -384,11 +384,11 @@ static char * getTarSpec(const char *arg)
+ 	char *cmd;
+ 	int specfiles = 0;
+ 
+-	cmd = rpmExpand("%{uncompress: ", arg, "} | ",
++	cmd = rpmExpand("%{uncompress: \"$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;
+@@ -401,7 +401,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);
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index 249bcfa3a..e555e0dd7 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -12,6 +12,7 @@
+ #include <rpm/rpmcli.h>
+ #include <rpm/rpmstring.h>
+ 
++#include "cliutils.h"
+ #include "debug.h"
+ 
+ static int verbose = 0;
+@@ -76,14 +77,14 @@ static archiveType *getArchiver(const char *fn)
+     return archiver;
+ }
+ 
+-static char *doUncompress(archiveType *at, const char *fn)
++static char *doUncompress(archiveType *at, const char *fn, const char *arg)
+ {
+     char *cmd = NULL;
+     if (at) {
+ 	cmd = rpmExpand(at->setTZ ? "TZ=UTC " : "",
+ 			at->cmd, " ", at->unpack, NULL);
+ 	/* path must not be expanded */
+-	cmd = rstrscat(&cmd, " '", fn, "'", NULL);
++	cmd = rstrscat(&cmd, " ", arg, NULL);
+     }
+     return cmd;
+ }
+@@ -151,7 +152,7 @@ afree:
+ 	return ret;
+ }
+ 
+-static char *doUntar(archiveType *at, int sr, const char *fn)
++static char *doUntar(archiveType *at, int sr, const char *fn, const char *arg)
+ {
+     char *buf = NULL;
+     char *tar = NULL;
+@@ -204,7 +205,7 @@ static char *doUntar(archiveType *at, int sr, const char *fn)
+ 			   at->cmd, " ", at->unpack, " ",
+ 			   verbose ? "" : at->quiet, NULL);
+ 	if (needtar) {
+-	    rasprintf(&buf, "%s %s '%s' | %s %s - %s", mkdir, zipper, fn, tar, taropts, stripcd);
++	    rasprintf(&buf, "%s %s %s | %s %s - %s", mkdir, zipper, arg, tar, taropts, stripcd);
+ 	} else if (at->compressed == COMPRESSED_GEM) {
+ 	    char *tmp = xstrdup(fn);
+ 	    const char *bn = basename(tmp);
+@@ -216,18 +217,18 @@ static char *doUntar(archiveType *at, int sr, const char *fn)
+ 	    rstrlcpy(gemnameversion, bn, nvlen);
+ 	    gemspec = rpmGetPath("", gemnameversion, ".gemspec", NULL);
+ 
+-	    rasprintf(&buf, "%s '%s' && %s spec '%s' --ruby > '%s'",
+-			zipper, fn, gem, fn, gemspec);
++	    rasprintf(&buf, "%s %s && %s spec %s --ruby > '%s'",
++			zipper, arg, gem, arg, gemspec);
+ 
+ 	    free(gemspec);
+ 	    free(gem);
+ 	    free(tmp);
+ 	} else {
+-	    rasprintf(&buf, "%s%s '%s' %s", mkdir, zipper, fn, stripcd);
++	    rasprintf(&buf, "%s%s %s %s", mkdir, zipper, arg, stripcd);
+ 	}
+ 	free(zipper);
+     } else {
+-	rasprintf(&buf, "%s %s %s '%s' %s", mkdir, tar, taropts, fn, stripcd);
++	rasprintf(&buf, "%s %s %s %s %s", mkdir, tar, taropts, arg, stripcd);
+     }
+ 
+ exit:
+@@ -242,6 +243,7 @@ int main(int argc, char *argv[])
+     int ec = EXIT_FAILURE;
+     poptContext optCon = NULL;
+     const char *arg = NULL;
++    const char *fnarg = "\"$1\"";
+     char *cmd = NULL;
+     archiveType *at = NULL;
+     int sr = 0;
+@@ -257,28 +259,36 @@ int main(int argc, char *argv[])
+     if (extract) {
+ 	if (dstpath)
+ 	    sr = singleRoot(arg);
+-	cmd = doUntar(at, sr, arg);
++	cmd = doUntar(at, sr, arg, fnarg);
+     } else {
+-	cmd = doUncompress(at, arg);
++	cmd = doUncompress(at, arg, fnarg);
+     }
+ 
+     if (cmd) {
+ 	FILE *inp = NULL;
+ 
+-	if (verbose || dryrun)
+-	    fprintf(stderr, "%s\n", cmd);
++	if (verbose || dryrun) {
++	    char *dryarg = NULL;
++	    char *drycmd = NULL;
++	    rasprintf(&dryarg, "'%s'", arg);
++	    drycmd = extract ? doUntar(at, sr, arg, dryarg) :
++			       doUncompress(at, arg, dryarg);
++	    fprintf(stderr, "%s\n", drycmd);
++	    free(drycmd);
++	    free(dryarg);
++	}
+ 
+ 	if (dryrun) {
+ 	    ec = EXIT_SUCCESS;
+ 	    goto exit;
+ 	}
+ 
+-	inp = popen(cmd, "r");
++	inp = rpopen(cmd, arg);
+ 	if (inp) {
+ 	    int status, c;
+ 	    while ((c = fgetc(inp)) != EOF)
+ 		fputc(c, stdout);
+-	    status = pclose(inp);
++	    status = rpclose(inp);
+ 	    if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+ 		ec = EXIT_SUCCESS;
+ 	}
+-- 
+2.56.0
+

diff --git a/0004-Rename-a-parameter-name-in-doUntar.patch b/0004-Rename-a-parameter-name-in-doUntar.patch
new file mode 100644
index 0000000..adb44e4
--- /dev/null
+++ b/0004-Rename-a-parameter-name-in-doUntar.patch
@@ -0,0 +1,77 @@
+From 5978f67c6e600fb39aade9c0dc53beb4870fab95 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Thu, 22 Oct 2026 09:56:27 +0200
+Subject: [PATCH 4/5] Rename a parameter name in doUntar()
+
+Now that the basename parameter is called "bn", rename "arg" (filename)
+to "fn" for consistency and readability. Do the same in the --dry-run
+branch while at it.
+
+No functional change.
+
+Backported from commit 1df4f546881b30251bfa0d281481607e49212074.
+---
+ tools/rpmuncompress.c | 20 ++++++++++----------
+ 1 file changed, 10 insertions(+), 10 deletions(-)
+
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index decf7d792..c99c334da 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -152,7 +152,7 @@ afree:
+ 	return ret;
+ }
+ 
+-static char *doUntar(archiveType *at, int sr, const char *bn, const char *arg)
++static char *doUntar(archiveType *at, int sr, const char *bn, const char *fn)
+ {
+     char *buf = NULL;
+     char *tar = NULL;
+@@ -205,20 +205,20 @@ static char *doUntar(archiveType *at, int sr, const char *bn, const char *arg)
+ 			   at->cmd, " ", at->unpack, " ",
+ 			   verbose ? "" : at->quiet, NULL);
+ 	if (needtar) {
+-	    rasprintf(&buf, "%s %s %s | %s %s - %s", mkdir, zipper, arg, tar, taropts, stripcd);
++	    rasprintf(&buf, "%s %s %s | %s %s - %s", mkdir, zipper, fn, tar, taropts, stripcd);
+ 	} else if (at->compressed == COMPRESSED_GEM) {
+ 	    char *gem = rpmGetPath("%{__gem}", NULL);
+ 
+ 	    rasprintf(&buf, "%s %s && %s spec %s --ruby > '%s.gemspec'",
+-			zipper, arg, gem, arg, bn);
++			zipper, fn, gem, fn, bn);
+ 
+ 	    free(gem);
+ 	} else {
+-	    rasprintf(&buf, "%s%s %s %s", mkdir, zipper, arg, stripcd);
++	    rasprintf(&buf, "%s%s %s %s", mkdir, zipper, fn, stripcd);
+ 	}
+ 	free(zipper);
+     } else {
+-	rasprintf(&buf, "%s %s %s %s %s", mkdir, tar, taropts, arg, stripcd);
++	rasprintf(&buf, "%s %s %s %s %s", mkdir, tar, taropts, fn, stripcd);
+     }
+ 
+ exit:
+@@ -274,14 +274,14 @@ int main(int argc, char *argv[])
+ 	FILE *inp = NULL;
+ 
+ 	if (verbose || dryrun) {
+-	    char *dryarg = NULL;
++	    char *dryfn = NULL;
+ 	    char *drycmd = NULL;
+-	    rasprintf(&dryarg, "'%s'", arg);
+-	    drycmd = extract ? doUntar(at, sr, bn, dryarg) :
+-			       doUncompress(at, dryarg);
++	    rasprintf(&dryfn, "'%s'", arg);
++	    drycmd = extract ? doUntar(at, sr, bn, dryfn) :
++			       doUncompress(at, dryfn);
+ 	    fprintf(stderr, "%s\n", drycmd);
+ 	    free(drycmd);
+-	    free(dryarg);
++	    free(dryfn);
+ 	}
+ 
+ 	if (dryrun) {
+-- 
+2.56.0
+

diff --git a/0005-Prevent-shell-injection-via-RubyGem-filenames.patch b/0005-Prevent-shell-injection-via-RubyGem-filenames.patch
new file mode 100644
index 0000000..04c59c3
--- /dev/null
+++ b/0005-Prevent-shell-injection-via-RubyGem-filenames.patch
@@ -0,0 +1,92 @@
+From 3d68be5f663e2174147f72eca55b0c6981ca0ad5 Mon Sep 17 00:00:00 2001
+From: Michal Domonkos <mdomonko@redhat.com>
+Date: Thu, 22 Oct 2026 10:46:11 +0200
+Subject: [PATCH 5/5] Prevent shell injection via RubyGem filenames
+
+Pass the archive's basename as a positional argument to the shell via
+rpopen() in order to avoid shell injection via crafted .gem filenames.
+This fixes a thinko in commit 7a4111bc5db4053e5381b65306903837763e7f11
+where this one remaining code path was missed.
+
+Make it the first positional argument ($1) and the existing filename the
+second ($2), to mirror the parameter order in doUntar().
+
+Adjust the --dry-run mode accordingly so that we print the real basename
+there. This has a cosmetic effect on the printed shell command: it moves
+the closing single quote in front of the .gemspec suffix, but since the
+suffix is controlled by us, it doesn't matter and the result would be
+the same as before if the user actually invoked the command. Therefore,
+just fix the test.
+
+Enable the respective test for this flaw as well.
+
+Related: CVE-2026-84838
+
+Backported from commit e95f1b29ae274620700d51d1741bf1392bfec0d8.
+---
+ tools/rpmuncompress.c | 14 +++++++++-----
+ 1 file changed, 9 insertions(+), 5 deletions(-)
+
+diff --git a/tools/rpmuncompress.c b/tools/rpmuncompress.c
+index c99c334da..46fb7c978 100644
+--- a/tools/rpmuncompress.c
++++ b/tools/rpmuncompress.c
+@@ -209,7 +209,7 @@ static char *doUntar(archiveType *at, int sr, const char *bn, const char *fn)
+ 	} else if (at->compressed == COMPRESSED_GEM) {
+ 	    char *gem = rpmGetPath("%{__gem}", NULL);
+ 
+-	    rasprintf(&buf, "%s %s && %s spec %s --ruby > '%s.gemspec'",
++	    rasprintf(&buf, "%s %s && %s spec %s --ruby > %s.gemspec",
+ 			zipper, fn, gem, fn, bn);
+ 
+ 	    free(gem);
+@@ -247,7 +247,8 @@ int main(int argc, char *argv[])
+     int ec = EXIT_FAILURE;
+     poptContext optCon = NULL;
+     const char *arg = NULL;
+-    const char *fnarg = "\"$1\"";
++    const char *bnarg = "\"$1\"";
++    const char *fnarg = "\"$2\"";
+     char *bn = NULL;
+     char *cmd = NULL;
+     archiveType *at = NULL;
+@@ -265,7 +266,7 @@ int main(int argc, char *argv[])
+     if (extract) {
+ 	if (dstpath)
+ 	    sr = singleRoot(arg);
+-	cmd = doUntar(at, sr, bn, fnarg);
++	cmd = doUntar(at, sr, bnarg, fnarg);
+     } else {
+ 	cmd = doUncompress(at, fnarg);
+     }
+@@ -274,14 +275,17 @@ int main(int argc, char *argv[])
+ 	FILE *inp = NULL;
+ 
+ 	if (verbose || dryrun) {
++	    char *drybn = NULL;
+ 	    char *dryfn = NULL;
+ 	    char *drycmd = NULL;
++	    rasprintf(&drybn, "'%s'", bn);
+ 	    rasprintf(&dryfn, "'%s'", arg);
+-	    drycmd = extract ? doUntar(at, sr, bn, dryfn) :
++	    drycmd = extract ? doUntar(at, sr, drybn, dryfn) :
+ 			       doUncompress(at, dryfn);
+ 	    fprintf(stderr, "%s\n", drycmd);
+ 	    free(drycmd);
+ 	    free(dryfn);
++	    free(drybn);
+ 	}
+ 
+ 	if (dryrun) {
+@@ -289,7 +293,7 @@ int main(int argc, char *argv[])
+ 	    goto exit;
+ 	}
+ 
+-	inp = rpopen(cmd, arg, NULL);
++	inp = rpopen(cmd, bn, arg, NULL);
+ 	if (inp) {
+ 	    int status, c;
+ 	    while ((c = fgetc(inp)) != EOF)
+-- 
+2.56.0
+

diff --git a/rpm.spec b/rpm.spec
index 7ae51d4..39c1874 100644
--- a/rpm.spec
+++ b/rpm.spec
@@ -27,7 +27,7 @@
 
 %global rpmver 4.19.1.1
 #global snapver rc1
-%global baserelease 27
+%global baserelease 28
 %global sover 10
 
 %global srcver %{rpmver}%{?snapver:-%{snapver}}
@@ -182,6 +182,17 @@ rpm-4.19.x-improve-syslog.patch
 
 0001-Prevent-command-injection-via-rpmbuild-t.patch
 
+0001-Fix-missing-quotes-in-doUncompress.patch
+0002-Define-a-nicer-alias-for-the-archiveType-struct.patch
+0003-Split-out-archiver-and-singleroot-in-rpmuncompress.patch
+0004-Prevent-command-injection-via-rpmbuild-t-filename.patch
+0001-Prevent-macro-injection-via-.gem-filenames.patch
+0001-Add-a-variable-argument-list-to-rpopen.patch
+0002-Let-callers-pass-the-basename-to-doUntar.patch
+0003-Drop-leftover-filename-arg-from-doUncompress.patch
+0004-Rename-a-parameter-name-in-doUntar.patch
+0005-Prevent-shell-injection-via-RubyGem-filenames.patch
+
 # These are not yet upstream
 rpm-4.7.1-geode-i686.patch
 
@@ -672,6 +683,11 @@ fi
 %doc %{_defaultdocdir}/rpm/API/
 
 %changelog
+* Wed Oct 21 2026 Michal Domonkos <mdomonko@redhat.com> - 4.19.1.1-28
+- CVE-2026-84233: Prevent macro injection via .gem filenames (RHEL-288155)
+- CVE-2026-84837: Prevent command injection via rpmbuild -t filename (RHEL-288156)
+- CVE-2026-84838: Prevent command injection via rpmuncompress (RHEL-288158)
+
 * Fri Oct 16 2026 Michal Domonkos <mdomonko@redhat.com> - 4.19.1.1-27
 - Bump release for rebuild (RHEL-282742)
 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-16 11:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 11:10 [rpms/python3-rpm] epel10.3: Prevent cmd injection via rpmbuild/rpmuncompress Michal Domonkos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox