KVM: arm64: Fix benign bug with incorrect use of VA_BITS.
PATCH 1/1 KVM: arm64: Fix benign bug with incorrect use of VA_BITS.
get_user_mapping_size() uses kvm's pgtable library to walk a user space page table created by the kernel, and in doing so, fakes up the metadata that the library needs, including ia_bits, which defines the size of the input address.
For the case where the kernel is compiled for 52 VA bits but runs on HW that does not support LVA, it will fall back to 48 VA bits at runtime. Therefore we must use vabits_actual rather than VA_BITS to get the true address size.
This is benign in the current code base because the pgtable library only uses it for error checking.
the THP mapping size")
--- arch/arm64/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/mmu.c +1 -1
@@ -641,7 +641,7 @@ static int get_user_mapping_size(struct kvm *kvm, u64 addr) {struct kvm_pgtable pgt = { .pgd = (kvm_pte_t *)kvm->mm->pgd, - .ia_bits =VA_BITS , + .ia_bits = vabits_actual, .start_level = (KVM_PGTABLE_MAX_LEVELS -CONFIG_PGTABLE_LEVELS ), .mm_ops = &kvm_user_mm_ops,
--
2.25.1
Marc Zyngier
maintainerHi Ryan,
Thanks for that.
Quoted 5 lines · Ryan Roberts
get_user_mapping_size()uses kvm's pgtable library to walk a user space page table created by the kernel, and in doing so, fakes up the metadata that the library needs, includingia_bits, which defines the size of the input address.
It isn't supposed to "fake" anything. It simply provides the information that the walker needs to correctly parse the page tables.
Quoted 11 lines
For the case where the kernel is compiled for 52 VA bits but runs on HW that does not support LVA, it will fall back to 48 VA bits at runtime. Therefore we must use
vabits_actualrather thanVA_BITSto get the true address size.This is benign in the current code base because the pgtable library only uses it for error checking.
Fixes 6011cf68c885 ("KVM: arm64: Walk userspace page tables to computethe THP mapping size")
nit: this should appear on a single line, without a line-break in the middle [1]...
Quoted 1 line
... without a blank line between Fixes: and the rest of the tags.
And while I'm on the "trivial remarks" train, drop the full stop at the end of the subject line.
Quoted 19 lines
Signed-off-by Ryan Roberts <[email protected]>--- arch/arm64/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/mmu.c +1
-2@@ -641,7 +641,7 @@ static int get_user_mapping_size(struct kvm *kvm, u64 addr) {struct kvm_pgtable pgt = { .pgd = (kvm_pte_t *)kvm->mm->pgd, - .ia_bits = VA_BITS, + .ia_bits = vabits_actual, .start_level = (KVM_PGTABLE_MAX_LEVELS -CONFIG_PGTABLE_LEVELS ), .mm_ops = &kvm_user_mm_ops, --
Quoted 3 lines
2.25.1
Other than the above nits, this is well spotted. I need to regenerate the kvmarm/next branch after the sysreg attack from James, so I'll try and fold that in.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 7 lines · Marc Zyngier
Hi Ryan,
Thanks for that.
Quoted 1 line · Ryan Roberts
Quoted 7 lines
Quoted 4 lines
get_user_mapping_size()uses kvm's pgtable library to walk a user space page table created by the kernel, and in doing so, fakes up the metadata that the library needs, includingia_bits, which defines the size of the input address.It isn't supposed to "fake" anything. It simply provides the information that the walker needs to correctly parse the page tables.
Apologies - poor choice of words.
Quoted 10 lines
Quoted 10 lines
For the case where the kernel is compiled for 52 VA bits but runs on HW that does not support LVA, it will fall back to 48 VA bits at runtime. Therefore we must use
vabits_actualrather thanVA_BITSto get the true address size.This is benign in the current code base because the pgtable library only uses it for error checking.
Quoted 8 lines
Quoted 2 lines
Fixes 6011cf68c885 ("KVM: arm64: Walk userspace page tables to computethe THP mapping size")
nit: this should appear on a single line, without a line-break in the middle [1]...>
Quoted 1 line
... without a blank line between Fixes: and the rest of the tags.
Ahh, thanks for the pointer. I'll admit that checkpatch did raise this but I assumed it was a false positive, because assumed the 75 chars per line rule would override.
Quoted 3 lines
And while I'm on the "trivial remarks" train, drop the full stop at the end of the subject line.
Yep, will do.
Quoted 19 lines
Quoted 19 lines
Signed-off-by Ryan Roberts <[email protected]>--- arch/arm64/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm64/kvm/mmu.c +1
-1@@ -641,7 +641,7 @@ static int get_user_mapping_size(struct kvm *kvm, u64 addr) {struct kvm_pgtable pgt = { .pgd = (kvm_pte_t *)kvm->mm->pgd, - .ia_bits =VA_BITS , + .ia_bits = vabits_actual, .start_level = (KVM_PGTABLE_MAX_LEVELS -CONFIG_PGTABLE_LEVELS ), .mm_ops = &kvm_user_mm_ops,
Quoted 8 lines
Quoted 4 lines
--
2.25.1Other than the above nits, this is well spotted. I need to regenerate the kvmarm/next branch after the sysreg attack from James, so I'll try and fold that in.
Sounds like you are happy to tend to the nits and don't need me to repost?
Quoted 11 lines · Ryan Roberts
get_user_mapping_size()uses kvm's pgtable library to walk a user space page table created by the kernel, and in doing so, fakes up the metadata that the library needs, includingia_bits, which defines the size of the input address.For the case where the kernel is compiled for 52 VA bits but runs on HW that does not support LVA, it will fall back to 48 VA bits at runtime. Therefore we must use
vabits_actualrather thanVA_BITSto get the true address size.[...]
Applied to next, thanks!
[1/1] KVM: arm64: Fix benign bug with incorrect use of VA_BITS.
commit: 219072c09abde0f1d0a6ce091be375e8eb7d08f0
Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.