* Re: [PATCH v1] KVM: arm64: Fix benign bug with incorrect use of VA_BITS.
@ 2022-12-05 13:49 ` Marc Zyngier
0 siblings, 0 replies; 12+ messages in thread
From: Marc Zyngier @ 2022-12-05 13:49 UTC (permalink / raw)
To: Ryan Roberts
Cc: James Morse, Alexandru Elisei, Suzuki K Poulose, Oliver Upton,
Catalin Marinas, Will Deacon, linux-arm-kernel, kvmarm, kvmarm
Hi Ryan,
Thanks for that.
On Mon, 05 Dec 2022 11:40:31 +0000,
Ryan Roberts <ryan.roberts@arm.com> wrote:
>
> 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.
It isn't supposed to "fake" anything. It simply provides the
information that the walker needs to correctly parse the page tables.
>
> 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.
>
> Fixes: 6011cf68c885 ("KVM: arm64: Walk userspace page tables to compute
> the THP mapping size")
nit: this should appear on a single line, without a line-break in the
middle [1]...
>
... 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.
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
> arch/arm64/kvm/mmu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 4efb983cff43..1ef0704420d9 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -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
>
>
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.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst#n139
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v1] KVM: arm64: Fix benign bug with incorrect use of VA_BITS.
@ 2022-12-05 13:49 ` Marc Zyngier
0 siblings, 0 replies; 12+ messages in thread
From: Marc Zyngier @ 2022-12-05 13:49 UTC (permalink / raw)
To: Ryan Roberts
Cc: James Morse, Alexandru Elisei, Suzuki K Poulose, Oliver Upton,
Catalin Marinas, Will Deacon, linux-arm-kernel, kvmarm, kvmarm
Hi Ryan,
Thanks for that.
On Mon, 05 Dec 2022 11:40:31 +0000,
Ryan Roberts <ryan.roberts@arm.com> wrote:
>
> 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.
It isn't supposed to "fake" anything. It simply provides the
information that the walker needs to correctly parse the page tables.
>
> 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.
>
> Fixes: 6011cf68c885 ("KVM: arm64: Walk userspace page tables to compute
> the THP mapping size")
nit: this should appear on a single line, without a line-break in the
middle [1]...
>
... 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.
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
> arch/arm64/kvm/mmu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 4efb983cff43..1ef0704420d9 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -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
>
>
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.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst#n139
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v1] KVM: arm64: Fix benign bug with incorrect use of VA_BITS.
@ 2022-12-05 14:06 ` Ryan Roberts
0 siblings, 0 replies; 12+ messages in thread
From: Ryan Roberts @ 2022-12-05 14:06 UTC (permalink / raw)
To: Marc Zyngier
Cc: Will Deacon, Catalin Marinas, kvmarm, kvmarm, linux-arm-kernel
On 05/12/2022 13:49, Marc Zyngier wrote:
> Hi Ryan,
>
> Thanks for that.
>
> On Mon, 05 Dec 2022 11:40:31 +0000,
> Ryan Roberts <ryan.roberts@arm.com> wrote:
>>
>> 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.
>
> 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.
>
>>
>> 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.
>>
>> Fixes: 6011cf68c885 ("KVM: arm64: Walk userspace page tables to compute
>> the THP mapping size")
>
> nit: this should appear on a single line, without a line-break in the
> middle [1]...>
>>
>
> ... 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.
>
> And while I'm on the "trivial remarks" train, drop the full stop at
> the end of the subject line.
Yep, will do.
>
>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
>> ---
>> arch/arm64/kvm/mmu.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
>> index 4efb983cff43..1ef0704420d9 100644
>> --- a/arch/arm64/kvm/mmu.c
>> +++ b/arch/arm64/kvm/mmu.c
>> @@ -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
>>
>>
>
> 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.
Sounds like you are happy to tend to the nits and don't need me to repost?
>
> Thanks,
>
> M.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst#n139
>
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v1] KVM: arm64: Fix benign bug with incorrect use of VA_BITS.
@ 2022-12-05 14:06 ` Ryan Roberts
0 siblings, 0 replies; 12+ messages in thread
From: Ryan Roberts @ 2022-12-05 14:06 UTC (permalink / raw)
To: Marc Zyngier
Cc: James Morse, Alexandru Elisei, Suzuki K Poulose, Oliver Upton,
Catalin Marinas, Will Deacon, linux-arm-kernel, kvmarm, kvmarm
On 05/12/2022 13:49, Marc Zyngier wrote:
> Hi Ryan,
>
> Thanks for that.
>
> On Mon, 05 Dec 2022 11:40:31 +0000,
> Ryan Roberts <ryan.roberts@arm.com> wrote:
>>
>> 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.
>
> 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.
>
>>
>> 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.
>>
>> Fixes: 6011cf68c885 ("KVM: arm64: Walk userspace page tables to compute
>> the THP mapping size")
>
> nit: this should appear on a single line, without a line-break in the
> middle [1]...>
>>
>
> ... 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.
>
> And while I'm on the "trivial remarks" train, drop the full stop at
> the end of the subject line.
Yep, will do.
>
>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
>> ---
>> arch/arm64/kvm/mmu.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
>> index 4efb983cff43..1ef0704420d9 100644
>> --- a/arch/arm64/kvm/mmu.c
>> +++ b/arch/arm64/kvm/mmu.c
>> @@ -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
>>
>>
>
> 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.
Sounds like you are happy to tend to the nits and don't need me to repost?
>
> Thanks,
>
> M.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst#n139
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v1] KVM: arm64: Fix benign bug with incorrect use of VA_BITS.
@ 2022-12-05 14:06 ` Ryan Roberts
0 siblings, 0 replies; 12+ messages in thread
From: Ryan Roberts @ 2022-12-05 14:06 UTC (permalink / raw)
To: Marc Zyngier
Cc: James Morse, Alexandru Elisei, Suzuki K Poulose, Oliver Upton,
Catalin Marinas, Will Deacon, linux-arm-kernel, kvmarm, kvmarm
On 05/12/2022 13:49, Marc Zyngier wrote:
> Hi Ryan,
>
> Thanks for that.
>
> On Mon, 05 Dec 2022 11:40:31 +0000,
> Ryan Roberts <ryan.roberts@arm.com> wrote:
>>
>> 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.
>
> 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.
>
>>
>> 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.
>>
>> Fixes: 6011cf68c885 ("KVM: arm64: Walk userspace page tables to compute
>> the THP mapping size")
>
> nit: this should appear on a single line, without a line-break in the
> middle [1]...>
>>
>
> ... 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.
>
> And while I'm on the "trivial remarks" train, drop the full stop at
> the end of the subject line.
Yep, will do.
>
>> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
>> ---
>> arch/arm64/kvm/mmu.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
>> index 4efb983cff43..1ef0704420d9 100644
>> --- a/arch/arm64/kvm/mmu.c
>> +++ b/arch/arm64/kvm/mmu.c
>> @@ -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
>>
>>
>
> 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.
Sounds like you are happy to tend to the nits and don't need me to repost?
>
> Thanks,
>
> M.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst#n139
>
^ permalink raw reply [flat|nested] 12+ messages in thread