Hello,

I've prepared patch 2.7.6-7+deb12u1 for bookworm-security, and it's ready for 
review.

The fix is already in Trixie (2.8-2+deb13u1) and in Sid, where it came with the 
2.8.1 upstream release. I've attached the debdiff against 2.7.6-7 and the draft 
DLA.

- CVE-2026-115207
https://security-tracker.debian.org/tracker/CVE-2026-115207
- Upstream commit 0cd45bb2132a42cd38d84b20661f3eae9b4da7ce
https://cgit.git.savannah.gnu.org/cgit/patch.git/commit/?id=0cd45bb2132a42cd38d84b20661f3eae9b4da7ce

The upstream change is small: it adds a name_is_valid check before patch automatically 
reverses a hunk. It applied with only a line-number offset, so the header marks it as a 
straight cherry-pick. In 2.7.6-7, a name containing ".." was already refused 
when patch created its temporary file, but an absolute path got through, and patch went 
ahead and created the file. The new check is the same name_is_valid test that a forward 
create already goes through. The comment in the new tests still says CVE-2026-XXXXX; I 
left it as is, since that's what the upstream commit says.

I built it in a Bookworm schroot. The upstream test suite gave 43 passes and 2 
expected failures (context-format and dash-o-append, both already listed in 
tests/Makefile.am). bad-filenames and create-delete both passed.

For the batch-mode case (-p0 -t), 2.7.6-7 created a file at the absolute path 
from a deletion header. Under umask 002, the file ended up with mode 664 and 
held the deleted line. 2.7.6-7+deb12u1 refuses that name. Normal use still 
works: a missing relative file named target is recreated, a one-line edit to an 
existing file still applies, and a forward create aimed at an absolute path is 
still refused.

The -R case behaves the same way. With a creation header naming an absolute 
path, 2.7.6-7 created the file, and 2.7.6-7+deb12u1 refuses it. A relative name 
that goes through a symlink is still refused at the temporary-file step on both 
builds. I also ran the same cases against 2.8-2+deb13u1 in a Trixie schroot, 
and the results matched.

The repository is not tracked on Salsa, but you can find the Debusine work 
request here: 
https://debusine.debian.net/debian/developers/work-request/1652612/

Feedback is welcome. If nothing showstopping comes up, I'll upload this and 
issue the DLA on Friday (November 27th, 2026; extra time for USA Thanksgiving 
this week).

Best regards,
Simon Quigley
[email protected]
diff -Nru patch-2.7.6/debian/changelog patch-2.7.6/debian/changelog
--- patch-2.7.6/debian/changelog        2021-01-09 02:58:08.000000000 -0600
+++ patch-2.7.6/debian/changelog        2026-11-23 10:14:57.000000000 -0600
@@ -1,3 +1,11 @@
+patch (2.7.6-7+deb12u1) bookworm-security; urgency=high
+
+  * Non-maintainer upload by the LTS Team.
+  * CVE-2026-115207: Reject an unsafe pathname during automatic reversal
+    of a patch that deletes a file.
+
+ -- Simon Quigley <[email protected]>  Mon, 23 Nov 2026 10:14:57 -0600
+
 patch (2.7.6-7) unstable; urgency=medium
 
   * Backport upstream fixes:
