Skip to content

Commit

Permalink
Merge pull request libgit2#5329 from pks-t/ethomson/v0.27.10
Browse files Browse the repository at this point in the history
Security release v0.27.10
  • Loading branch information
pks-t authored Dec 10, 2019
2 parents 3828d7a + 34c9295 commit 45c6187
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 53 deletions.
60 changes: 60 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
v0.27.10
--------

This is a security release fixing the following issues:

- CVE-2019-1348: the fast-import stream command "feature
export-marks=path" allows writing to arbitrary file paths. As
libgit2 does not offer any interface for fast-import, it is not
susceptible to this vulnerability.

- CVE-2019-1349: by using NTFS 8.3 short names, backslashes or
alternate filesystreams, it is possible to cause submodules to
be written into pre-existing directories during a recursive
clone using git. As libgit2 rejects cloning into non-empty
directories by default, it is not susceptible to this
vulnerability.

- CVE-2019-1350: recursive clones may lead to arbitrary remote
code executing due to improper quoting of command line
arguments. As libgit2 uses libssh2, which does not require us
to perform command line parsing, it is not susceptible to this
vulnerability.

- CVE-2019-1351: Windows provides the ability to substitute
drive letters with arbitrary letters, including multi-byte
Unicode letters. To fix any potential issues arising from
interpreting such paths as relative paths, we have extended
detection of DOS drive prefixes to accomodate for such cases.

- CVE-2019-1352: by using NTFS-style alternative file streams for
the ".git" directory, it is possible to overwrite parts of the
repository. While this has been fixed in the past for Windows,
the same vulnerability may also exist on other systems that
write to NTFS filesystems. We now reject any paths starting
with ".git:" on all systems.

- CVE-2019-1353: by using NTFS-style 8.3 short names, it was
possible to write to the ".git" directory and thus overwrite
parts of the repository, leading to possible remote code
execution. While this problem was already fixed in the past for
Windows, other systems accessing NTFS filesystems are
vulnerable to this issue too. We now enable NTFS protecions by
default on all systems to fix this attack vector.

- CVE-2019-1354: on Windows, backslashes are not a valid part of
a filename but are instead interpreted as directory separators.
As other platforms allowed to use such paths, it was possible
to write such invalid entries into a Git repository and was
thus an attack vector to write into the ".git" dierctory. We
now reject any entries starting with ".git\" on all systems.

- CVE-2019-1387: it is possible to let a submodule's git
directory point into a sibling's submodule directory, which may
result in overwriting parts of the Git repository and thus lead
to arbitrary command execution. As libgit2 doesn't provide any
way to do submodule clones natively, it is not susceptible to
this vulnerability. Users of libgit2 that have implemented
recursive submodule clones manually are encouraged to review
their implementation for this vulnerability.

v0.27.9
-------

Expand Down
4 changes: 2 additions & 2 deletions include/git2/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#ifndef INCLUDE_git_version_h__
#define INCLUDE_git_version_h__

#define LIBGIT2_VERSION "0.27.9"
#define LIBGIT2_VERSION "0.27.10"
#define LIBGIT2_VER_MAJOR 0
#define LIBGIT2_VER_MINOR 27
#define LIBGIT2_VER_REVISION 9
#define LIBGIT2_VER_REVISION 10
#define LIBGIT2_VER_PATCH 0

#define LIBGIT2_SOVERSION 27
Expand Down
73 changes: 52 additions & 21 deletions src/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,29 @@
#include <stdio.h>
#include <ctype.h>

#define LOOKS_LIKE_DRIVE_PREFIX(S) (git__isalpha((S)[0]) && (S)[1] == ':')
static int dos_drive_prefix_length(const char *path)
{
int i;

/*
* Does it start with an ASCII letter (i.e. highest bit not set),
* followed by a colon?
*/
if (!(0x80 & (unsigned char)*path))
return *path && path[1] == ':' ? 2 : 0;

/*
* While drive letters must be letters of the English alphabet, it is
* possible to assign virtually _any_ Unicode character via `subst` as
* a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff
* like this:
*
* subst ֍: %USERPROFILE%\Desktop
*/
for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++)
; /* skip first UTF-8 character */
return path[i] == ':' ? i + 1 : 0;
}

#ifdef GIT_WIN32
static bool looks_like_network_computer_name(const char *path, int pos)
Expand Down Expand Up @@ -123,11 +145,11 @@ static int win32_prefix_length(const char *path, int len)
GIT_UNUSED(len);
#else
/*
* Mimic unix behavior where '/.git' returns '/': 'C:/.git' will return
* 'C:/' here
* Mimic unix behavior where '/.git' returns '/': 'C:/.git'
* will return 'C:/' here
*/
if (len == 2 && LOOKS_LIKE_DRIVE_PREFIX(path))
return 2;
if (dos_drive_prefix_length(path) == len)
return len;

/*
* Similarly checks if we're dealing with a network computer name
Expand Down Expand Up @@ -260,11 +282,11 @@ const char *git_path_topdir(const char *path)

int git_path_root(const char *path)
{
int offset = 0;
int offset = 0, prefix_len;

/* Does the root of the path look like a windows drive ? */
if (LOOKS_LIKE_DRIVE_PREFIX(path))
offset += 2;
if ((prefix_len = dos_drive_prefix_length(path)))
offset += prefix_len;

#ifdef GIT_WIN32
/* Are we dealing with a windows network path? */
Expand Down Expand Up @@ -1609,8 +1631,12 @@ GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size
if (!start)
return true;

