Skip to content

Commit 1f480d5

Browse files
committed
Sync with 2.34.2
* maint-2.34: Git 2.34.2 Git 2.33.2 Git 2.32.1 Git 2.31.2 GIT-VERSION-GEN: bump to v2.33.1 Git 2.30.3 setup_git_directory(): add an owner check for the top-level directory Add a function to determine whether a path is owned by the current user
2 parents 4c53a8c + 4d0b43a commit 1f480d5

File tree

13 files changed

+265
-12
lines changed

13 files changed

+265
-12
lines changed

Documentation/RelNotes/2.30.3.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Git v2.30.2 Release Notes
2+
=========================
3+
4+
This release addresses the security issue CVE-2022-24765.
5+
6+
Fixes since v2.30.2
7+
-------------------
8+
9+
* Build fix on Windows.
10+
11+
* Fix `GIT_CEILING_DIRECTORIES` with Windows-style root directories.
12+
13+
* CVE-2022-24765:
14+
On multi-user machines, Git users might find themselves
15+
unexpectedly in a Git worktree, e.g. when another user created a
16+
repository in `C:\.git`, in a mounted network drive or in a
17+
scratch space. Merely having a Git-aware prompt that runs `git
18+
status` (or `git diff`) and navigating to a directory which is
19+
supposedly not a Git worktree, or opening such a directory in an
20+
editor or IDE such as VS Code or Atom, will potentially run
21+
commands defined by that other user.
22+
23+
Credit for finding this vulnerability goes to 俞晨东; The fix was
24+
authored by Johannes Schindelin.

Documentation/RelNotes/2.31.2.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Git v2.31.2 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.30.3 to address
5+
the security issue CVE-2022-24765; see the release notes for that
6+
version for details.

Documentation/RelNotes/2.32.1.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Git v2.32.1 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.30.3 and
5+
v2.31.2 to address the security issue CVE-2022-24765; see the
6+
release notes for these versions for details.

Documentation/RelNotes/2.33.2.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Git v2.33.2 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.30.3, v2.31.2
5+
and v2.32.1 to address the security issue CVE-2022-24765; see
6+
the release notes for these versions for details.
7+
8+
In addition, it contains the following fixes:
9+
10+
* Squelch over-eager warning message added during this cycle.
11+
12+
* A bug in "git rebase -r" has been fixed.
13+
14+
* One CI task based on Fedora image noticed a not-quite-kosher
15+
construct recently, which has been corrected.

Documentation/RelNotes/2.34.2.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Git v2.34.2 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.30.3, v2.31.2,
5+
v2.32.1 and v2.33.2 to address the security issue CVE-2022-24765;
6+
see the release notes for these versions for details.

Documentation/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ include::config/rerere.txt[]
462462

463463
include::config/reset.txt[]
464464

465+
include::config/safe.txt[]
466+
465467
include::config/sendemail.txt[]
466468

467469
include::config/sequencer.txt[]

Documentation/config/safe.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
safe.directory::
2+
These config entries specify Git-tracked directories that are
3+
considered safe even if they are owned by someone other than the
4+
current user. By default, Git will refuse to even parse a Git
5+
config of a repository owned by someone else, let alone run its
6+
hooks, and this config setting allows users to specify exceptions,
7+
e.g. for intentionally shared repositories (see the `--shared`
8+
option in linkgit:git-init[1]).
9+
+
10+
This is a multi-valued setting, i.e. you can add more than one directory
11+
via `git config --add`. To reset the list of safe directories (e.g. to
12+
override any such directories specified in the system config), add a
13+
`safe.directory` entry with an empty value.
14+
+
15+
This config setting is only respected when specified in a system or global
16+
config, not when it is specified in a repository config or via the command
17+
line option `-c safe.directory=<path>`.
18+
+
19+
The value of this setting is interpolated, i.e. `~/<path>` expands to a
20+
path relative to the home directory and `%(prefix)/<path>` expands to a
21+
path relative to Git's (runtime) prefix.

compat/mingw.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../git-compat-util.h"
22
#include "win32.h"
3+
#include <aclapi.h>
34
#include <conio.h>
45
#include <wchar.h>
56
#include "../strbuf.h"
@@ -2630,6 +2631,92 @@ static void setup_windows_environment(void)
26302631
}
26312632
}
26322633

