Hi,

Following up on my two earlier mails (the static patch-applies check, and
the reproducer run that confirmed sid 6.1.0-1 is affected): I have now done
the "after" side that was still missing, for the stable suites.

I adapted the upstream fix 2a11eb3e4e51 to the Debian 4.x sources (the
upstream commit is against the .cc tree; the stable suites still use .c)
and built and tested patched packages. The test input is a tarball with a
single *.spec member whose name carries an rpm macro command substitution,
i.e. %(...), plus a minimal valid spec body, run as rpmbuild -ts with an
isolated _topdir/_specdir:

- rpm 4.20.1+dfsg-3 (trixie): the backport applies cleanly (patch -p1, no
fuzz) and builds. Unpatched, the command in the member name is executed
when running rpmbuild -ts on the tarball. Patched, it is not executed, and
rpmbuild -ts still writes the .src.rpm, so a normal -t build is unaffected.

- rpm 4.18.0+dfsg-1+deb12u1 (bookworm): same result - applies cleanly,
builds, unpatched executes the injected command, patched does not, and the
SRPM is still produced.

- rpm 4.16.1.2+dfsg1-3 (bullseye): the bookworm backport applies with line
offsets (no fuzz); I did not build-test this one.

The patched builds were configured with the libgcrypt crypto backend and
with optional subsystems (SELinux, audit, plugins, python, sequoia)
disabled; the change is confined to getTarSpec() and parseSpec(), so that
does not affect the result.

Attached are the two backports as DEP-3 patches, adapted for 4.20.1 and
4.18.0. These are the stable-source versions of the upstream patch I
attached earlier.

