lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210512043107.30076-2-zhenzhong.duan@intel.com>
Date:   Wed, 12 May 2021 12:31:07 +0800
From:   Zhenzhong Duan <zhenzhong.duan@...el.com>
To:     linux-kernel@...r.kernel.org
Cc:     linux-kselftest@...r.kernel.org, kvm@...r.kernel.org,
        pbonzini@...hat.com, shuah@...nel.org,
        Zhenzhong Duan <zhenzhong.duan@...el.com>
Subject: [PATCH] selftests: kvm: Fix a potential elf loading issue

vm_vaddr_alloc() setup GVA to GPA mapping page by page, then GPA may not be
continuous if same memslot is used for data and page table allocation.

kvm_vm_elf_load() expects a continuous memory of GPA or else it need to
read file data page by page. Fix it by adding a check in vm_vaddr_alloc()
to ensure memory is allocated in a whole if same memslot is used for data
and page table.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@...el.com>
---
 tools/testing/selftests/kvm/lib/kvm_util.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 159f4d62241d..6118a2f8906e 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -1097,9 +1097,14 @@ vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
 			  uint32_t data_memslot, uint32_t pgd_memslot)
 {
 	uint64_t pages = (sz >> vm->page_shift) + ((sz % vm->page_size) != 0);
+	vm_paddr_t paddr_start = 0;
 
 	virt_pgd_alloc(vm, pgd_memslot);
 
+	if (data_memslot == pgd_memslot)
+		paddr_start = vm_phy_pages_alloc(vm, pages,
+				KVM_UTIL_MIN_PFN * vm->page_size, data_memslot);
+
 	/*
 	 * Find an unused range of virtual page addresses of at least
 	 * pages in length.
@@ -1111,8 +1116,12 @@ vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
 		pages--, vaddr += vm->page_size) {
 		vm_paddr_t paddr;
 
-		paddr = vm_phy_page_alloc(vm,
-				KVM_UTIL_MIN_PFN * vm->page_size, data_memslot);
+		if (paddr_start) {
+			paddr = paddr_start;
+			paddr_start += vm->page_size;
+		} else
+			paddr = vm_phy_page_alloc(vm,
+					KVM_UTIL_MIN_PFN * vm->page_size, data_memslot);
 
 		virt_pg_map(vm, vaddr, paddr, pgd_memslot);
 
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