esp-idf/tools
Frantisek Hrbata 99f9dd4c07 feat(docker): allow to add paths into git's safe.directory
With 8959555cee7e[1] ("setup_git_directory(): add an owner check for the top..")
git added an ownership check of the git directory and refuses to
run any git commands, even parsing the config file, if the git directory
is not owned by the current user. The "fatal: detected dubious ownership in repository"
is reported.

This fixes CVE-2022-24765[2], which allows to compromise user account. On a
multi-user system or e.g. on a shared file system, one user may create a "rogue"
git repository with e.g. core.fsmonitor set to an arbitrary command. Other user
may unwillingly execute this command by running e.g. git-diff or
git-status within the "rogue" git repository, which may be in one of the parent
directories. If e.g. PS1 is set to display information about a git
repository in CWD, as suggested in Git in Bash[3], the user do not need to run
any git command to trigger this, just entering some subdirectory under
this "rogue" git repository is enough, because the git command will be
started transparently through the script used in PS1. The core.fsmonitor
can be set to arbitrary command. It's purpose is to help git to identify changed files
and speed up the scanning for changed files.

rogue
├── .git     # owned by user1
└── dir1     # owned by user2
    ├── dir2 # owned by user2
    └── .git # owned by user2

user1 sets core.fsmonitor for git repository in rogue directory
$ git config --add core.fsmonitor "bash -c 'rm -rf \$HOME'"

user2 enters dir1 and runs e.g. git diff and triggers the core.fsmonitor command.

The ownership check may cause problems when running git commands in
ESP-IDF Docker container. For example user may run the container as
root, but the mounted project may be owned by a particular user.

In this case git will refuse to execute any git command within the
"/project" directory, because it's not owned by root. To overcome this,
git allows to set safe.directories, for which the ownership check is
skipped. The security check may be completely disabled by setting
safe.directories to "*". This solution was proposed in PR 12636[4], but
it would allow make it possible to exploit this vulnerability again.

This fix allows user to specify git's safe.directory in IDF_GIT_SAFE_DIR
environmental variable, which may be set during container startup.

The IDF_GIT_SAFE_DIR has same format as PATH and multiple directories can be
specified by using a ":" separator. To entirely disable this git security check
within the container, user may set IDF_GIT_SAFE_DIR='*'. This might be
heplfull in CI.

Closes https://github.com/espressif/esp-idf/pull/12636

[1] - 8959555cee
[2] - https://nvd.nist.gov/vuln/detail/cve-2022-24765
[3] - https://git-scm.com/book/en/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Bash
[4] - https://github.com/espressif/esp-idf/pull/12636

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2023-12-01 08:23:16 +01:00
..
ble
catch
ci Merge branch 'test/idf-build-apps-1.0.0_v5.1' into 'release/v5.1' 2023-11-28 14:59:39 +08:00
cmake change(version): Update version to 5.1.2 2023-11-10 07:51:59 +05:30
docker feat(docker): allow to add paths into git's safe.directory 2023-12-01 08:23:16 +01:00
esp_app_trace
esp_prov
gen_soc_caps_kconfig
idf_py_actions Merge branch 'coredump-info-offset_v5.1' into 'release/v5.1' 2023-11-16 18:56:55 +08:00
kconfig_new
ldgen fix(ldgen): duplicate entries in the generated .ld file 2023-09-21 19:38:49 +08:00
mass_mfg
mocks
requirements Merge branch 'gdb_panic_server_remove_v5.1' into 'release/v5.1' 2023-09-21 10:09:07 +08:00
templates/sample_component
test_apps ci(system): re-enable build test app for C2 and C6, clean up configs 2023-11-28 18:09:06 +01:00
test_build_system feat(ci): add test for custom cmake CMAKE_EXECUTABLE_SUFFIX 2023-11-20 11:03:28 +01:00
test_idf_py
test_idf_tools feat(tools): Add QEMU 8.0.0_20230522 to tools.json 2023-10-11 12:28:47 +07:00
test_mkdfu
test_mkuf2
test_sbom
unit-test-app
check_python_dependencies.py
check_term.py
detect_python.fish
detect_python.sh
eclipse-code-style.xml
format-minimal.sh
format.sh
gdb_panic_server.py
gen_esp_err_to_name.py
generate_debug_prefix_map.py
idf.py
idf_monitor.py
idf_size.py
idf_tools.py feat(tools): Add QEMU 8.0.0_20230522 to tools.json 2023-10-11 12:28:47 +07:00
install_util.py
mkdfu.py
mkuf2.py
python_version_checker.py
requirements.json
requirements_schema.json
set-submodules-to-github.sh
split_paths_by_spaces.py
tools.json Merge branch 'feature/add_qemu_to_tools-json_v5.1' into 'release/v5.1' 2023-11-16 18:54:46 +08:00
tools_schema.json