Skip to content

Commit 98db725

Browse files
author
Marc Zyngier
committed
KVM: arm64: Set the MTE tag bit before releasing the page
Setting a page flag without holding a reference to the page is living dangerously. In the tag-writing path, we drop the reference to the page by calling kvm_release_pfn_dirty(), and only then set the PG_mte_tagged bit. It would be safer to do it the other way round. Fixes: f0376ed ("KVM: arm64: Add ioctl to fetch/store tags in a guest") Cc: Catalin Marinas <catalin.marinas@arm.com> Reviewed-by: Steven Price <steven.price@arm.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/87k0mjidwb.wl-maz@kernel.org
1 parent 04c02c2 commit 98db725

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

arch/arm64/kvm/guest.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,14 @@ long kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm,
10531053
} else {
10541054
num_tags = mte_copy_tags_from_user(maddr, tags,
10551055
MTE_GRANULES_PER_PAGE);
1056+
1057+
/*
1058+
* Set the flag after checking the write
1059+
* completed fully
1060+
*/
1061+
if (num_tags == MTE_GRANULES_PER_PAGE)
1062+
set_bit(PG_mte_tagged, &page->flags);
1063+
10561064
kvm_release_pfn_dirty(pfn);
10571065
}
10581066

@@ -1061,10 +1069,6 @@ long kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm,
10611069
goto out;
10621070
}
10631071

1064-
/* Set the flag after checking the write completed fully */
1065-
if (write)
1066-
set_bit(PG_mte_tagged, &page->flags);
1067-
10681072
gfn++;
10691073
tags += num_tags;
10701074
length -= PAGE_SIZE;

0 commit comments

Comments
 (0)