-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix symlink race condition (TOCTOU): use O_NOFOLLOW to open files
The rsync vulnerability CVE-2024-12747 also affected gokrazy/rsync (before this commit): An attacker could replace a regular file (= contents will be transferred) with a symlink pointing outside of the specified directory. To reproduce the issue, run TestReceiverSymlinkTraversal with the following change to rsyncd/rsyncd.go applied to simulate an attack: --- i/rsyncd/rsyncd.go +++ w/rsyncd/rsyncd.go @@ -373,6 +375,16 @@ func (s *Server) HandleConn(module Module, rd io.Reader, crd *countingReader, cw s.logger.Printf("file list sent") + // HACK: swap out the passwd file with a symlink to /etc/passwd + if err := os.Remove(filepath.Join(module.Path, "passwd")); err != nil { + return err + } + if err := os.Symlink("../passwd", filepath.Join(module.Path, "passwd")); err != nil { + return err + } + s.logger.Printf("HACK: swapped passwd file for symlink") + // Sort the file list. The client sorts, so we need to sort, too (in the // same way!), otherwise our indices do not match what the client will // request. Before this commit, the test would transfer the "secret" contents; after this commit, the test fails with "no such file or directory".
- Loading branch information
1 parent
3a9d1ec
commit 1b1fbf6
Showing
7 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:build !unix | ||
|
||
package nofollow | ||
|
||
// Maybe resolves to unix.O_NOFOLLOW on unix systems, | ||
// 0 on other platforms. TODO(go1.24): use os.Root. | ||
const Maybe = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build unix | ||
|
||
package nofollow | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
// Maybe resolves to unix.O_NOFOLLOW on unix systems, | ||
// 0 on other platforms. TODO(go1.24): use os.Root. | ||
const Maybe = unix.O_NOFOLLOW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters