summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/git/files/CVE-2021-40330.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/git/files/CVE-2021-40330.patch')
-rw-r--r--meta/recipes-devtools/git/files/CVE-2021-40330.patch108
1 files changed, 108 insertions, 0 deletions
diff --git a/meta/recipes-devtools/git/files/CVE-2021-40330.patch b/meta/recipes-devtools/git/files/CVE-2021-40330.patch
new file mode 100644
index 0000000000..725f98f0b7
--- /dev/null
+++ b/meta/recipes-devtools/git/files/CVE-2021-40330.patch
@@ -0,0 +1,108 @@
1From e77ca0c7d577408878d2b3e8c7336e6119cb3931 Mon Sep 17 00:00:00 2001
2From: Minjae Kim <flowergom@gmail.com>
3Date: Thu, 25 Nov 2021 06:36:26 +0000
4Subject: [PATCH] git_connect_git(): forbid newlines in host and path
5
6When we connect to a git:// server, we send an initial request that
7looks something like:
8
9 002dgit-upload-pack repo.git\0host=example.com
10
11If the repo path contains a newline, then it's included literally, and
12we get:
13
14 002egit-upload-pack repo
15 .git\0host=example.com
16
17This works fine if you really do have a newline in your repository name;
18the server side uses the pktline framing to parse the string, not
19newlines. However, there are many _other_ protocols in the wild that do
20parse on newlines, such as HTTP. So a carefully constructed git:// URL
21can actually turn into a valid HTTP request. For example:
22
23 git://localhost:1234/%0d%0a%0d%0aGET%20/%20HTTP/1.1 %0d%0aHost:localhost%0d%0a%0d%0a
24
25becomes:
26
27 0050git-upload-pack /
28 GET / HTTP/1.1
29 Host:localhost
30
31 host=localhost:1234
32
33on the wire. Again, this isn't a problem for a real Git server, but it
34does mean that feeding a malicious URL to Git (e.g., through a
35submodule) can cause it to make unexpected cross-protocol requests.
36Since repository names with newlines are presumably quite rare (and
37indeed, we already disallow them in git-over-http), let's just disallow
38them over this protocol.
39
40Hostnames could likewise inject a newline, but this is unlikely a
41problem in practice; we'd try resolving the hostname with a newline in
42it, which wouldn't work. Still, it doesn't hurt to err on the side of
43caution there, since we would not expect them to work in the first
44place.
45
46The ssh and local code paths are unaffected by this patch. In both cases
47we're trying to run upload-pack via a shell, and will quote the newline
48so that it makes it intact. An attacker can point an ssh url at an
49arbitrary port, of course, but unless there's an actual ssh server
50there, we'd never get as far as sending our shell command anyway. We
51_could_ similarly restrict newlines in those protocols out of caution,
52but there seems little benefit to doing so.
53
54The new test here is run alongside the git-daemon tests, which cover the
55same protocol, but it shouldn't actually contact the daemon at all. In
56theory we could make the test more robust by setting up an actual
57repository with a newline in it (so that our clone would succeed if our
58new check didn't kick in). But a repo directory with newline in it is
59likely not portable across all filesystems. Likewise, we could check
60git-daemon's log that it was not contacted at all, but we do not
61currently record the log (and anyway, it would make the test racy with
62the daemon's log write). We'll just check the client-side stderr to make
63sure we hit the expected code path.
64
65Reported-by: Harold Kim <h.kim@flatt.tech>
66Signed-off-by: Jeff King <peff@peff.net>
67Signed-off-by: Junio C Hamano <gitster@pobox.com>
68
69Upstream-Status: Backported [https://github.com/git/git/commit/a02ea577174ab8ed18f847cf1693f213e0b9c473]
70CVE: CVE-2021-40330
71Signed-off-by: Minjae Kim <flowergom@gmail.com>
72---
73 connect.c | 2 ++
74 t/t5570-git-daemon.sh | 5 +++++
75 2 files changed, 7 insertions(+)
76
77diff --git a/connect.c b/connect.c
78index b6451ab..929de9a 100644
79--- a/connect.c
80+++ b/connect.c
81@@ -1064,6 +1064,8 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport,
82 target_host = xstrdup(hostandport);
83
84 transport_check_allowed("git");
85+ if (strchr(target_host, '\n') || strchr(path, '\n'))
86+ die(_("newline is forbidden in git:// hosts and repo paths"));
87
88 /*
89 * These underlying connection commands die() if they
90diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh
91index 34487bb..79cd218 100755
92--- a/t/t5570-git-daemon.sh
93+++ b/t/t5570-git-daemon.sh
94@@ -103,6 +103,11 @@ test_expect_success 'fetch notices corrupt idx' '
95 )
96 '
97
98+test_expect_success 'client refuses to ask for repo with newline' '
99+ test_must_fail git clone "$GIT_DAEMON_URL/repo$LF.git" dst 2>stderr &&
100+ test_i18ngrep newline.is.forbidden stderr
101+'
102+
103 test_remote_error()
104 {
105 do_export=YesPlease
106--
1072.17.1
108