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