/* Reject paths like ".git\" */
if (path[start] == '\\')
/*
* Reject paths that start with Windows-style directory separators
* (".git\") or NTFS alternate streams (".git:") and could be used
* to write to the ".git" directory on Windows platforms.
*/
if (path[start] == '\\' || path[start] == ':')
return false;

/* Reject paths like '.git ' or '.git.' */
Expand All @@ -1622,12 +1648,21 @@ GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size
return false;
}

GIT_INLINE(bool) only_spaces_and_dots(const char *path)
/*
* Windows paths that end with spaces and/or dots are elided to the
* path without them for backward compatibility. That is to say
* that opening file "foo ", "foo." or even "foo . . ." will all
* map to a filename of "foo". This function identifies spaces and
* dots at the end of a filename, whether the proper end of the
* filename (end of string) or a colon (which would indicate a
* Windows alternate data stream.)
*/
GIT_INLINE(bool) ntfs_end_of_filename(const char *path)
{
const char *c = path;

for (;; c++) {
if (*c == '\0')
if (*c == '\0' || *c == ':')
return true;
if (*c != ' ' && *c != '.')
return false;
Expand All @@ -1642,13 +1677,13 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const

if (name[0] == '.' && len >= dotgit_len &&
!strncasecmp(name + 1, dotgit_name, dotgit_len)) {
return !only_spaces_and_dots(name + dotgit_len + 1);
return !ntfs_end_of_filename(name + dotgit_len + 1);
}

/* Detect the basic NTFS shortname with the first six chars */
if (!strncasecmp(name, dotgit_name, 6) && name[6] == '~' &&
name[7] >= '1' && name[7] <= '4')
return !only_spaces_and_dots(name + 8);
return !ntfs_end_of_filename(name + 8);

/* Catch fallback names */
for (i = 0, saw_tilde = 0; i < 8; i++) {
Expand All @@ -1670,7 +1705,7 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const
}
}

return !only_spaces_and_dots(name + i);
return !ntfs_end_of_filename(name + i);
}

GIT_INLINE(bool) verify_char(unsigned char c, unsigned int flags)
Expand Down Expand Up @@ -1804,7 +1839,7 @@ GIT_INLINE(unsigned int) dotgit_flags(
git_repository *repo,
unsigned int flags)
{
int protectHFS = 0, protectNTFS = 0;
int protectHFS = 0, protectNTFS = 1;
int error = 0;

flags |= GIT_PATH_REJECT_DOT_GIT_LITERAL;
Expand All @@ -1813,16 +1848,12 @@ GIT_INLINE(unsigned int) dotgit_flags(
protectHFS = 1;
#endif

#ifdef GIT_WIN32
protectNTFS = 1;
#endif

if (repo && !protectHFS)
error = git_repository__cvar(&protectHFS, repo, GIT_CVAR_PROTECTHFS);
if (!error && protectHFS)
flags |= GIT_PATH_REJECT_DOT_GIT_HFS;

if (repo && !protectNTFS)
if (repo)
error = git_repository__cvar(&protectNTFS, repo, GIT_CVAR_PROTECTNTFS);
if (!error && protectNTFS)
flags |= GIT_PATH_REJECT_DOT_GIT_NTFS;
Expand Down
2 changes: 1 addition & 1 deletion src/repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ typedef enum {
/* core.protectHFS */
GIT_PROTECTHFS_DEFAULT = GIT_CVAR_FALSE,
/* core.protectNTFS */
GIT_PROTECTNTFS_DEFAULT = GIT_CVAR_FALSE,
GIT_PROTECTNTFS_DEFAULT = GIT_CVAR_TRUE,
/* core.fsyncObjectFiles */
GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CVAR_FALSE,
} git_cvar_value;
Expand Down
13 changes: 11 additions & 2 deletions tests/checkout/nasty.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ void test_checkout_nasty__dot_git_dot(void)
*/
void test_checkout_nasty__git_tilde1(void)
{
#ifdef GIT_WIN32
test_checkout_fails("refs/heads/git_tilde1", ".git/foobar");
#endif
test_checkout_fails("refs/heads/git_tilde1", "git~1/foobar");
}

/* A tree that contains an entry "git~2", when we have forced the short
Expand Down Expand Up @@ -274,6 +273,16 @@ void test_checkout_nasty__dot_git_colon_stuff(void)
#endif
}

/* A tree that contains an entry ".git::$INDEX_ALLOCATION" because NTFS
* will interpret that as a synonym to ".git", even when mounted via SMB
* on macOS.
*/
void test_checkout_nasty__dotgit_alternate_data_stream(void)
{
test_checkout_fails("refs/heads/dotgit_alternate_data_stream", ".git/dummy-file");
test_checkout_fails("refs/heads/dotgit_alternate_data_stream", ".git::$INDEX_ALLOCATION/dummy-file");
}

/* Trees that contains entries with a tree ".git" that contain
* byte sequences:
* { 0xe2, 0x80, 0x8c }
Expand Down
2 changes: 1 addition & 1 deletion tests/clar_libgit2.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* calls that are supposed to fail!
*/
#define cl_git_fail(expr) do { \
giterr_clear(); \
if ((expr) == 0) \
giterr_clear(), \
cl_git_report_failure(0, 0, __FILE__, __LINE__, "Function call succeeded: " #expr); \
} while (0)

Expand Down
Loading

0 comments on commit 45c6187

Please sign in to comment.