From 3f2042e33acb6db91594e12ebd63b9abd9e753cc Mon Sep 17 00:00:00 2001 From: Jon Maloy Date: Wed, 7 Jun 2023 11:45:09 -0400 Subject: [PATCH 15/21] memory: stricter checks prior to unsetting engaged_in_io RH-Author: Jon Maloy RH-MergeRequest: 165: memory: prevent dma-reentracy issues RH-Jira: RHEL-516 RH-Acked-by: Miroslav Rezanina RH-Commit: [11/13] b8e1a4b49dd7fa3b7948d32f46dfe1d7f7a4c1cf (jmaloy/jmaloy-qemu-kvm-2) Jira: https://issues.redhat.com/browse/RHEL-516 Upstream: Merged CVE: CVE-2023-2680 commit 3884bf6468ac6bbb58c2b3feaa74e87f821b52f3 Author: Alexander Bulekov Date: Tue May 16 04:40:02 2023 -0400 memory: stricter checks prior to unsetting engaged_in_io engaged_in_io could be unset by an MR with re-entrancy checks disabled. Ensure that only MRs that can set the engaged_in_io flag can unset it. Signed-off-by: Alexander Bulekov Message-Id: <20230516084002.3813836-1-alxndr@bu.edu> Reviewed-by: Darren Kenny Signed-off-by: Thomas Huth Signed-off-by: Jon Maloy --- softmmu/memory.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index b7b3386e9d..26424f1d78 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -534,6 +534,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr, unsigned access_size; unsigned i; MemTxResult r = MEMTX_OK; + bool reentrancy_guard_applied = false; if (!access_size_min) { access_size_min = 1; @@ -552,6 +553,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr, return MEMTX_ACCESS_ERROR; } mr->dev->mem_reentrancy_guard.engaged_in_io = true; + reentrancy_guard_applied = true; } /* FIXME: support unaligned access? */ @@ -568,7 +570,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr, access_mask, attrs); } } - if (mr->dev) { + if (mr->dev && reentrancy_guard_applied) { mr->dev->mem_reentrancy_guard.engaged_in_io = false; } return r; -- 2.39.3