From 95f3bdf66b098c39c09ca52d2cd542117e8b3e2c Mon Sep 17 00:00:00 2001 From: Ryan Lee Date: Tue, 3 Dec 2024 13:04:16 -0800 Subject: [PATCH] Fix race condition in loop device setup in mount regression test Calling losetup -f first and passing its result to create the loop device creates a race condition in which the loop device might be claimed first in between the two losetup calls. Instead, create the device atomically and then obtain the loop device /dev/ handle afterwards. Signed-off-by: Ryan Lee --- tests/regression/apparmor/mount.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/regression/apparmor/mount.sh b/tests/regression/apparmor/mount.sh index fd87898b0..de9d78c13 100755 --- a/tests/regression/apparmor/mount.sh +++ b/tests/regression/apparmor/mount.sh @@ -77,8 +77,8 @@ if [ ! -b /dev/loop0 ] ; then fi # find the next free loop device and mount it -loop_device=$(losetup -f) || fatalerror 'Unable to find a free loop device' -/sbin/losetup "$loop_device" ${mount_file} > /dev/null 2> /dev/null +/sbin/losetup -f ${mount_file} || fatalerror 'Unable to set up a loop device' +loop_device="$(/sbin/losetup -n -O NAME -l -j ${mount_file})" options=( # default and non-default options