diff mbox series

[wrynose,5/6] git: fix CVE-2026-114467

Message ID 20261125051246.3108822-5-asparmar@cisco.com
State New
Headers show
Series [wrynose,1/6] git: fix CVE-2026-105437 | expand

Commit Message

From: Ashishkumar Parmar <asparmar@cisco.com>

This patch applies the upstream Git 2.53.1 backport for
CVE-2026-114467. The upstream fix merge is referenced in [1],
and the security release notes are referenced in [2]. Individual
fix links are recorded in the embedded patch headers.

[1] https://github.com/git/git/commit/8e02c245c26d3cceccaa1b4e61daea197f1e82c8
[2] https://github.com/git/git/blob/v2.53.1/Documentation/RelNotes/2.50.2.adoc

Signed-off-by: Ashishkumar Parmar <asparmar@cisco.com>
---
 .../git/git/CVE-2026-114467.patch             | 150 ++++++++++++++++++
 meta/recipes-devtools/git/git_2.53.0.bb       |   1 +
 2 files changed, 151 insertions(+)
 create mode 100644 meta/recipes-devtools/git/git/CVE-2026-114467.patch
diff mbox series

Patch

diff --git a/meta/recipes-devtools/git/git/CVE-2026-114467.patch b/meta/recipes-devtools/git/git/CVE-2026-114467.patch
new file mode 100644
index 0000000000..2200907203
--- /dev/null
+++ b/meta/recipes-devtools/git/git/CVE-2026-114467.patch
@@ -0,0 +1,150 @@ 
+From f8c2fab7b46210866fce7b3c4248bbf79fd138f5 Mon Sep 17 00:00:00 2001
+From: Karthik Nayak <karthik.188@gmail.com>
+Date: Mon, 16 Mar 2026 11:00:45 +0100
+Subject: [PATCH] commit: rewrite `remove_signature()` to work with multiple
+ signatures
+
+The `remove_signature()` allows stripping GPG signatures from a given
+commit message buffer. It does so by parsing the message and recognizing
+the start and end positions of signatures present in the message.
+However, it assumes that a message can only contain two signatures at
+most.
+
+Commits crafted with more than two signatures will trigger a stack
+memory corruption as the function writes past the end of a fixed-size
+stack array `sigs[2]`.
+
+To avoid this, rewrite the function to use an internal buffer which
+simply collects non-signature lines and then swaps it with the incoming
+buffer. This removes the need for using a fixed size array for tracking
+individual signatures and allows the function to work with more than two
+signatures.
+
+CVE: CVE-2026-114467
+Upstream-Status: Backport [https://github.com/git/git/commit/aff587222342473034a270a3a04cfb1eba0a1117]
+
+Reported-by: pwn2addr <p2addr@gmail.com>
+Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
+Signed-off-by: Ashishkumar Parmar <asparmar@cisco.com>
+---
+ commit.c         | 35 +++++++++++++----------------------
+ t/t7600-merge.sh | 37 +++++++++++++++++++++++++++++++++++++
+ 2 files changed, 50 insertions(+), 22 deletions(-)
+
+diff --git a/commit.c b/commit.c
+index 28bb5ce0..a7d0996b 100644
+--- a/commit.c
++++ b/commit.c
+@@ -1224,51 +1224,42 @@ int parse_buffer_signed_by_header(const char *buffer,
+ 
+ int remove_signature(struct strbuf *buf)
+ {
+-	const char *line = buf->buf;
+ 	const char *tail = buf->buf + buf->len;
++	const char *line = buf->buf;
++	int signature_found = 0;
+ 	int in_signature = 0;
+-	struct sigbuf {
+-		const char *start;
+-		const char *end;
+-	} sigs[2], *sigp = &sigs[0];
+-	int i;
+-	const char *orig_buf = buf->buf;
++	struct strbuf final;
+ 
+-	memset(sigs, 0, sizeof(sigs));
++	strbuf_init(&final, buf->len);
+ 
+ 	while (line < tail) {
+ 		const char *next = memchr(line, '\n', tail - line);
+ 		next = next ? next + 1 : tail;
+ 
+-		if (in_signature && line[0] == ' ')
+-			sigp->end = next;
+-		else if (starts_with(line, "gpgsig")) {
++		if (in_signature && line[0] == ' ') {
++			/* Still inside a signature, ignore the content. */
++		} else if (starts_with(line, "gpgsig")) {
+ 			int i;
+ 			for (i = 1; i < GIT_HASH_NALGOS; i++) {
+ 				const char *p;
+ 				if (skip_prefix(line, gpg_sig_headers[i], &p) &&
+-				    *p == ' ') {
+-					sigp->start = line;
+-					sigp->end = next;
+-					in_signature = 1;
+-				}
++				    *p == ' ')
++					signature_found = in_signature = 1;
+ 			}
+ 		} else {
+ 			if (*line == '\n')
+ 				/* dump the whole remainder of the buffer */
+ 				next = tail;
+-			if (in_signature && sigp - sigs != ARRAY_SIZE(sigs))
+-				sigp++;
+ 			in_signature = 0;
++			strbuf_add(&final, line, next - line);
+ 		}
+ 		line = next;
+ 	}
+ 
+-	for (i = ARRAY_SIZE(sigs) - 1; i >= 0; i--)
+-		if (sigs[i].start)
+-			strbuf_remove(buf, sigs[i].start - orig_buf, sigs[i].end - sigs[i].start);
++	strbuf_swap(buf, &final);
++	strbuf_release(&final);
+ 
+-	return sigs[0].start != NULL;
++	return signature_found;
+ }
+ 
+ static void handle_signed_tag(const struct commit *parent, struct commit_extra_header ***tail)
+diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
+index 9838094b..9116b567 100755
+--- a/t/t7600-merge.sh
++++ b/t/t7600-merge.sh
+@@ -1054,6 +1054,43 @@ test_expect_success GPG 'merge --no-edit tag should skip editor' '
+ 	test_cmp expect actual
+ '
+ 
++test_expect_success GPG 'merge tag with multiple signatures' '
++	git commit --allow-empty -m "A newer commit" &&
++	git tag -s -m "A newer commit" signed_base &&
++
++	OBJECT_ID=$(git rev-parse HEAD) &&
++	git cat-file -p signed_base >base &&
++	HEADERS=$(sed "/^$/q" base) &&
++	BODY=$(sed "1,/^$/d" base) &&
++
++	# Manually craft a tag with multiple signatures. But we
++	# utilize the signature of a valid tag, so that this new tag will
++	# also pass verification.
++	cat >tag-text <<-EOF &&
++	$HEADERS
++	gpgsig -----BEGIN PGP SIGNATURE-----
++	 VGhpcyBpcyBub3QgcmVhbGx5IGEgc2lnbmF0dXJlLg==
++	 -----END PGP SIGNATURE-----
++	gpgsig-sha256 -----BEGIN PGP SIGNATURE-----
++	 VGhpcyBpcyBub3QgcmVhbGx5IGEgc2lnbmF0dXJlLg==
++	 -----END PGP SIGNATURE-----
++	gpgsig-sha256 -----BEGIN PGP SIGNATURE-----
++	 VGhpcyBpcyBub3QgcmVhbGx5IGEgc2lnbmF0dXJlLg==
++	 -----END PGP SIGNATURE-----
++
++	$BODY
++	EOF
++
++	TAG_HASH=$(git hash-object -t tag -w tag-text) &&
++	git update-ref refs/tags/multiple-signs $TAG_HASH &&
++	git reset --hard @~1 &&
++	git merge --no-edit multiple-signs &&
++	git cat-file -p HEAD >actual &&
++	# During the merge of signed tags, validation is done against the
++	# payload after stripping any additional signature.
++	test_grep "Good signature" actual
++'
++
+ test_expect_success 'set up mod-256 conflict scenario' '
+ 	# 256 near-identical stanzas...
+ 	for i in $(test_seq 1 256); do
diff --git a/meta/recipes-devtools/git/git_2.53.0.bb b/meta/recipes-devtools/git/git_2.53.0.bb
index c5bf87e44f..59bac1497f 100644
--- a/meta/recipes-devtools/git/git_2.53.0.bb
+++ b/meta/recipes-devtools/git/git_2.53.0.bb
@@ -21,6 +21,7 @@  SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
            file://CVE-2026-111760_p2.patch \
            file://CVE-2026-111760_p3.patch \
            file://CVE-2026-111760_p4.patch \
+           file://CVE-2026-114467.patch \
            "
 
 SRC_URI:append:class-nativesdk = " \