From e3624fc7bb69ec6473576235d7176536a4c7a3d3 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/storage/pkg/lockfile/lockfile.go b/storage/pkg/lockfile/lockfile.go index 3a8a4bc398..a083ed3275 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,9 @@ 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 }