Bladeren bron

Fix layer store Get locking

Get was calling getReference without layerL held. This meant writes to
the references map could race. Such races are dangerous because they can
corrupt the map and crash the process.

Fixes #21616
Fixes #21674

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Aaron Lehmann 9 jaren geleden
bovenliggende
commit
0538981c31
1 gewijzigde bestanden met toevoegingen van 4 en 1 verwijderingen
  1. 4 1
      layer/layer_store.go

+ 4 - 1
layer/layer_store.go

@@ -334,7 +334,10 @@ func (ls *layerStore) get(l ChainID) *roLayer {
 }
 }
 
 
 func (ls *layerStore) Get(l ChainID) (Layer, error) {
 func (ls *layerStore) Get(l ChainID) (Layer, error) {
-	layer := ls.get(l)
+	ls.layerL.Lock()
+	defer ls.layerL.Unlock()
+
+	layer := ls.getWithoutLock(l)
 	if layer == nil {
 	if layer == nil {
 		return nil, ErrLayerDoesNotExist
 		return nil, ErrLayerDoesNotExist
 	}
 	}