Subject: Bug: permissions problem when recursively cloning from a suid program

From: [email-masked]
Date: Tue, 5 Jan 2021 13:07:27 -0500

What did you do before the bug happened? (Steps to reproduce your issue)

Hi, i tried to clone a repository with submodules from a program running with the suid/guid bit set.

What did you expect to happen? (Expected behavior)

It should clone the repository, with the submodules, with permissions from the owner of the suid program.

What happened instead? (Actual behavior)

git fails with a permissions error:

```
error: could not lock config file /path/to/.git/config: Permission denied
fatal: Failed to register url for submodule path
```

What's different between what you expected and what actually happened?

Cloning failed when fetching submodules (--recursive). However, it only works without submodules.

Anything else you want to add:

I could reproduce the bug on the next branch. I have a small reproduction case. It's a rust program, but the code is a bit more convoluted so it works without any dependency (just the standard library). Reproduction instructions in the repository:

https://tildegit.org/southerntofu/testsuid

[System Info]
git version:
git version 2.30.0.284.gd98b1dd5ea
cpu: x86_64
built from commit: d98b1dd5eaa7327399716162c746c9bd3cac3866
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
[REDACTED]
$SHELL (typically, interactive shell): /bin/bash