summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fsimpl
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2021-01-29 12:16:55 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-29 12:18:42 -0800
commit0fa534f1164f2bf6cf50a37d4dce584b6fc8ec07 (patch)
treede6f046c67076a88448faa221bf4e3aad2308ae5 /pkg/sentry/fsimpl
parent25284ae3c9b5f8d96686ba5b18b53819a961d34d (diff)
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
Diffstat (limited to 'pkg/sentry/fsimpl')
-rw-r--r--pkg/sentry/fsimpl/gofer/special_file.go9
1 files changed, 7 insertions, 2 deletions
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 {