mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-22 10:31:08 +00:00
KVM: arm64: Prevent unconditional donation of unmapped regions from the host
Since host stage-2 mappings are created lazily, we cannot rely solely on
the pte in order to recover the target physical address when checking a
host-initiated memory transition as this permits donation of unmapped
regions corresponding to MMIO or "no-map" memory.
Instead of inspecting the pte, move the addr_is_allowed_memory() check
into the host callback function where it is passed the physical address
directly from the walker.
Cc: Quentin Perret <qperret@google.com>
Fixes: e82edcc75c
("KVM: arm64: Implement do_share() helper for sharing memory")
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230518095844.1178-1-will@kernel.org
This commit is contained in:
parent
6254873226
commit
09cce60bdd
1 changed files with 7 additions and 7 deletions
|
@ -575,7 +575,7 @@ struct pkvm_mem_donation {
|
||||||
|
|
||||||
struct check_walk_data {
|
struct check_walk_data {
|
||||||
enum pkvm_page_state desired;
|
enum pkvm_page_state desired;
|
||||||
enum pkvm_page_state (*get_page_state)(kvm_pte_t pte);
|
enum pkvm_page_state (*get_page_state)(kvm_pte_t pte, u64 addr);
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __check_page_state_visitor(const struct kvm_pgtable_visit_ctx *ctx,
|
static int __check_page_state_visitor(const struct kvm_pgtable_visit_ctx *ctx,
|
||||||
|
@ -583,10 +583,7 @@ static int __check_page_state_visitor(const struct kvm_pgtable_visit_ctx *ctx,
|
||||||
{
|
{
|
||||||
struct check_walk_data *d = ctx->arg;
|
struct check_walk_data *d = ctx->arg;
|
||||||
|
|
||||||
if (kvm_pte_valid(ctx->old) && !addr_is_allowed_memory(kvm_pte_to_phys(ctx->old)))
|
return d->get_page_state(ctx->old, ctx->addr) == d->desired ? 0 : -EPERM;
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
return d->get_page_state(ctx->old) == d->desired ? 0 : -EPERM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_page_state_range(struct kvm_pgtable *pgt, u64 addr, u64 size,
|
static int check_page_state_range(struct kvm_pgtable *pgt, u64 addr, u64 size,
|
||||||
|
@ -601,8 +598,11 @@ static int check_page_state_range(struct kvm_pgtable *pgt, u64 addr, u64 size,
|
||||||
return kvm_pgtable_walk(pgt, addr, size, &walker);
|
return kvm_pgtable_walk(pgt, addr, size, &walker);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum pkvm_page_state host_get_page_state(kvm_pte_t pte)
|
static enum pkvm_page_state host_get_page_state(kvm_pte_t pte, u64 addr)
|
||||||
{
|
{
|
||||||
|
if (!addr_is_allowed_memory(addr))
|
||||||
|
return PKVM_NOPAGE;
|
||||||
|
|
||||||
if (!kvm_pte_valid(pte) && pte)
|
if (!kvm_pte_valid(pte) && pte)
|
||||||
return PKVM_NOPAGE;
|
return PKVM_NOPAGE;
|
||||||
|
|
||||||
|
@ -709,7 +709,7 @@ static int host_complete_donation(u64 addr, const struct pkvm_mem_transition *tx
|
||||||
return host_stage2_set_owner_locked(addr, size, host_id);
|
return host_stage2_set_owner_locked(addr, size, host_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum pkvm_page_state hyp_get_page_state(kvm_pte_t pte)
|
static enum pkvm_page_state hyp_get_page_state(kvm_pte_t pte, u64 addr)
|
||||||
{
|
{
|
||||||
if (!kvm_pte_valid(pte))
|
if (!kvm_pte_valid(pte))
|
||||||
return PKVM_NOPAGE;
|
return PKVM_NOPAGE;
|
||||||
|
|
Loading…
Reference in a new issue