Skip to content

gracefully handle invalid "extra-hosts" for containers#52275

Merged
vvoland merged 3 commits intomoby:masterfrom
thaJeztah:permissive_ip
Apr 1, 2026
Merged

gracefully handle invalid "extra-hosts" for containers#52275
vvoland merged 3 commits intomoby:masterfrom
thaJeztah:permissive_ip

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

daemon/pkg/opts: ValidateIPAddress: use netip.Parse

Make sure we use the same function to validate as we use to parse
the IP-address.

daemon: Daemon.restore: trim whitespace in extra-hosts

Older daemons were more permissive when handling whitespace, which
can cause the daemon to panic when handling existing container-configs;

goroutine 767 [running]:
net/netip.MustParseAddr(...)
        /usr/local/go/src/net/netip/netip.go:136
github.com/moby/moby/v2/daemon.buildSandboxOptions(0xc0009c2008, 0xc000b8c588)
        /root/build-deb/engine/daemon/container_operations.go:93 +0x1994
github.com/moby/moby/v2/daemon.(*Daemon).initializeNetworking(0xc0009a4c88, {0x5563cdcda848, 0xc000f6e810}, 0xc0009c2008, 0xc000b8c588)
        /root/build-deb/engine/daemon/container_operations.go:473 +0x33c
github.com/moby/moby/v2/daemon.(*Daemon).containerStart(0xc0009a4c88, {0x5563cdcda810, 0x5563cf72ec20}, 0xc0009c2008, 0xc000b8c588, {0x0, 0x0}, {0x0, 0x0}, 0x1)
        /root/build-deb/engine/daemon/start.go:134 +0x8d8
github.com/moby/moby/v2/daemon.(*Daemon).restore.func4(0xc000b8c588, 0xc000312d90)
        /root/build-deb/engine/daemon/daemon.go:632 +0x430
created by github.com/moby/moby/v2/daemon.(*Daemon).restore in goroutine 1
        /root/build-deb/engine/daemon/daemon.go:606 +0x7ff

Migrate existing configs to more gracefully handle startup after upgrading
from an older version of the daemon.

daemon: buildSandboxOptions: warn, not panic on invalid extra host

This is mostly a defense in-depth for handling containers that were
created with an older version of docker. Log a warning instead of
panicking on invalid values.

- Human readable description for the release notes

Prevent a daemon crash during startup after upgrading if a container config containers a malformed IP-address.

- A picture of a cute animal (not mandatory but encouraged)

Make sure we use the same function to validate as we use to parse
the IP-address.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Older daemons were more permissive when handling whitespace, which
can cause the daemon to panic when handling existing container-configs;

```

goroutine 767 [running]:
net/netip.MustParseAddr(...)
        /usr/local/go/src/net/netip/netip.go:136
github.com/moby/moby/v2/daemon.buildSandboxOptions(0xc0009c2008, 0xc000b8c588)
        /root/build-deb/engine/daemon/container_operations.go:93 +0x1994
github.com/moby/moby/v2/daemon.(*Daemon).initializeNetworking(0xc0009a4c88, {0x5563cdcda848, 0xc000f6e810}, 0xc0009c2008, 0xc000b8c588)
        /root/build-deb/engine/daemon/container_operations.go:473 +0x33c
github.com/moby/moby/v2/daemon.(*Daemon).containerStart(0xc0009a4c88, {0x5563cdcda810, 0x5563cf72ec20}, 0xc0009c2008, 0xc000b8c588, {0x0, 0x0}, {0x0, 0x0}, 0x1)
        /root/build-deb/engine/daemon/start.go:134 +0x8d8
github.com/moby/moby/v2/daemon.(*Daemon).restore.func4(0xc000b8c588, 0xc000312d90)
        /root/build-deb/engine/daemon/daemon.go:632 +0x430
created by github.com/moby/moby/v2/daemon.(*Daemon).restore in goroutine 1
        /root/build-deb/engine/daemon/daemon.go:606 +0x7ff
```

Migrate existing configs to more gracefully handle startup after upgrading
from an older version of the daemon.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
This is mostly a defense in-depth for handling containers that were
created with an older version of docker. Log a warning instead of
panicking on invalid values.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Comment thread daemon/pkg/opts/opts.go
Comment on lines 299 to 301
// IP address, and returns the value in normalized form. Leading and trailing
// whitespace is allowed, but it does not allow IPv6 addresses surrounded by
// square brackets ("[::1]").
Copy link
Copy Markdown
Contributor

@vvoland vvoland Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-// IP address, and returns the value in normalized form. Leading and trailing
-// whitespace is allowed, but it does not allow IPv6 addresses surrounded by
-// square brackets ("[::1]").
+// IP address, and returns the value in normalized form.
+// Leading and trailing whitespace is not allowed.

@thaJeztah
Copy link
Copy Markdown
Member Author

The "vm" test keeps failing; very likely unrelated, but if you can double-check? Otherwise we should just merge probably.

@vvoland vvoland merged commit 20d257b into moby:master Apr 1, 2026
294 of 300 checks passed
@thaJeztah thaJeztah deleted the permissive_ip branch April 1, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Daemon fails to start; panic: ParseAddr("x.x.x.x "): unexpected character (at " ")

2 participants