aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'patches/util-linux/2.36.1/util-linux-2.36.1-switch_root-check-if-mountpoint-exists.patch')
-rw-r--r--patches/util-linux/2.36.1/util-linux-2.36.1-switch_root-check-if-mountpoint-exists.patch31
1 files changed, 31 insertions, 0 deletions
diff --git a/patches/util-linux/2.36.1/util-linux-2.36.1-switch_root-check-if-mountpoint-exists.patch b/patches/util-linux/2.36.1/util-linux-2.36.1-switch_root-check-if-mountpoint-exists.patch
new file mode 100644
index 0000000..17bcd91
--- /dev/null
+++ b/patches/util-linux/2.36.1/util-linux-2.36.1-switch_root-check-if-mountpoint-exists.patch
@@ -0,0 +1,31 @@
+switch_root: check if mount point to move even exists
+
+--- a/sys-utils/switch_root.c
++++ b/sys-utils/switch_root.c
+@@ -131,7 +131,12 @@ static int switchroot(const char *newroot)
+ int i;
+ int cfd;
+ pid_t pid;
+- struct stat newroot_stat, sb;
++ struct stat newroot_stat, oldroot_stat, sb;
++
++ if (stat("/", &oldroot_stat) != 0) {
++ warn(_("stat of %s failed"), "/");
++ return -1;
++ }
+
+ if (stat(newroot, &newroot_stat) != 0) {
+ warn(_("stat of %s failed"), newroot);
+@@ -143,6 +148,11 @@ static int switchroot(const char *newroot)
+
+ snprintf(newmount, sizeof(newmount), "%s%s", newroot, umounts[i]);
+
++ if ((stat(umounts[i], &sb) == 0) && sb.st_dev == oldroot_stat.st_dev) {
++ /* mount point to move seems to be a normal directory or stat failed */
++ continue;
++ }
++
+ if ((stat(newmount, &sb) != 0) || (sb.st_dev != newroot_stat.st_dev)) {
+ /* mount point seems to be mounted already or stat failed */
+ umount2(umounts[i], MNT_DETACH);
+