Skip to content

Allow the macOS sandbox to write in the /var/folders/ and /var/db/mds/ directories#4797

Merged
kit-ty-kate merged 1 commit intoocaml:masterfrom
kit-ty-kate:relax-sandbox-macos
Nov 4, 2025
Merged

Allow the macOS sandbox to write in the /var/folders/ and /var/db/mds/ directories#4797
kit-ty-kate merged 1 commit intoocaml:masterfrom
kit-ty-kate:relax-sandbox-macos

Conversation

@kit-ty-kate
Copy link
Copy Markdown
Member

@kit-ty-kate kit-ty-kate commented Aug 12, 2021

This is an attempt at fixing #4389
Fixes discuss.ocaml.org#17407

I've used dtrace on /usr/bin/security but I still can't find the exact point where something is written in that directory.
It looks related to something in /private/var/db/mds, probably a symlink to /private/var/folders.

In any case i've looked around and realized that macports had similar things so maybe it makes sense(?). They also have other things but I'm not sure we should allow even more: https://github.com/macports/macports-base/blob/2c6fc24ddd1d6961afa83c5b35be12224b6850f6/src/port1.0/portsandbox.tcl#L92

All in all I have no idea what this directory is supposed to be in the context of /usr/bin/security. Their commit adding it doesn't say anything either: macports/macports-base@e3eceea

Several blog posts in the wild are also trying to understand what's up with this directory:

hier(7) says it's "per-user temporary files and caches", so allowing writes like macports does doesn't seem right to me.

However, I found out (late into writing this PR even ^^") that if we forbid reads into that directory, /usr/bin/security won't try to write in it and still succeeds.
This is most likely a bug in macOS itself but there we are!

cc @hannesm

Backported to the 2.5 branch in #6775

@kit-ty-kate kit-ty-kate changed the title Relax the macOS sandbox (fixes #4389) Make the macOS sandbox stricter to workaround a macOS bug (fixes #4389) Aug 12, 2021
@kit-ty-kate kit-ty-kate linked an issue Aug 12, 2021 that may be closed by this pull request
@rjbou rjbou requested a review from AltGr August 23, 2021 16:06
@rjbou rjbou force-pushed the relax-sandbox-macos branch from 865f183 to 416a74e Compare September 2, 2021 14:49
@rjbou rjbou added this to the 2.2.0~alpha milestone Sep 2, 2021
@dra27
Copy link
Copy Markdown
Member

dra27 commented Sep 3, 2021

What's up with the macOS test?

@rjbou rjbou force-pushed the relax-sandbox-macos branch from 416a74e to 6d4a26b Compare September 13, 2021 15:58
@kit-ty-kate
Copy link
Copy Markdown
Member Author

kit-ty-kate commented Sep 13, 2021

I've sent a bug report to Apple about it btw.

@rjbou
Copy link
Copy Markdown
Collaborator

rjbou commented Sep 15, 2021

What's up with the macOS test?

Found it!

+ ${BASEDIR}/OPAM/opam-init/hooks/sandbox.sh "build" "sh" "-c" "echo SUCCESS | tee check-write"
- shell-init: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
- SUCCESS

@rjbou
Copy link
Copy Markdown
Collaborator

rjbou commented Sep 15, 2021

So sandbox check is failing, and it is removed from config file.

@rjbou
Copy link
Copy Markdown
Collaborator

rjbou commented May 20, 2022

From tests, seems that this changes disable sandbox.

@kit-ty-kate
Copy link
Copy Markdown
Member Author

kit-ty-kate commented Apr 9, 2025

Well, time to unearth this and do an emergency point release tomorrow i guess https://discuss.ocaml.org/t/cant-install-async-0-17-0-on-macos-15-4/16468/3

The current version of the patch doesn't work but i'll push the one that does.

@kit-ty-kate kit-ty-kate modified the milestones: 2.3.1, 2.5.0~alpha1 Jul 28, 2025
@rjbou rjbou self-requested a review October 14, 2025 10:05
…mds/` directories

It is required by some of macOS core tools such as security(1) and
previous TMPDIR stored in /var/folders/*/*/T/ have been seen accessed by
xcode in the wild on occasion.

While the /var/folders/*/*/C/ directory contain things that are kept
indefinitely, these files are in theory understood by applications to be
writeable by anyone and thus not trusted.

The mds subdirectory is a cache used to search for files in the system.

Both of these are part of other tools that use sandbox-exec such as
MacPorts. See for example:

https://github.com/macports/macports-base/blob/2c6fc24ddd1d6961afa83c5b35be12224b6850f6/src/port1.0/portsandbox.tcl#L92
@kit-ty-kate kit-ty-kate changed the title Make the macOS sandbox stricter to workaround a macOS bug (fixes #4389) Allow the macOS sandbox to write in the /var/folders/ and /var/db/mds/ directories Oct 16, 2025
@kit-ty-kate
Copy link
Copy Markdown
Member Author

Coping the new commit description:

Allow the macOS sandbox to write in the `/var/folders/` and `/var/db/mds/` directories

It is required by some of macOS core tools such as security(1) and
previous TMPDIR stored in /var/folders/*/*/T/ have been seen accessed by
xcode in the wild on occasion.

While the /var/folders/*/*/C/ directory contain things that are kept
indefinitely, these files are in theory understood by applications to be
writeable by anyone and thus not trusted.

The mds subdirectory is a cache used to search for files in the system.

Both of these are part of other tools that use sandbox-exec such as
MacPorts. See for example:

https://github.com/macports/macports-base/blob/2c6fc24ddd1d6961afa83c5b35be12224b6850f6/src/port1.0/portsandbox.tcl#L92

@kit-ty-kate kit-ty-kate marked this pull request as ready for review October 17, 2025 00:22
Copy link
Copy Markdown
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (if all very strange!)

Copy link
Copy Markdown
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed on dev meeting: The PR is good to go.

@rjbou
Copy link
Copy Markdown
Collaborator

rjbou commented Nov 4, 2025

ocaml-benchmarks is failing with no log, it's out of the scope of this PR.

@kit-ty-kate
Copy link
Copy Markdown
Member Author

The ocaml-benchmark failure comes from ocaml/infrastructure#179. Ignoring.

@kit-ty-kate kit-ty-kate merged commit b5b0235 into ocaml:master Nov 4, 2025
43 of 44 checks passed
@kit-ty-kate kit-ty-kate modified the milestones: 2.5.0~alpha2, 2.6.0~alpha1 Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sandbox too strict on macos

4 participants