From 9d6e4c7fd37ceb5ad798e4d2ca949a1f1b710b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 17 Feb 2022 18:42:40 +0100 Subject: [PATCH] Lock overlay.Driver.locker before creating a layer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's _completely_ unclear to me why we need this driver-specific locking when the whole layerStore is locked before calling the driver; but if it makes any sense at all, and Driver.Remove is taking the lock, it seems that driver.create should take the lock as well. Note that additionalLayer.CreateAs is not holding Driver.locker over its modifications; this does not change that. Signed-off-by: Miloslav Trmač --- drivers/overlay/overlay.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/overlay/overlay.go b/drivers/overlay/overlay.go index c911acb5c3..fc3f9d7e0e 100644 --- a/drivers/overlay/overlay.go +++ b/drivers/overlay/overlay.go @@ -942,6 +942,11 @@ func (d *Driver) create(id, parent string, opts *graphdriver.CreateOpts, disable rootUID = int(st.UID()) rootGID = int(st.GID()) } + + // --- Only access "dir" below. + d.locker.Lock(id) + defer d.locker.Unlock(id) + if err := idtools.MkdirAllAndChownNew(dir, 0700, idPair); err != nil { return err }