Skip to content

recovery: add O_NOFOLLOW|O_EXCL to prevent symlink-following in recovery file creation#448

Merged
ebiggers merged 1 commit intogoogle:masterfrom
kuranikaran:fix-recovery-symlink-following
Apr 15, 2026
Merged

recovery: add O_NOFOLLOW|O_EXCL to prevent symlink-following in recovery file creation#448
ebiggers merged 1 commit intogoogle:masterfrom
kuranikaran:fix-recovery-symlink-following

Conversation

@kuranikaran
Copy link
Copy Markdown

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:

  • filesystem.go:608: os.O_WRONLY|os.O_TRUNC|unix.O_NOFOLLOW
  • filesystem.go:747: os.O_RDONLY|unix.O_NOFOLLOW|unix.O_NONBLOCK

This change adds os.O_EXCL|unix.O_NOFOLLOW to align with the existing
security pattern.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 13, 2026

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.
@kuranikaran kuranikaran force-pushed the fix-recovery-symlink-following branch from fea6c21 to a3279c3 Compare April 13, 2026 18:02
@ebiggers ebiggers self-requested a review April 15, 2026 06:29
@ebiggers ebiggers merged commit 2dee71c into google:master Apr 15, 2026
10 checks passed
@ebiggers
Copy link
Copy Markdown
Collaborator

Merged, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants