recovery: add O_NOFOLLOW|O_EXCL to prevent symlink-following in recovery file creation#448
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
…ery file creation WriteRecoveryInstructions() opens the recovery README with os.OpenFile using O_WRONLY|O_CREATE without O_NOFOLLOW. When fscrypt encrypt runs as root, this allows a local attacker to place a symlink at the recovery file path, causing root to write through the symlink and then fchown the target file to the attacker. Adding O_EXCL|O_NOFOLLOW aligns with the existing security pattern in filesystem.go:608 and filesystem.go:747.
fea6c21 to
a3279c3
Compare
|
Merged, thanks. |
|
Hey @ebiggers, thanks for the quick merge! Since this was a security fix (symlink-following allowing root to write through a symlink + fchown when fscrypt encrypt runs under sudo), would you be open to creating a GitHub Security Advisory for this? GitHub can assign a CVE directly through the advisory process. Happy to help draft the advisory details if needed. |
|
I'm not entirely convinced this is CVE-worthy. The same issue could be claimed in any program that ever writes any file without O_NOFOLLOW, as the program could be run as root with the target directory owned by another user. Also O_NOFOLLOW doesn't solve the problem if the parent directory is owned by that other user, as well. Running programs as root against files owned by another user (when they are logged in and have the opportunity to concurrently change those files) just isn't a great practice. |
WriteRecoveryInstructions() at recovery.go:94 opens the recovery README
with os.O_WRONLY|os.O_CREATE without O_NOFOLLOW. When fscrypt encrypt
runs as root via sudo, a local attacker who controls the parent directory
can place a symlink at the recovery file path, causing root to write
through the symlink and fchown the target to the attacker.
The rest of the codebase uses O_NOFOLLOW consistently:
This change adds os.O_EXCL|unix.O_NOFOLLOW to align with the existing
security pattern.