The vulnerability in go-billy stems from insufficient validation and missing safety mechanisms when handling symbolic links (symlinks). This can lead to infinite loops, uncontrolled recursion, and resource exhaustion when processing crafted or malformed filesystem structures. The root cause is the lack of cycle detection and depth limits during symlink resolution.
The patches address these issues by introducing several key changes:
-
Symlink Loop Detection: In helper/chroot/chroot.go, the resolveFollowedPath function was modified to detect and reject symlink loops. It now returns a syscall.ELOOP error if a symlink points to itself or creates a circular reference.
-
Maximum Symlink Follow Limit: The resolveFollowedPath function now includes a counter (followed) that limits the number of symlinks that can be followed during path resolution to a maximum of 8 (defined by maxFollowedSymlinks). This prevents excessive recursion and resource consumption.
-
Use of Lstat in removeAll: In util/util.go, the removeAll function was changed to use lstat instead of Stat. lstat does not follow symlinks, which prevents the function from entering an infinite loop when it encounters a symlink that creates a directory cycle.
By implementing these changes, the patched versions of go-billy are no longer vulnerable to denial-of-service attacks that exploit the mishandling of symlinks.