mirror of
https://github.com/hardkernel/linux.git
synced 2026-03-25 12:00:22 +09:00
ANDROID: KVM: arm64: Fix size calculation of FFA memory range
Ensure that the FFA memory range to be checked and annotated in the host stage-2 page-table is page-aligned and that its size is calculated using 64-bit arithmetic to avoid the host triggering overflow and subsequent truncation. Bug: 228889679 Reported-by: Gulshan Singh <gsgx@google.com> Signed-off-by: Will Deacon <willdeacon@google.com> Change-Id: Ifc51ee9598905cf2926d19c53159804f89d74040
This commit is contained in:
@@ -284,10 +284,13 @@ static u32 __ffa_host_share_ranges(struct ffa_mem_region_addr_range *ranges,
|
||||
|
||||
for (i = 0; i < nranges; ++i) {
|
||||
struct ffa_mem_region_addr_range *range = &ranges[i];
|
||||
u64 npages = (range->pg_cnt * FFA_PAGE_SIZE) / PAGE_SIZE;
|
||||
u64 sz = (u64)range->pg_cnt * FFA_PAGE_SIZE;
|
||||
u64 pfn = hyp_phys_to_pfn(range->address);
|
||||
|
||||
if (__pkvm_host_share_ffa(pfn, npages))
|
||||
if (!PAGE_ALIGNED(sz))
|
||||
break;
|
||||
|
||||
if (__pkvm_host_share_ffa(pfn, sz / PAGE_SIZE))
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -301,10 +304,13 @@ static u32 __ffa_host_unshare_ranges(struct ffa_mem_region_addr_range *ranges,
|
||||
|
||||
for (i = 0; i < nranges; ++i) {
|
||||
struct ffa_mem_region_addr_range *range = &ranges[i];
|
||||
u64 npages = (range->pg_cnt * FFA_PAGE_SIZE) / PAGE_SIZE;
|
||||
u64 sz = (u64)range->pg_cnt * FFA_PAGE_SIZE;
|
||||
u64 pfn = hyp_phys_to_pfn(range->address);
|
||||
|
||||
if (__pkvm_host_unshare_ffa(pfn, npages))
|
||||
if (!PAGE_ALIGNED(sz))
|
||||
break;
|
||||
|
||||
if (__pkvm_host_unshare_ffa(pfn, sz / PAGE_SIZE))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user