Commit 1a33a37a authored by Michael Shigorin's avatar Michael Shigorin Committed by Anton Midyukov

tar2fs: avoid losetup race

There's a race condition (TOCTOU) between losetup --find and applying the obtained path after additional dd in between; twice awful as *at least* running both losetups closely would reduce the window significantly, and reading the manpage properly back then would eliminate this. Reported-by: 's avatarAnton Midyukov <antohami@altlinux.org> Suggested-by: 's avatarGleb F-Malinovskiy <glebfm@altlinux.org>
parent e245447c
......@@ -165,7 +165,6 @@ for i in losetup sfdisk parted kpartx $MKFS; do
fi
done
LOOPDEV="$(losetup --find)" # would be sad about non-binary megabytes too
ROOTFS="$WORKDIR/chroot"
BOOTFS=
......@@ -204,7 +203,8 @@ trap exit_handler EXIT ERR
rm -f -- "$IMG"
OFFSET="$(($CUR_BOUNDARY + $EFIPARTSIZEM + $BOOTLOADERPARTSIZEM + $BOOTSIZEM + $ROOTSIZEM - 1))"
dd if=/dev/zero of="$IMG" conv=notrunc bs=$MB count=1 seek="$OFFSET"
losetup "$LOOPDEV" "$IMG"
losetup -f "$IMG"
LOOPDEV=$(losetup -j "$IMG" | cut -f 1 -d ':')
parting mklabel "$PARTTABLE"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment