Hi Salvatore,
For the rpmbuild/rpmuncompress command-injection part of this report I
have built and tested backports and attached them for trixie and
bookworm. (On 2026-11-03 I sent the full upstream commit map for all
four CVEs to debian-security-tracker; this is the follow-up with the
tested patches.)
Attached:
CVE-2026-84837-rpm-4.20.patch trixie, rpm 4.20.1
CVE-2026-84837-rpm-4.18.patch bookworm, rpm 4.18.0
Each patch combines upstream 7a4111bc5db4 ("Prevent command injection
via rpmbuild -t filename"; Fixes: CVE-2026-84837 CVE-2026-84838) with
its .gem follow-up PR #4371 (e7a086a8e203 makes rpopen variadic;
e95f1b29ae27 passes the RubyGem basename positionally). The tarball
filename reaches a shell in getTarSpec() (rpmbuild) and in rpmuncompress,
and the derived .gem spec output name does too, so a crafted filename or
a crafted .gem basename runs arbitrary commands. The fix passes the
filename to /bin/sh as $1 and the derived .gemspec output name as $2, so
neither is interpolated into the command string.
Packaging notes:
- 4.20: rpopen/rpclose go into tools/cliutils and rpmuncompress is
linked against it.
- 4.18 has no shared cliutils linked into both tools, so a
self-contained static rpopen/rpclose is added to rpmbuild.c and
rpmuncompress.c (no autotools changes).
- My positional numbering differs from upstream (here filename=$1,
gemspec-name=$2; upstream uses basename=$1, filename=$2) but the
effect is identical; this is noted in the patch header. Upstream
test hunks dropped.
- These are a follow-up to the CVE-2026-78367 backports in #1145876
and apply on top of them (apply those first; only small line
offsets).
Scope:
- CVE-2026-84837 and CVE-2026-84838: both fixed, including the
RubyGem (.gem) path.
- CVE-2026-84233 (command execution via macro expansion in the
crafted .gem path) overlaps 84838 and, as far as I can tell, is the
same code path closed by e95f1b29ae27, so these patches should
address it too; upstream never linked a commit to 84233, so treat
that mapping as likely but unconfirmed.
- CVE-2026-44605 (ndb integer/heap overflow) is a separate issue and
is NOT addressed here; the upstream commits are in my 2026-11-03
tracker mail.
Testing (both 4.20.1 and 4.18.0, built from the Debian source):
- tar.gz filename, via rpmbuild -ts on a file whose name contains
$(...): unpatched runs the embedded command; patched does not, and
the tarball is still unpacked and the SRPM is built normally.
- .gem filename, via rpmuncompress -x on a .gem whose basename
contains a single-quote breakout (with %__gem stubbed so the command
chain is reached): with only 7a4111bc5 the command still runs; with
the follow-up it does not. Confirmed on both suites.
bullseye (4.16): the rpmbuild.c part applies with an offset, but
rpmuncompress is structured differently there and needs a separate
adaptation; I can do that if useful.
Regards,
Sumit
From: Michal Domonkos <[email protected]>
Date: Wed, 22 Oct 2026 10:46:11 +0200
Subject: [PATCH] Prevent command injection via rpmbuild -t / rpmuncompress filenames
Backport of the upstream fix for the tarball-filename command injection in
getTarSpec() (rpmbuild) and rpmuncompress. A crafted filename otherwise reaches
a shell. The filename is passed to /bin/sh as the positional $1 argument via a
read-only popen variant (rpopen); the derived .gem spec output name is passed as
$2, so neither is interpolated into the command string.
Origin: backport, https://github.com/rpm-software-management/rpm/commit/7a4111bc5db4053e5381b65306903837763e7f11
Origin: backport, https://github.com/rpm-software-management/rpm/commit/e7a086a8e203f123fbd37ead9b52188d1302ce0e
Origin: backport, https://github.com/rpm-software-management/rpm/commit/e95f1b29ae274620700d51d1741bf1392bfec0d8
Bug: https://github.com/rpm-software-management/rpm/issues/4314
Bug-Debian: https://bugs.debian.org/1146602
Last-Update: 2026-11-06
Notes: Adapted for rpm 4.18.0 (bookworm). Combines upstream 7a4111bc5 (CVE-2026-84837
and the main CVE-2026-84838 paths) with the .gem follow-up PR #4371 (e7a086a8
variadic rpopen; e95f1b29a RubyGem basename positional). 4.18 has no shared cliutils
linked into both tools, so a self-contained static variadic rpopen/rpclose is added
to rpmbuild.c and rpmuncompress.c (no autotools change). The fn->$1 / gemname->$2
substitutions were applied by hand. The positional numbering differs from upstream
(here fn=$1, gemspec-name=$2) but the effect is identical. In --dry-run/-v the
printed command shows the $2 placeholder for the gemspec output (cosmetic). Follow-up
to the CVE-2026-78367 backport (#1145876); apply that first. Test-suite hunks dropped.
--- a/rpmbuild.c 2022-08-30 07:42:23.815854089 -0400
+++ b/rpmbuild.c 2026-11-05 20:54:51.083952127 -0500
@@ -3,6 +3,8 @@
#include <errno.h>
#include <libgen.h>
#include <ctype.h>
+#include <sys/wait.h>
+#include <stdarg.h>
#include <rpm/rpmcli.h>
#include <rpm/rpmlib.h> /* RPMSIGTAG, rpmReadPackageFile .. */
@@ -364,6 +366,62 @@
* Try to find a spec from a tarball pointed to by arg.
* Return absolute path to spec name on success, otherwise NULL.
*/
+/*
+ * A read-only popen(3) variant that passes untrusted input (args) to the
+ * shell as positional arguments $1, $2, ... so the command (cmd) can
+ * reference them instead of interpolating them into the command string.
+ * The argument list must be NULL-terminated. Backport helper for
+ * CVE-2026-84837 / CVE-2026-84838.
+ */
+static FILE *rpopen(const char *cmd, const char *arg, ...)
+{
+ FILE *stream = NULL;
+ const char *argv[16];
+ va_list ap;
+ int n = 0;
+ int pipefd[2];
+ pid_t pid;
+
+ if (pipe(pipefd) < 0)
+ return NULL;
+
+ argv[n++] = "/bin/sh";
+ argv[n++] = "-c";
+ argv[n++] = cmd;
+ argv[n++] = "sh";
+ va_start(ap, arg);
+ for (const char *s = arg; s != NULL && n < 15; s = va_arg(ap, const char *))
+ argv[n++] = s;
+ va_end(ap);
+ argv[n] = NULL;
+
+ if ((pid = fork()) == 0) {
+ dup2(pipefd[1], STDOUT_FILENO);
+ close(pipefd[0]);
+ execv(argv[0], (char *const *)argv);
+ _exit(EXIT_FAILURE);
+ } else if (pid == -1) {
+ close(pipefd[0]);
+ close(pipefd[1]);
+ return NULL;
+ }
+
+ close(pipefd[1]);
+ stream = fdopen(pipefd[0], "r");
+ return stream;
+}
+
+static int rpclose(FILE *stream)
+{
+ int rc = -1;
+ int status;
+
+ if ((waitpid(-1, &status, 0) != -1) && WIFEXITED(status))
+ rc = WEXITSTATUS(status);
+ fclose(stream);
+ return rc;
+}
+
static char * getTarSpec(const char *arg)
{
char *specFile = NULL;
@@ -383,11 +441,11 @@
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, NULL))) {
rpmlog(RPMLOG_ERR, _("Failed to open tar pipe: %m\n"));
} else {
char *fok;
@@ -400,7 +458,7 @@
}
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);
--- a/tools/rpmuncompress.c 2022-08-30 07:42:23.830854214 -0400
+++ b/tools/rpmuncompress.c 2026-11-05 20:54:51.084339651 -0500
@@ -4,6 +4,8 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <sys/wait.h>
+#include <stdarg.h>
#include <rpm/rpmcli.h>
#include <rpm/rpmstring.h>
@@ -65,19 +67,75 @@
return archiver;
}
-static char *doUncompress(const char *fn)
+/*
+ * A read-only popen(3) variant that passes untrusted input (args) to the
+ * shell as positional arguments $1, $2, ... so the command (cmd) can
+ * reference them instead of interpolating them into the command string.
+ * The argument list must be NULL-terminated. Backport helper for
+ * CVE-2026-84837 / CVE-2026-84838.
+ */
+static FILE *rpopen(const char *cmd, const char *arg, ...)
+{
+ FILE *stream = NULL;
+ const char *argv[16];
+ va_list ap;
+ int n = 0;
+ int pipefd[2];
+ pid_t pid;
+
+ if (pipe(pipefd) < 0)
+ return NULL;
+
+ argv[n++] = "/bin/sh";
+ argv[n++] = "-c";
+ argv[n++] = cmd;
+ argv[n++] = "sh";
+ va_start(ap, arg);
+ for (const char *s = arg; s != NULL && n < 15; s = va_arg(ap, const char *))
+ argv[n++] = s;
+ va_end(ap);
+ argv[n] = NULL;
+
+ if ((pid = fork()) == 0) {
+ dup2(pipefd[1], STDOUT_FILENO);
+ close(pipefd[0]);
+ execv(argv[0], (char *const *)argv);
+ _exit(EXIT_FAILURE);
+ } else if (pid == -1) {
+ close(pipefd[0]);
+ close(pipefd[1]);
+ return NULL;
+ }
+
+ close(pipefd[1]);
+ stream = fdopen(pipefd[0], "r");
+ return stream;
+}
+
+static int rpclose(FILE *stream)
+{
+ int rc = -1;
+ int status;
+
+ if ((waitpid(-1, &status, 0) != -1) && WIFEXITED(status))
+ rc = WEXITSTATUS(status);
+ fclose(stream);
+ return rc;
+}
+
+static char *doUncompress(const char *fn, const char *arg)
{
char *cmd = NULL;
const struct archiveType_s *at = getArchiver(fn);
if (at) {
cmd = rpmExpand(at->cmd, " ", at->unpack, NULL);
/* path must not be expanded */
- cmd = rstrscat(&cmd, " ", fn, NULL);
+ cmd = rstrscat(&cmd, " ", arg, NULL);
}
return cmd;
}
-static char *doUntar(const char *fn)
+static char *doUntar(const char *fn, const char *arg, char **gemval)
{
const struct archiveType_s *at = NULL;
char *buf = NULL;
@@ -95,7 +153,7 @@
zipper = rpmExpand(at->cmd, " ", at->unpack, " ",
verbose ? "" : at->quiet, NULL);
if (needtar) {
- rasprintf(&buf, "%s '%s' | %s %s -", zipper, fn, tar, taropts);
+ rasprintf(&buf, "%s %s | %s %s -", zipper, arg, tar, taropts);
} else if (at->compressed == COMPRESSED_GEM) {
const char *bn = basename(fn);
size_t nvlen = strlen(bn) - 3;
@@ -106,17 +164,17 @@
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 > \"$2\"",
+ zipper, arg, gem, arg);
- free(gemspec);
+ *gemval = gemspec;
free(gem);
} else {
- rasprintf(&buf, "%s '%s'", zipper, fn);
+ rasprintf(&buf, "%s %s", zipper, arg);
}
free(zipper);
} else {
- rasprintf(&buf, "%s %s '%s'", tar, taropts, fn);
+ rasprintf(&buf, "%s %s %s", tar, taropts, arg);
}
exit:
@@ -129,6 +187,8 @@
int ec = EXIT_FAILURE;
poptContext optCon = NULL;
const char *arg = NULL;
+ const char *fnarg = "\"$1\"";
+ char *gemval = NULL;
optCon = rpmcliInit(argc, argv, optionsTable);
@@ -137,24 +197,33 @@
goto exit;
}
- char *cmd = extract ? doUntar(arg) : doUncompress(arg);
+ char *cmd = extract ? doUntar(arg, fnarg, &gemval) : doUncompress(arg, fnarg);
if (cmd) {
FILE *inp = NULL;
- if (verbose || dryrun)
- fprintf(stderr, "%s\n", cmd);
+ if (verbose || dryrun) {
+ char *dryarg = NULL;
+ char *drygemval = NULL;
+ char *drycmd = NULL;
+ rasprintf(&dryarg, "'%s'", arg);
+ drycmd = extract ? doUntar(arg, dryarg, &drygemval) : doUncompress(arg, dryarg);
+ fprintf(stderr, "%s\n", drycmd);
+ free(drygemval);
+ free(drycmd);
+ free(dryarg);
+ }
if (dryrun) {
ec = EXIT_SUCCESS;
goto exit;
}
- inp = popen(cmd, "r");
+ inp = rpopen(cmd, arg, gemval, NULL);
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;
}
@@ -162,6 +231,7 @@
}
exit:
+ free(gemval);
rpmcliFini(optCon);
return ec;
}
From: Michal Domonkos <[email protected]>
Date: Wed, 22 Oct 2026 10:46:11 +0200
Subject: [PATCH] Prevent command injection via rpmbuild -t / rpmuncompress filenames
Backport of the upstream fix for the tarball-filename command injection in
getTarSpec() (rpmbuild) and rpmuncompress. A crafted filename otherwise reaches
a shell. The filename is passed to /bin/sh as the positional $1 argument via a
read-only popen variant (rpopen); the derived .gem spec output name is passed as
$2, so neither is interpolated into the command string.
Origin: backport, https://github.com/rpm-software-management/rpm/commit/7a4111bc5db4053e5381b65306903837763e7f11
Origin: backport, https://github.com/rpm-software-management/rpm/commit/e7a086a8e203f123fbd37ead9b52188d1302ce0e
Origin: backport, https://github.com/rpm-software-management/rpm/commit/e95f1b29ae274620700d51d1741bf1392bfec0d8
Bug: https://github.com/rpm-software-management/rpm/issues/4314
Bug-Debian: https://bugs.debian.org/1146602
Last-Update: 2026-11-06
Notes: Adapted for rpm 4.20.1 (trixie). Combines upstream 7a4111bc5 (CVE-2026-84837
and the main CVE-2026-84838 paths) with the .gem follow-up PR #4371 (e7a086a8
makes rpopen variadic; e95f1b29a passes the RubyGem basename positionally). rpopen/
rpclose live in tools/cliutils and rpmuncompress is linked against it (CMakeLists).
rpmuncompress.c is structurally different from master (C basename/gem handling),
so the fn->$1 / gemname->$2 substitutions were applied by hand to doUncompress/
doUntar/main. The positional numbering differs from upstream (here fn=$1,
gemspec-name=$2; upstream uses basename=$1, fn=$2) but the effect is identical:
no attacker-controlled string is interpolated into the shell command. In --dry-run/
-v the printed command shows the $2 placeholder for the gemspec output (cosmetic;
that path is never executed). Follow-up to the CVE-2026-78367 backport (#1145876);
apply that first. Test-suite hunks dropped.
--- a/tools/cliutils.h 2025-02-19 10:29:33.000000000 -0500
+++ b/tools/cliutils.h 2026-11-05 20:53:25.351964660 -0500
@@ -26,6 +26,14 @@
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, $2, and so on. The argument list must be NULL-terminated.
+ */
+FILE *rpopen(const char *cmd, const char *arg, ...);
+int rpclose(FILE *stream);
+
#ifdef __cplusplus
}
#endif
--- a/tools/cliutils.c 2025-02-19 10:29:33.000000000 -0500
+++ b/tools/cliutils.c 2026-11-05 20:53:25.351534453 -0500
@@ -3,6 +3,8 @@
#include <sys/wait.h>
#include <rpm/rpmlog.h>
+#include <rpm/argv.h>
+#include <stdarg.h>
#include <rpm/rpmlib.h>
#include <rpm/rpmfileutil.h>
#include <rpm/rpmmacro.h>
@@ -83,3 +85,56 @@
}
return rc;
}
+
+FILE *rpopen(const char *cmd, const char *arg, ...)
+{
+ FILE *stream = NULL;
+ ARGV_t argv = NULL;
+ va_list ap;
+ 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");
+
+ 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);
+ 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;
+}
--- a/tools/rpmbuild.c 2025-02-19 10:29:33.000000000 -0500
+++ b/tools/rpmbuild.c 2026-11-05 20:53:25.352429153 -0500
@@ -375,11 +375,11 @@
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, NULL))) {
rpmlog(RPMLOG_ERR, _("Failed to open tar pipe: %m\n"));
} else {
char *fok;
@@ -392,7 +392,7 @@
}
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);
--- a/tools/rpmuncompress.c 2025-02-19 10:29:33.000000000 -0500
+++ b/tools/rpmuncompress.c 2026-11-05 20:53:25.353326309 -0500
@@ -12,6 +12,7 @@
#include <rpm/rpmcli.h>
#include <rpm/rpmstring.h>
+#include "cliutils.h"
#include "debug.h"
static int verbose = 0;
@@ -74,7 +75,7 @@
return archiver;
}
-static char *doUncompress(const char *fn)
+static char *doUncompress(const char *fn, const char *arg)
{
char *cmd = NULL;
const struct archiveType_s *at = getArchiver(fn);
@@ -82,7 +83,7 @@
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;
}
@@ -143,7 +144,7 @@
return rootName;
}
-static char *doUntar(const char *fn)
+static char *doUntar(const char *fn, const char *arg, char **gemval)
{
const struct archiveType_s *at = NULL;
char *buf = NULL;
@@ -199,7 +200,7 @@
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);
@@ -211,18 +212,18 @@
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 > \"$2\"",
+ zipper, arg, gem, arg);
- free(gemspec);
+ *gemval = 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:
@@ -237,6 +238,8 @@
int ec = EXIT_FAILURE;
poptContext optCon = NULL;
const char *arg = NULL;
+ const char *fnarg = "\"$1\"";
+ char *gemval = NULL;
char *cmd = NULL;
optCon = rpmcliInit(argc, argv, optionsTable);
@@ -246,24 +249,33 @@
goto exit;
}
- cmd = extract ? doUntar(arg) : doUncompress(arg);
+ cmd = extract ? doUntar(arg, fnarg, &gemval) : doUncompress(arg, fnarg);
if (cmd) {
FILE *inp = NULL;
- if (verbose || dryrun)
- fprintf(stderr, "%s\n", cmd);
+ if (verbose || dryrun) {
+ char *dryarg = NULL;
+ char *drygemval = NULL;
+ char *drycmd = NULL;
+ rasprintf(&dryarg, "'%s'", arg);
+ drycmd = extract ? doUntar(arg, dryarg, &drygemval) : doUncompress(arg, dryarg);
+ fprintf(stderr, "%s\n", drycmd);
+ free(drygemval);
+ free(drycmd);
+ free(dryarg);
+ }
if (dryrun) {
ec = EXIT_SUCCESS;
goto exit;
}
- inp = popen(cmd, "r");
+ inp = rpopen(cmd, arg, gemval, NULL);
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;
}
@@ -271,6 +283,7 @@
exit:
free(cmd);
+ free(gemval);
rpmcliFini(optCon);
return ec;
}
--- a/tools/CMakeLists.txt 2025-02-19 10:29:33.000000000 -0500
+++ b/tools/CMakeLists.txt 2026-11-05 20:53:25.353524255 -0500
@@ -10,7 +10,7 @@
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)