From 0020660cffaf029c13ba278a29ba4de15756087a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Wed, 11 Feb 2026 18:19:15 +0100 Subject: [PATCH] fix race between lock() and AssertLocked() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only write l.locked and l.lockType when counter == 0 to prevent race with unsynchronized reads in AssertLocked(). Fixes: https://github.com/containers/podman/issues/27924 Signed-off-by: Jan Rodák --- storage/pkg/lockfile/lockfile.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/storage/pkg/lockfile/lockfile.go b/storage/pkg/lockfile/lockfile.go index 3a8a4bc398..29b1c9a258 100644 --- a/storage/pkg/lockfile/lockfile.go +++ b/storage/pkg/lockfile/lockfile.go @@ -399,9 +399,9 @@ func (l *LockFile) lock(lType rawfilelock.LockType) { if err := rawfilelock.LockFile(l.fd, lType); err != nil { panic(err) } + l.lockType = lType + l.locked = true } - l.lockType = lType - l.locked = true l.counter++ } @@ -442,9 +442,10 @@ func (l *LockFile) tryLock(lType rawfilelock.LockType) error { rwMutexUnlocker() return err } + l.lockType = lType + l.locked = true + } - l.lockType = lType - l.locked = true l.counter++ return nil }