Skip to content

Commit

Permalink
Don't blindly reuse state from a previous layer when re-creating it
Browse files Browse the repository at this point in the history
We have reports in the wild of a layer store where two symbolic links
in linkDir point to the same layer. That could only happen when calling
Driver.create with a previously-used layer ID (which happens all the time
because pulls use deterministic layer IDs), without fully deleting
the previous version of the layer (so far, we don't know how that has
happened).

To avoid such situations, don't just leave whatever was in
the layer directory laying around; try to remove any pre-existing
contents, as well as the symbolic link in linkDir, if any.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Apr 22, 2022
1 parent 565d1f9 commit 2a3194c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/overlay/overlay.go
Expand Up @@ -939,6 +939,16 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts, disable
rootUID = int(st.UID())
rootGID = int(st.GID())
}

if _, err := system.Lstat(dir); err == nil {
logrus.Warnf("Trying to create a layer %#v while directory %q already exists; removing it first", id, dir)
// Don’t just os.RemoveAll(dir) here; d.Remove also removes the link in linkDir,
// so that we can’t end up with two symlinks in linkDir pointing to the same layer.
if err := d.Remove(id); err != nil {
return errors.Wrapf(err, "removing a pre-existing layer directory %q", dir)
}
}

if err := idtools.MkdirAllAndChownNew(dir, 0700, idPair); err != nil {
return err
}
Expand Down

0 comments on commit 2a3194c

Please sign in to comment.