593589
From a6fec757c8a17f3a5b92fb766b0f2eeb3b1a208a Mon Sep 17 00:00:00 2001
593589
From: Giuseppe Scrivano <gscrivan@redhat.com>
593589
Date: Thu, 19 Dec 2019 19:06:00 +0100
593589
Subject: [PATCH] store: keep graph lock during Mount
593589
593589
This solves a race condition where a mountpoint is created without the
593589
home mount being present.
593589
593589
The cause is that another process could be calling the graph driver
593589
cleanup as part of store.Shutdown() causing the unmount of the
593589
driver home directory.
593589
593589
The unmount could happen between the time the rlstore is retrieved and
593589
the actual mount, causing the driver mount to be done without a home
593589
mount below it.
593589
593589
A third process then would re-create again the home mount, shadowing
593589
the previous mount.
593589
593589
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1757845
593589
593589
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
593589
---
593589
 store.go | 16 ++++++++++++++++
593589
 1 file changed, 16 insertions(+)
593589
593589
diff --git a/store.go b/store.go
593589
index 65808b8a0..272153e51 100644
593589
--- a/vendor/github.com/containers/storage/store.go
593589
+++ b/vendor/github.com/containers/storage/store.go
593589
@@ -2479,6 +2479,10 @@ func (s *store) Mount(id, mountLabel string) (string, error) {
593589
 	if err != nil {
593589
 		return "", err
593589
 	}
593589
+
593589
+	s.graphLock.Lock()
593589
+	defer s.graphLock.Unlock()
593589
+
593589
 	rlstore.Lock()
593589
 	defer rlstore.Unlock()
593589
 	if modified, err := rlstore.Modified(); modified || err != nil {
593589
@@ -2486,6 +2490,18 @@ func (s *store) Mount(id, mountLabel string) (string, error) {
593589
 			return "", err
593589
 		}
593589
 	}
593589
+
593589
+	/* We need to make sure the home mount is present when the Mount is done.  */
593589
+	if s.graphLock.TouchedSince(s.lastLoaded) {
593589
+		s.graphDriver = nil
593589
+		s.layerStore = nil
593589
+		s.graphDriver, err = s.getGraphDriver()
593589
+		if err != nil {
593589
+			return "", err
593589
+		}
593589
+		s.lastLoaded = time.Now()
593589
+	}
593589
+
593589
 	if rlstore.Exists(id) {
593589
 		options := drivers.MountOpts{
593589
 			MountLabel: mountLabel,