2634+
static PSID get_current_user_sid(void)
2635+
{
2636+
HANDLE token;
2637+
DWORD len = 0;
2638+
PSID result = NULL;
2639+
2640+
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
2641+
return NULL;
2642+
2643+
if (!GetTokenInformation(token, TokenUser, NULL, 0, &len)) {
2644+
TOKEN_USER *info = xmalloc((size_t)len);
2645+
if (GetTokenInformation(token, TokenUser, info, len, &len)) {
2646+
len = GetLengthSid(info->User.Sid);
2647+
result = xmalloc(len);
2648+
if (!CopySid(len, result, info->User.Sid)) {
2649+
error(_("failed to copy SID (%ld)"),
2650+
GetLastError());
2651+
FREE_AND_NULL(result);
2652+
}
2653+
}
2654+
FREE_AND_NULL(info);
2655+
}
2656+
CloseHandle(token);
2657+
2658+
return result;
2659+
}
2660+
2661+
int is_path_owned_by_current_sid(const char *path)
2662+
{
2663+
WCHAR wpath[MAX_PATH];
2664+
PSID sid = NULL;
2665+
PSECURITY_DESCRIPTOR descriptor = NULL;
2666+
DWORD err;
2667+
2668+
static wchar_t home[MAX_PATH];
2669+
2670+
int result = 0;
2671+
2672+
if (xutftowcs_path(wpath, path) < 0)
2673+
return 0;
2674+
2675+
/*
2676+
* On Windows, the home directory is owned by the administrator, but for
2677+
* all practical purposes, it belongs to the user. Do pretend that it is
2678+
* owned by the user.
2679+
*/
2680+
if (!*home) {
2681+
DWORD size = ARRAY_SIZE(home);
2682+
DWORD len = GetEnvironmentVariableW(L"HOME", home, size);
2683+
if (!len || len > size)
2684+
wcscpy(home, L"::N/A::");
2685+
}
2686+
if (!wcsicmp(wpath, home))
2687+
return 1;
2688+
2689+
/* Get the owner SID */
2690+
err = GetNamedSecurityInfoW(wpath, SE_FILE_OBJECT,
2691+
OWNER_SECURITY_INFORMATION |
2692+
DACL_SECURITY_INFORMATION,
2693+
&sid, NULL, NULL, NULL, &descriptor);
2694+
2695+
if (err != ERROR_SUCCESS)
2696+
error(_("failed to get owner for '%s' (%ld)"), path, err);
2697+
else if (sid && IsValidSid(sid)) {
2698+
/* Now, verify that the SID matches the current user's */
2699+
static PSID current_user_sid;
2700+
2701+
if (!current_user_sid)
2702+
current_user_sid = get_current_user_sid();
2703+
2704+
if (current_user_sid &&
2705+
IsValidSid(current_user_sid) &&
2706+
EqualSid(sid, current_user_sid))
2707+
result = 1;
2708+
}
2709+
2710+
/*
2711+
* We can release the security descriptor struct only now because `sid`
2712+
* actually points into this struct.
2713+
*/
2714+
if (descriptor)
2715+
LocalFree(descriptor);
2716+
2717+
return result;
2718+
}
2719+
26332720
int is_valid_win32_path(const char *path, int allow_literal_nul)
26342721
{
26352722
const char *p = path;

compat/mingw.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,13 @@ char *mingw_query_user_email(void);
453453
#include <inttypes.h>
454454
#endif
455455

456+
/**
457+
* Verifies that the specified path is owned by the user running the
458+
* current process.
459+
*/
460+
int is_path_owned_by_current_sid(const char *path);
461+
#define is_path_owned_by_current_user is_path_owned_by_current_sid
462+
456463
/**
457464
* Verifies that the given path is a valid one on Windows.
458465
*

git-compat-util.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,18 @@ static inline int git_offset_1st_component(const char *path)
430430
#define is_valid_path(path) 1
431431
#endif
432432

433+
#ifndef is_path_owned_by_current_user
434+
static inline int is_path_owned_by_current_uid(const char *path)
435+
{
436+
struct stat st;
437+
if (lstat(path, &st))
438+
return 0;
439+
return st.st_uid == geteuid();
440+
}
441+
442+
#define is_path_owned_by_current_user is_path_owned_by_current_uid
443+
#endif
444+
433445
#ifndef find_last_dir_sep
434446
static inline char *git_find_last_dir_sep(const char *path)
435447
{

0 commit comments

Comments
 (0)