teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 0037-nspawn-EROFS-for-chowning-mount-points-is-not-fatal-.patch

Zbigniew Jędrzejewski-Szmek 35bb94
From 1b7014dfc1584d1f3b10eb91c4f22e0deaca999d Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek 35bb94
From: Lauri Tirkkonen <lotheac@iki.fi>
Zbigniew Jędrzejewski-Szmek 35bb94
Date: Tue, 24 Oct 2017 20:40:50 +0300
Zbigniew Jędrzejewski-Szmek 35bb94
Subject: [PATCH] nspawn: EROFS for chowning mount points is not fatal (#7122)
Zbigniew Jędrzejewski-Szmek 35bb94
Zbigniew Jędrzejewski-Szmek 35bb94
This fixes --read-only with --private-users. mkdir_userns_p may return
Zbigniew Jędrzejewski-Szmek 35bb94
-EROFS if either mkdir or lchown fails; lchown failing is fine as the
Zbigniew Jędrzejewski-Szmek 35bb94
mount point will just be overmounted, and if mkdir fails then the
Zbigniew Jędrzejewski-Szmek 35bb94
following mount() will also fail (with ENOENT).
Zbigniew Jędrzejewski-Szmek 35bb94
Zbigniew Jędrzejewski-Szmek 35bb94
(cherry picked from commit 4f13e534282414b5e58ef31a26cc5c3f06f8cb18)
Zbigniew Jędrzejewski-Szmek 35bb94
---
Zbigniew Jędrzejewski-Szmek 35bb94
 src/nspawn/nspawn-mount.c | 8 ++++++--
Zbigniew Jędrzejewski-Szmek 35bb94
 1 file changed, 6 insertions(+), 2 deletions(-)
Zbigniew Jędrzejewski-Szmek 35bb94
Zbigniew Jędrzejewski-Szmek 35bb94
diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c
Zbigniew Jędrzejewski-Szmek 35bb94
index 531f29cb7b..9b7ceb6bdc 100644
Zbigniew Jędrzejewski-Szmek 35bb94
--- a/src/nspawn/nspawn-mount.c
Zbigniew Jędrzejewski-Szmek 35bb94
+++ b/src/nspawn/nspawn-mount.c
Zbigniew Jędrzejewski-Szmek 35bb94
@@ -598,11 +598,15 @@ int mount_all(const char *dest,
Zbigniew Jędrzejewski-Szmek 35bb94
 
Zbigniew Jędrzejewski-Szmek 35bb94
                 r = mkdir_userns_p(dest, where, 0755, mount_settings, uid_shift);
Zbigniew Jędrzejewski-Szmek 35bb94
                 if (r < 0 && r != -EEXIST) {
Zbigniew Jędrzejewski-Szmek 35bb94
-                        if (fatal)
Zbigniew Jędrzejewski-Szmek 35bb94
+                        if (fatal && r != -EROFS)
Zbigniew Jędrzejewski-Szmek 35bb94
                                 return log_error_errno(r, "Failed to create directory %s: %m", where);
Zbigniew Jędrzejewski-Szmek 35bb94
 
Zbigniew Jędrzejewski-Szmek 35bb94
                         log_debug_errno(r, "Failed to create directory %s: %m", where);
Zbigniew Jędrzejewski-Szmek 35bb94
-                        continue;
Zbigniew Jędrzejewski-Szmek 35bb94
+                        /* If we failed mkdir() or chown() due to the root
Zbigniew Jędrzejewski-Szmek 35bb94
+                         * directory being read only, attempt to mount this fs
Zbigniew Jędrzejewski-Szmek 35bb94
+                         * anyway and let mount_verbose log any errors */
Zbigniew Jędrzejewski-Szmek 35bb94
+                        if (r != -EROFS)
Zbigniew Jędrzejewski-Szmek 35bb94
+                                continue;
Zbigniew Jędrzejewski-Szmek 35bb94
                 }
Zbigniew Jędrzejewski-Szmek 35bb94
 
Zbigniew Jędrzejewski-Szmek 35bb94
                 o = mount_table[k].options;