]> git.proxmox.com Git - pve-container.git/commitdiff
use sanitize_mountpoint in foreach_mountpoint
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 17 Sep 2015 11:06:58 +0000 (13:06 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 17 Sep 2015 11:22:32 +0000 (13:22 +0200)
This is for consistency as well as it's a minor security
improvement.

If the source is a path we also want to sanitize it in order
to not get broken behavior when using paths like
/dev/../something etc.

src/PVE/LXC.pm
src/PVE/VZDump/LXC.pm

index 8abc21e65504ce2dc5f19ee9a8e653efecf026a6..c7f7ef506f5e9a6229366db37e88869ba97f8cba 100644 (file)
@@ -1818,6 +1818,19 @@ sub mountpoint_names {
     return $reverse ? reverse @names : @names;
 }
 
+# The container might have *different* symlinks than the host. realpath/abs_path
+# use the actual filesystem to resolve links.
+sub sanitize_mountpoint {
+    my ($mp) = @_;
+    $mp = '/' . $mp; # we always start with a slash
+    $mp =~ s@/{2,}@/@g; # collapse sequences of slashes
+    $mp =~ s@/\./@@g; # collapse /./
+    $mp =~ s@/\.(/)?$@$1@; # collapse a trailing /. or /./
+    $mp =~ s@(.*)/[^/]+/\.\./@$1/@g; # collapse /../ without regard for symlinks
+    $mp =~ s@/\.\.(/)?$@$1@; # collapse trailing /.. or /../ disregarding symlinks
+    return $mp;
+}
+
 sub foreach_mountpoint_full {
     my ($conf, $reverse, $func) = @_;
 
@@ -1825,7 +1838,14 @@ sub foreach_mountpoint_full {
        my $value = $conf->{$key};
        next if !defined($value);
        my $mountpoint = parse_ct_mountpoint($value);
-       $mountpoint->{mp} = '/' if $key eq 'rootfs'; # just to be sure
+
+       # just to be sure: rootfs is /
+       my $path = $key eq 'rootfs' ? '/' : $mountpoint->{mp};
+       $mountpoint->{mp} = sanitize_mountpoint($path);
+
+       $path = $mountpoint->{volume};
+       $mountpoint->{volume} = sanitize_mountpoint($path) if $path =~ m|^/|;
+
        &$func($key, $mountpoint);
     }
 }
index 4c421f5ff1a6b1225602aea39ce5393feffa9387..c9a75dd5fa8c0505cdf4326fba5b8cb13a00a26f 100644 (file)
@@ -92,19 +92,6 @@ my $check_mountpoint_empty = sub {
     });
 };
 
-# The container might have *different* symlinks than the host. realpath/abs_path
-# use the actual filesystem to resolve links.
-sub sanitize_mountpoint {
-    my ($mp) = @_;
-    $mp = '/' . $mp; # we always start with a slash
-    $mp =~ s@/{2,}@/@g; # collapse sequences of slashes
-    $mp =~ s@/\./@@g; # collapse /./
-    $mp =~ s@/\.(/)?$@$1@; # collapse a trailing /. or /./
-    $mp =~ s@(.*)/[^/]+/\.\./@$1/@g; # collapse /../ without regard for symlinks
-    $mp =~ s@/\.\.(/)?$@$1@; # collapse trailing /.. or /../ disregarding symlinks
-    return $mp;
-}
-
 sub prepare {
     my ($self, $task, $vmid, $mode) = @_;
 
@@ -124,8 +111,6 @@ sub prepare {
        my $volid = $data->{volume};
        my $mount = $data->{mp};
 
-       $mount = $data->{mp} = sanitize_mountpoint($mount);
-
        return if !$volid || !$mount || $volid =~ m|^/|;
 
        if ($name ne 'rootfs' && !$data->{backup}) {