The separate follow-up commit 7a4111bc5d (bug #1146602) is still a separate
backport and is not covered here.

Regards,
Sumit Verma
From: Michal Domonkos <[email protected]>
Date: Wed, 26 Aug 2026 10:53:12 +0200
Subject: Prevent command injection via rpmbuild -t

When running in -t mode, the spec member name in the passed tarball will
get macro-expanded twice: first when constructing the target filename in
getTarSpec() and then in parseSpec(). This allows a crafted tarball to
execute arbitrary code when the user just runs rpmbuild -ts or similar.

Origin: backport, https://github.com/rpm-software-management/rpm/commit/2a11eb3e4e51094082e0123aebd797ec051dc094
Bug: https://github.com/rpm-software-management/rpm/issues/4314
Bug-Debian: https://bugs.debian.org/1145876
Last-Update: 2026-11-05
Notes: Adapted for rpm 4.18.0 (bookworm): tools/rpmbuild.cc -> rpmbuild.c,
 build/parseSpec.cc -> build/parseSpec.c, context refreshed. Test-suite
 hunks (tests/rpmbuild.at, tests/data/misc/CVE-2026-78367.py) dropped.
 Built and tested on bookworm (rpm 4.18.0): unpatched rpmbuild -ts runs
 a %(...) payload in the spec member name, patched does not, SRPM still builds.

--- a/build/parseSpec.c
+++ b/build/parseSpec.c
@@ -899,7 +899,7 @@ static rpmSpec parseSpec(const char *spe
     /* Set up a new Spec structure with no packages. */
     spec = newSpec();
 
-    spec->specFile = rpmGetPath(specFile, NULL);
+    spec->specFile = rpmCleanPath(xstrdup(specFile));
     pushOFI(spec, spec->specFile);
     /* If buildRoot not specified, use default %{buildroot} */
     if (buildRoot) {
--- a/rpmbuild.c
+++ b/rpmbuild.c
@@ -367,6 +367,8 @@ static int isSpecFile(const char * specf
 static char * getTarSpec(const char *arg)
 {
     char *specFile = NULL;
+    char *specDir = NULL;
+    char *specBase = NULL;
     char *specFinal = NULL;
     const char **spec;
     char tarbuf[BUFSIZ];
@@ -416,9 +418,11 @@ static char * getTarSpec(const char *arg
     if (!gotspec) {
     	rpmlog(RPMLOG_ERR, _("Failed to read spec file from %s\n"), arg);
     } else {
+	specDir = rpmExpand("%{_specdir}", NULL);
+	specBase = basename(tarbuf);
 	/* remove trailing \n */
-	tarbuf[strlen(tarbuf)-1] = '\0';
-	specFinal = rpmExpand("%{_specdir}/%{basename:", tarbuf, "}", NULL);
+	specBase[strlen(specBase)-1] = '\0';
+	rasprintf(&specFinal, "%s/%s", specDir, specBase);
 	if (rename(specFile, specFinal)) {
 	    rpmlog(RPMLOG_ERR, _("Failed to rename %s to %s: %m\n"),
 		    specFile, specFinal);
@@ -429,6 +433,7 @@ static char * getTarSpec(const char *arg
 
 exit:
     free(specFile);
+    free(specDir);
     Fclose(fd);
     return specFinal;
 }
From: Michal Domonkos <[email protected]>
Date: Wed, 26 Aug 2026 10:53:12 +0200
Subject: Prevent command injection via rpmbuild -t

When running in -t mode, the spec member name in the passed tarball will
get macro-expanded twice: first when constructing the target filename in
getTarSpec() and then in parseSpec(). This allows a crafted tarball to
execute arbitrary code when the user just runs rpmbuild -ts or similar.

Origin: backport, https://github.com/rpm-software-management/rpm/commit/2a11eb3e4e51094082e0123aebd797ec051dc094
Bug: https://github.com/rpm-software-management/rpm/issues/4314
Bug-Debian: https://bugs.debian.org/1145876
Last-Update: 2026-11-05
Notes: Adapted for rpm 4.20.1 (trixie): tools/rpmbuild.cc -> tools/rpmbuild.c,
 build/parseSpec.cc -> build/parseSpec.c, line offsets refreshed. Test-suite
 hunks (tests/rpmbuild.at, tests/data/misc/CVE-2026-78367.py) dropped.
 Built and tested on trixie (rpm 4.20.1): unpatched rpmbuild -ts runs
 a %(...) payload in the spec member name, patched does not, SRPM still builds.

--- a/build/parseSpec.c
+++ b/build/parseSpec.c
@@ -1308,7 +1308,7 @@ static rpmSpec parseSpec(const char *spe
     /* Set up a new Spec structure with no packages. */
     spec = newSpec();
 
-    spec->specFile = rpmGetPath(specFile, NULL);
+    spec->specFile = rpmCleanPath(xstrdup(specFile));
     pushOFI(spec, spec->specFile);
     /* If explicit --buildroot was passed, grab hold of it */
     if (buildRoot)
--- a/tools/rpmbuild.c
+++ b/tools/rpmbuild.c
@@ -359,6 +359,8 @@ static int isSpecFile(const char * specf
 static char * getTarSpec(const char *arg)
 {
     char *specFile = NULL;
+    char *specDir = NULL;
+    char *specBase = NULL;
     char *specFinal = NULL;
     const char **spec;
     char tarbuf[BUFSIZ];
@@ -408,9 +410,11 @@ static char * getTarSpec(const char *arg
     if (!gotspec) {
     	rpmlog(RPMLOG_ERR, _("Failed to read spec file from %s\n"), arg);
     } else {
+	specDir = rpmExpand("%{_specdir}", NULL);
+	specBase = basename(tarbuf);
 	/* remove trailing \n */
-	tarbuf[strlen(tarbuf)-1] = '\0';
-	specFinal = rpmExpand("%{_specdir}/%{basename:", tarbuf, "}", NULL);
+	specBase[strlen(specBase)-1] = '\0';
+	rasprintf(&specFinal, "%s/%s", specDir, specBase);
 	if (rename(specFile, specFinal)) {
 	    rpmlog(RPMLOG_ERR, _("Failed to rename %s to %s: %m\n"),
 		    specFile, specFinal);
@@ -421,6 +425,7 @@ static char * getTarSpec(const char *arg
 
 exit:
     free(specFile);
+    free(specDir);
     Fclose(fd);
     return specFinal;
 }

Reply via email to