From 711a7a2c2bb6ea7d77a9a4d62a144c6728e9f5e7 Mon Sep 17 00:00:00 2001 From: Gabriel Niebler Date: Fri, 3 Feb 2023 18:54:37 +0100 Subject: [PATCH] common: Chown mount even if already idmapped to account for remounts This is a logical consequence of introducing the chown check in _idmapped_mount, since now a read-only mount can be made idmapped successfully. But if the mount is then remounted rw the chown never happens, as _idmapped_mount sees that it's already idmapped and bows out early. This patch fixes that by simply moving the chown ahead of the idmapped check, so it will be performed in any case, even on already idmapped mounts. Signed-off-by: Gabriel Niebler Reviewed-by: Christian Brauner Signed-off-by: Zorro Lang --- common/rc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/rc b/common/rc index d65d52e6..16ef36af 100644 --- a/common/rc +++ b/common/rc @@ -408,10 +408,6 @@ _idmapped_mount() local tmp=`mktemp -d` local mount_rec=`findmnt -rncv -S $dev -o OPTIONS` - if [[ "$mount_rec" == *"idmapped"* ]]; then - return 0 - fi - # We create an idmapped mount where {g,u}id 0 writes to disk as # {g,u}id 10000000 and $(id -u fsgqa) + 10000000. We change ownership # of $mnt, provided it's not read-only, so {g,u} id 0 can actually @@ -419,6 +415,11 @@ _idmapped_mount() if [[ "$mount_rec" != *"ro,"* && "$mount_rec" != *",ro"* ]]; then chown 10000000:10000000 $mnt || return 1 fi + # But if the mount is already idmapped, then there's nothing more to do. + if [[ "$mount_rec" == *"idmapped"* ]]; then + return 0 + fi + $here/src/vfs/mount-idmapped \ --map-mount b:10000000:0:100000000000 \ $mnt $tmp -- 2.39.5