diff -Nru patch-2.7.6/debian/patches/CVE-2026-115207.patch 
patch-2.7.6/debian/patches/CVE-2026-115207.patch
--- patch-2.7.6/debian/patches/CVE-2026-115207.patch    1969-12-31 
18:00:00.000000000 -0600
+++ patch-2.7.6/debian/patches/CVE-2026-115207.patch    2026-11-22 
13:21:58.000000000 -0600
@@ -0,0 +1,107 @@
+Origin: upstream, 
https://cgit.git.savannah.gnu.org/cgit/patch.git/commit/?id=0cd45bb2132a42cd38d84b20661f3eae9b4da7ce
+Reviewed-by: Simon Quigley <[email protected]>
+Last-Update: 2026-11-22
+
+From 0cd45bb2132a42cd38d84b20661f3eae9b4da7ce Mon Sep 17 00:00:00 2001
+From: Andreas Gruenbacher <[email protected]>
+Date: Wed, 21 Oct 2026 16:49:38 +0200
+Subject: Prevent creation of out-of-tree files (CVE-2026-115207)
+
+When reverse-applying a patch that deletes a file, patch created that
+file without checking if the pathname is safe.  Fix that by adding the
+missing check.
+* src/pch.c (intuit_diff_type): Add the missing check.
+* tests/create-delete: Add two new tests.
+* tests/bad-filenames: This changes the output of these tests.
+---
+ src/pch.c           |  1 +
+ tests/bad-filenames |  2 ++
+ tests/create-delete | 46 ++++++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 49 insertions(+)
+
+diff --git a/src/pch.c b/src/pch.c
+index a65322c..64ce72f 100644
+--- a/src/pch.c
++++ b/src/pch.c
+@@ -956,6 +956,7 @@ intuit_diff_type (bool need_header, mode_t *p_file_type)
+             }
+ 
+           if (i0 != NONE
++              && name_is_valid (p_name[i0])
+               && (i == NONE || (st[i].st_mode & S_IFMT) == file_type)
+               && maybe_reverse (p_name[i == NONE ? i0 : i], i == NONE,
+                                 i == NONE || st[i].st_size == 0)
+diff --git a/tests/bad-filenames b/tests/bad-filenames
+index 2515f0a..ae6ba13 100644
+--- a/tests/bad-filenames
++++ b/tests/bad-filenames
+@@ -104,6 +104,7 @@ cat > d.diff <<EOF
+ EOF
+ 
+ check 'patch -f -p0 --dry-run < d.diff || echo status: $?' <<EOF
++Ignoring potentially dangerous file name ../g
+ can't find file to patch at input line 3
+ Perhaps you used the wrong -p or --strip option?
+ The text leading up to this was:
+@@ -118,6 +119,7 @@ EOF
+ 
+ echo 1 > f
+ check 'patch -f -p0 --dry-run < d.diff || echo status: $?' <<EOF
++Ignoring potentially dangerous file name ../g
+ checking file f
+ EOF
+ 
+diff --git a/tests/create-delete b/tests/create-delete
+index adcce27..8edeb67 100644
+--- a/tests/create-delete
++++ b/tests/create-delete
+@@ -295,3 +295,49 @@ EOF
+ check 'cat target.orig' <<EOF
+ data
+ EOF
++
++# ================================================================
++# CVE-2026-XXXXX: Reverse-applying a patch should not create
++# out-of-tree files.
++
++cat > p.diff <<EOF
++--- ../invalid
+++++ ../invalid
++@@ -1 +0,0 @@
++-data
++EOF
++
++check 'patch -p0 -t < p.diff || echo status: $?' <<EOF
++Ignoring potentially dangerous file name ../invalid
++can't find file to patch at input line 3
++Perhaps you used the wrong -p or --strip option?
++The text leading up to this was:
++--------------------------
++|--- ../invalid
++|+++ ../invalid
++--------------------------
++No file to patch.  Skipping patch.
++1 out of 1 hunk ignored
++status: 1
++EOF
++
++cat > p.diff <<EOF
++--- $PWD/invalid      2025-01-01 12:00:00.000000000 +0000
+++++ $PWD/invalid      1970-01-01 00:00:00.000000000 +0000
++@@ -1 +0,0 @@
++-data
++EOF
++
++check 'patch -p0 -t < p.diff || echo status: $?' <<EOF
++Ignoring potentially dangerous file name $PWD/invalid
++can't find file to patch at input line 3
++Perhaps you used the wrong -p or --strip option?
++The text leading up to this was:
++--------------------------
++|--- $PWD/invalid     2025-01-01 12:00:00.000000000 +0000
++|+++ $PWD/invalid     1970-01-01 00:00:00.000000000 +0000
++--------------------------
++No file to patch.  Skipping patch.
++1 out of 1 hunk ignored
++status: 1
++EOF
diff -Nru patch-2.7.6/debian/patches/series patch-2.7.6/debian/patches/series
--- patch-2.7.6/debian/patches/series   2021-01-09 02:58:08.000000000 -0600
+++ patch-2.7.6/debian/patches/series   2026-11-22 13:21:58.000000000 -0600
@@ -13,3 +13,4 @@
 0007-Do_not_leak_temporary_file_on_failed_multi-file.patch
 0008-Avoid_invalid_memory_access_in_context_format_diffs.patch
 0009-Fix_failed_assertion_outstate-after_newline.patch
+CVE-2026-115207.patch
-------------------------------------------------------------------------
Debian LTS Advisory DLA-XXXX-1                [email protected]
https://www.debian.org/lts/security/                        Simon Quigley
November 25, 2026                             https://wiki.debian.org/LTS
-------------------------------------------------------------------------

Package        : patch
Version        : 2.7.6-7+deb12u1
CVE ID         : CVE-2026-115207

GNU patch applies a diff to a set of files. An attacker who can get a
user or an automated job to apply a crafted patch with patch's -p0
option could create a new file at an arbitrary absolute path, with
attacker-chosen contents and the privileges of that user.

CVE-2026-115207

    When patch reversed a hunk automatically, either in batch mode (-t)
    or after the user answered yes to "Assume -R?", or when -R was used
    on a patch that creates a file, it did not check the file name
    first. A crafted patch could name an absolute path, and patch would
    create the file there. A git-style header could also make the new
    file executable or a symbolic link.

For Debian 12 bookworm, this problem has been fixed in version
2.7.6-7+deb12u1.

We recommend that you upgrade your patch packages.

For the detailed security status of patch please refer to
its security tracker page at:
https://security-tracker.debian.org/tracker/patch

Further information about Debian LTS security advisories, how to apply
these updates to your system, and frequently asked questions can be
found at: https://wiki.debian.org/LTS

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to