From 0fa534f1164f2bf6cf50a37d4dce584b6fc8ec07 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Fri, 29 Jan 2021 12:16:55 -0800 Subject: Fix deadlock in specialFileFD.pwrite When file is regular and metadata cache is authoritative, metadata lock is taken. The code deadlocks trying to acquire the metadata lock again to update time stampts. PiperOrigin-RevId: 354584594 --- pkg/sentry/fsimpl/gofer/special_file.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pkg/sentry/fsimpl') diff --git a/pkg/sentry/fsimpl/gofer/special_file.go b/pkg/sentry/fsimpl/gofer/special_file.go index 089955a96..ae972fcb5 100644 --- a/pkg/sentry/fsimpl/gofer/special_file.go +++ b/pkg/sentry/fsimpl/gofer/special_file.go @@ -299,10 +299,15 @@ func (fd *specialFileFD) pwrite(ctx context.Context, src usermem.IOSequence, off src = src.TakeFirst64(limit) } - // Do a buffered write. See rationale in PRead. if d.cachedMetadataAuthoritative() { - d.touchCMtime() + if fd.isRegularFile { + d.touchCMtimeLocked() + } else { + d.touchCMtime() + } } + + // Do a buffered write. See rationale in PRead. buf := make([]byte, src.NumBytes()) copied, copyErr := src.CopyIn(ctx, buf) if copied == 0 && copyErr != nil { -- cgit v1.2.3