Skip to content

Commit a490248

Browse files
committed
daemon: daemon.prepareMountPoints(): fix panic if mount is not a volume
The daemon.lazyInitializeVolume() function only handles restoring Volumes if a Driver is specified. The Container's MountPoints field may also contain other kind of mounts (e.g., bind-mounts). Those were ignored, and don't return an error; https://github.com/moby/moby/blob/1d9c8619cded4657af1529779c5771127e8ad0e7/daemon/volumes.go#L243-L252C2 However, the prepareMountPoints() assumed each MountPoint was a volume, and logged an informational message about the volume being restored; https://github.com/moby/moby/blob/1d9c8619cded4657af1529779c5771127e8ad0e7/daemon/mounts.go#L18-L25 This would panic if the MountPoint was not a volume; github.com/docker/docker/daemon.(*Daemon).prepareMountPoints(0xc00054b7b8?, 0xc0007c2500) /root/rpmbuild/BUILD/src/engine/.gopath/src/github.com/docker/docker/daemon/mounts.go:24 +0x1c0 github.com/docker/docker/daemon.(*Daemon).restore.func5(0xc0007c2500, 0x0?) /root/rpmbuild/BUILD/src/engine/.gopath/src/github.com/docker/docker/daemon/daemon.go:552 +0x271 created by github.com/docker/docker/daemon.(*Daemon).restore /root/rpmbuild/BUILD/src/engine/.gopath/src/github.com/docker/docker/daemon/daemon.go:530 +0x8d8 panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x564e9be4c7c0] This issue was introduced in 647c2a6 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 98d3da7 commit a490248

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

daemon/mounts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ func (daemon *Daemon) prepareMountPoints(container *container.Container) error {
1818
if err := daemon.lazyInitializeVolume(container.ID, config); err != nil {
1919
return err
2020
}
21+
if config.Volume == nil {
22+
// FIXME(thaJeztah): should we check for config.Type here as well? (i.e., skip bind-mounts etc)
23+
continue
24+
}
2125
if alive {
2226
log.G(context.TODO()).WithFields(logrus.Fields{
2327
"container": container.ID,

integration/daemon/daemon_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,24 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
436436
err = c.VolumeRemove(ctx, v.Name, false)
437437
assert.NilError(t, err)
438438
})
439+
440+
// Make sure that we don't panic if the container has bind-mounts
441+
// (which should not be "restored")
442+
// Regression test for https://github.com/moby/moby/issues/45898
443+
t.Run("container with bind-mounts", func(t *testing.T) {
444+
m := mount.Mount{
445+
Type: mount.TypeBind,
446+
Source: os.TempDir(),
447+
Target: "/foo",
448+
}
449+
cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top"))
450+
defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
451+
452+
d.Restart(t, "--live-restore", "--iptables=false")
453+
454+
err := c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
455+
assert.NilError(t, err)
456+
})
439457
}
440458

441459
func TestDaemonDefaultBridgeWithFixedCidrButNoBip(t *testing.T) {

0 commit comments

Comments
 (0)