summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHitendra Prajapati <hprajapati@mvista.com>2023-05-17 12:44:37 +0530
committerSteve Sakoman <steve@sakoman.com>2023-05-25 05:49:26 -1000
commit1824a583fa72cd1debe39cc0cf352171b3a795a3 (patch)
tree1f1f197c88d902d7cf748c05ab1b5c53f73c9015
parent967c2d41452ccb42fe832837bc96c2719328ec9f (diff)
downloadpoky-1824a583fa72cd1debe39cc0cf352171b3a795a3.tar.gz
git: fix CVE-2023-25652
Git is a revision control system. Prior to versions 2.30.9, 2.31.8, 2.32.7, 2.33.8, 2.34.8, 2.35.8, 2.36.6, 2.37.7, 2.38.5, 2.39.3, and 2.40.1, by feeding specially crafted input to `git apply --reject`, a path outside the working tree can be overwritten with partially controlled contents (corresponding to the rejected hunk(s) from the given patch). A fix is available in versions 2.30.9, 2.31.8, 2.32.7, 2.33.8, 2.34.8, 2.35.8, 2.36.6, 2.37.7, 2.38.5, 2.39.3, and 2.40.1. As a workaround, avoid using `git apply` with `--reject` when applying patches from an untrusted source. Use `git apply --stat` to inspect a patch before applying; avoid applying one that create a conflict where a link corresponding to the `*.rej` file exists. References: https://nvd.nist.gov/vuln/detail/CVE-2023-25652 Upstream-Status: Backport from https://github.com/git/git/commit/9db05711c98efc14f414d4c87135a34c13586e0b (From OE-Core rev: 6747482316b8f7839a09bf041d8c11b559f84b44) Signed-off-by: Hitendra Prajapati <hprajapati@mvista.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-devtools/git/files/CVE-2023-25652.patch94
-rw-r--r--meta/recipes-devtools/git/git.inc1
2 files changed, 95 insertions, 0 deletions
diff --git a/meta/recipes-devtools/git/files/CVE-2023-25652.patch b/meta/recipes-devtools/git/files/CVE-2023-25652.patch
new file mode 100644
index 0000000000..d6b17a2b8a
--- /dev/null
+++ b/meta/recipes-devtools/git/files/CVE-2023-25652.patch
@@ -0,0 +1,94 @@
1From 9db05711c98efc14f414d4c87135a34c13586e0b Mon Sep 17 00:00:00 2001
2From: Johannes Schindelin <johannes.schindelin@gmx.de>
3Date: Thu, 9 Mar 2023 16:02:54 +0100
4Subject: [PATCH] apply --reject: overwrite existing `.rej` symlink if it
5 exists
6
7The `git apply --reject` is expected to write out `.rej` files in case
8one or more hunks fail to apply cleanly. Historically, the command
9overwrites any existing `.rej` files. The idea being that
10apply/reject/edit cycles are relatively common, and the generated `.rej`
11files are not considered precious.
12
13But the command does not overwrite existing `.rej` symbolic links, and
14instead follows them. This is unsafe because the same patch could
15potentially create such a symbolic link and point at arbitrary paths
16outside the current worktree, and `git apply` would write the contents
17of the `.rej` file into that location.
18
19Therefore, let's make sure that any existing `.rej` file or symbolic
20link is removed before writing it.
21
22Reported-by: RyotaK <ryotak.mail@gmail.com>
23Helped-by: Taylor Blau <me@ttaylorr.com>
24Helped-by: Junio C Hamano <gitster@pobox.com>
25Helped-by: Linus Torvalds <torvalds@linuxfoundation.org>
26Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
27
28Upstream-Status: Backport [https://github.com/git/git/commit/9db05711c98efc14f414d4c87135a34c13586e0b]
29CVE: CVE-2023-25652
30Signed-off-by: Hitendra Prajapati <hprajapati@mvista.com>
31---
32 apply.c | 14 ++++++++++++--
33 t/t4115-apply-symlink.sh | 15 +++++++++++++++
34 2 files changed, 27 insertions(+), 2 deletions(-)
35
36diff --git a/apply.c b/apply.c
37index 4f303bf..aa7111d 100644
38--- a/apply.c
39+++ b/apply.c
40@@ -4531,7 +4531,7 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
41 FILE *rej;
42 char namebuf[PATH_MAX];
43 struct fragment *frag;
44- int cnt = 0;
45+ int fd, cnt = 0;
46 struct strbuf sb = STRBUF_INIT;
47
48 for (cnt = 0, frag = patch->fragments; frag; frag = frag->next) {
49@@ -4571,7 +4571,17 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
50 memcpy(namebuf, patch->new_name, cnt);
51 memcpy(namebuf + cnt, ".rej", 5);
52
53- rej = fopen(namebuf, "w");
54+ fd = open(namebuf, O_CREAT | O_EXCL | O_WRONLY, 0666);
55+ if (fd < 0) {
56+ if (errno != EEXIST)
57+ return error_errno(_("cannot open %s"), namebuf);
58+ if (unlink(namebuf))
59+ return error_errno(_("cannot unlink '%s'"), namebuf);
60+ fd = open(namebuf, O_CREAT | O_EXCL | O_WRONLY, 0666);
61+ if (fd < 0)
62+ return error_errno(_("cannot open %s"), namebuf);
63+ }
64+ rej = fdopen(fd, "w");
65 if (!rej)
66 return error_errno(_("cannot open %s"), namebuf);
67
68diff --git a/t/t4115-apply-symlink.sh b/t/t4115-apply-symlink.sh
69index 1acb7b2..2b034ff 100755
70--- a/t/t4115-apply-symlink.sh
71+++ b/t/t4115-apply-symlink.sh
72@@ -125,4 +125,19 @@ test_expect_success SYMLINKS 'symlink escape when deleting file' '
73 test_path_is_file .git/delete-me
74 '
75
76+test_expect_success SYMLINKS '--reject removes .rej symlink if it exists' '
77+ test_when_finished "git reset --hard && git clean -dfx" &&
78+
79+ test_commit file &&
80+ echo modified >file.t &&
81+ git diff -- file.t >patch &&
82+ echo modified-again >file.t &&
83+
84+ ln -s foo file.t.rej &&
85+ test_must_fail git apply patch --reject 2>err &&
86+ test_i18ngrep "Rejected hunk" err &&
87+ test_path_is_missing foo &&
88+ test_path_is_file file.t.rej
89+'
90+
91 test_done
92--
932.25.1
94
diff --git a/meta/recipes-devtools/git/git.inc b/meta/recipes-devtools/git/git.inc
index 8b864053eb..e64472ea28 100644
--- a/meta/recipes-devtools/git/git.inc
+++ b/meta/recipes-devtools/git/git.inc
@@ -29,6 +29,7 @@ SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
29 file://CVE-2023-22490-3.patch \ 29 file://CVE-2023-22490-3.patch \
30 file://CVE-2023-23946.patch \ 30 file://CVE-2023-23946.patch \
31 file://CVE-2023-29007.patch \ 31 file://CVE-2023-29007.patch \
32 file://CVE-2023-25652.patch \
32 " 33 "
33S = "${WORKDIR}/git-${PV}" 34S = "${WORKDIR}/git-${PV}"
34 35