Skip to content

Commit 2dee71c

Browse files
karanh3krboyebiggers
authored andcommitted
recovery: add O_NOFOLLOW|O_EXCL to prevent symlink-following in recovery 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.
1 parent 298ed2a commit 2dee71c

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

actions/recovery.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"strconv"
2525

26+
"golang.org/x/sys/unix"
2627
"google.golang.org/protobuf/proto"
2728

2829
"github.com/google/fscrypt/crypto"
@@ -91,7 +92,7 @@ func AddRecoveryPassphrase(policy *Policy, dirname string) (*crypto.Key, *Protec
9192
// passphrase in a different location if they actually need it.
9293
func WriteRecoveryInstructions(recoveryPassphrase *crypto.Key, recoveryProtector *Protector,
9394
policy *Policy, path string) error {
94-
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0600)
95+
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL|unix.O_NOFOLLOW, 0600)
9596
if err != nil {
9697
return err
9798
}

0 commit comments

Comments
 (0)