2014-11-24 21:37:56 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='check that read-tree rejects confusing paths'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success 'create base tree' '
|
|
|
|
echo content >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m base &&
|
|
|
|
blob=$(git rev-parse HEAD:file) &&
|
|
|
|
tree=$(git rev-parse HEAD^{tree})
|
|
|
|
'
|
|
|
|
|
2014-12-16 02:15:20 +03:00
|
|
|
test_expect_success 'enable core.protectHFS for rejection tests' '
|
|
|
|
git config core.protectHFS true
|
|
|
|
'
|
|
|
|
|
2014-12-17 01:46:59 +03:00
|
|
|
test_expect_success 'enable core.protectNTFS for rejection tests' '
|
|
|
|
git config core.protectNTFS true
|
|
|
|
'
|
|
|
|
|
2014-12-16 02:15:20 +03:00
|
|
|
while read path pretty; do
|
|
|
|
: ${pretty:=$path}
|
2014-12-17 01:46:59 +03:00
|
|
|
case "$path" in
|
|
|
|
*SPACE)
|
|
|
|
path="${path%SPACE} "
|
|
|
|
;;
|
|
|
|
esac
|
2014-12-16 02:15:20 +03:00
|
|
|
test_expect_success "reject $pretty at end of path" '
|
2014-11-24 21:37:56 +03:00
|
|
|
printf "100644 blob %s\t%s" "$blob" "$path" >tree &&
|
|
|
|
bogus=$(git mktree <tree) &&
|
|
|
|
test_must_fail git read-tree $bogus
|
|
|
|
'
|
|
|
|
|
2014-12-16 02:15:20 +03:00
|
|
|
test_expect_success "reject $pretty as subtree" '
|
2014-11-24 21:37:56 +03:00
|
|
|
printf "040000 tree %s\t%s" "$tree" "$path" >tree &&
|
|
|
|
bogus=$(git mktree <tree) &&
|
|
|
|
test_must_fail git read-tree $bogus
|
|
|
|
'
|
2014-12-16 02:15:20 +03:00
|
|
|
done <<-EOF
|
2014-11-24 21:37:56 +03:00
|
|
|
.
|
|
|
|
..
|
|
|
|
.git
|
2014-11-24 21:39:12 +03:00
|
|
|
.GIT
|
2014-12-16 02:15:20 +03:00
|
|
|
${u200c}.Git {u200c}.Git
|
|
|
|
.gI${u200c}T .gI{u200c}T
|
|
|
|
.GiT${u200c} .GiT{u200c}
|
2014-12-17 01:46:59 +03:00
|
|
|
git~1
|
|
|
|
.git.SPACE .git.{space}
|
|
|
|
.\\\\.GIT\\\\foobar backslashes
|
|
|
|
.git\\\\foobar backslashes2
|
path: safeguard `.git` against NTFS Alternate Streams Accesses
Probably inspired by HFS' resource streams, NTFS supports "Alternate
Data Streams": by appending `:<stream-name>` to the file name,
information in addition to the file contents can be written and read,
information that is copied together with the file (unless copied to a
non-NTFS location).
These Alternate Data Streams are typically used for things like marking
an executable as having just been downloaded from the internet (and
hence not necessarily being trustworthy).
In addition to a stream name, a stream type can be appended, like so:
`:<stream-name>:<stream-type>`. Unless specified, the default stream
type is `$DATA` for files and `$INDEX_ALLOCATION` for directories. In
other words, `.git::$INDEX_ALLOCATION` is a valid way to reference the
`.git` directory!
In our work in Git v2.2.1 to protect Git on NTFS drives under
`core.protectNTFS`, we focused exclusively on NTFS short names, unaware
of the fact that NTFS Alternate Data Streams offer a similar attack
vector.
Let's fix this.
Seeing as it is better to be safe than sorry, we simply disallow paths
referring to *any* NTFS Alternate Data Stream of `.git`, not just
`::$INDEX_ALLOCATION`. This also simplifies the implementation.
This closes CVE-2019-1352.
Further reading about NTFS Alternate Data Streams:
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/c54dec26-1551-4d3a-a0ea-4fa40f848eb3
Reported-by: Nicolas Joly <Nicolas.Joly@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2019-08-28 13:22:17 +03:00
|
|
|
.git...:alternate-stream
|
2014-11-24 21:37:56 +03:00
|
|
|
EOF
|
|
|
|
|
2014-12-16 02:15:20 +03:00
|
|
|
test_expect_success 'utf-8 paths allowed with core.protectHFS off' '
|
|
|
|
test_when_finished "git read-tree HEAD" &&
|
|
|
|
test_config core.protectHFS false &&
|
|
|
|
printf "100644 blob %s\t%s" "$blob" ".gi${u200c}t" >tree &&
|
|
|
|
ok=$(git mktree <tree) &&
|
|
|
|
git read-tree $ok
|
|
|
|
'
|
|
|
|
|
2014-11-24 21:37:56 +03:00
|
|
|
test_done
|