#987419 schroot: Incorrect mount/unmount binfmt handler sequence for start/stop schroot stages

Package:
schroot
Source:
schroot
Description:
Execute commands in a chroot environment
Submitter:
"Max A. Dednev"
Date:
2021-04-23 16:09:04 UTC
Severity:
important
#987419#5
Date:
2021-04-23 16:07:58 UTC
From:
To:
Dear Maintainer,

I'm using schroot for building packages with sbuild using qemu-arm-static
binfmt handler in chroot environment.

/etc/setup.d/15binfmt handler script incorrectly tries to perform bind mount
while schroot session is stopping. This leads to the mount error and terminates
schroot session end. So such sessions couldn't be ended. So, 15binfmt script
should take into account current $STAGE value to properly handle requested
operation. My modified script shows example of such handling process:

for emulator in $(update-binfmts --find "$shell"); do
    dst="${CHROOT_PATH}$emulator"
    if [ ! -e "$emulator" ]; then
        info "Missing emulator: $emulator; not enabling binfmt support"
    else
        if [ "$STAGE" == "setup-start" ] || \
           [ "$STAGE" == "setup-recover" ]; then
            [ -e "$dst" ] || { mkdir -p "$(dirname "$dst")"; touch "$dst"; }
            mount --bind "$emulator" "$dst"
            mount -o remount,ro,bind "$dst"
        elif [ "$STAGE" == "setup-stop"  ]; then
            umount "$dst"
        fi
    fi
done

It includes modifications, backported from schroot version 1.6.10-12, line:
...
[ -e "$dst" ] || { mkdir -p "$(dirname "$dst")"; touch "$dst"; }
...