From 7412d5fbce5e05c53da45a38ffdfcff048721336 Mon Sep 17 00:00:00 2001 From: Johannes 'josch' Schauer Date: Mon, 8 Oct 2018 11:26:31 +0200 Subject: [PATCH] also unmount in unshare mode to prevent wrong directory permissions of mount targets --- mmdebstrap | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mmdebstrap b/mmdebstrap index 8c4e2fd..945f441 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -1135,10 +1135,19 @@ sub setup { die "unsupported type: $type"; } } - # no need to umount if the mount namespace was unshared - if ($options->{mode} ne 'unshare') { - 0 == system('umount', '--no-mtab', "$options->{root}/sys") or die "umount failed: $?"; + # naturally we have to clean up after ourselves in sudo mode where we + # do a real mount. But we also need to unmount in unshare mode because + # otherwise, even with the --one-file-system tar option, the + # permissions of the mount source will be stored and not the mount + # target (the directory) + if ($options->{mode} eq 'unshare') { + # since we cannot write to /etc/mtab we need --no-mtab + # unmounting /sys only seems to be successful with --lazy + 0 == system('umount', '--no-mtab', '--lazy', "$options->{root}/sys") or die "umount failed: $?"; 0 == system('umount', '--no-mtab', "$options->{root}/proc") or die "umount failed: $?"; + } else { + 0 == system('umount', "$options->{root}/sys") or die "umount failed: $?"; + 0 == system('umount', "$options->{root}/proc") or die "umount failed: $?"; } }