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: <1198667160-22953-8-git-send-email-avi@qumranet.com>
Date:	Wed, 26 Dec 2007 13:05:12 +0200
From:	Avi Kivity <avi@...ranet.com>
To:	linux-kernel@...r.kernel.org, kvm-devel@...ts.sourceforge.net
Cc:	Izik Eidus <izike@...ranet.com>
Subject: [PATCH 07/55] KVM: Unmap kernel-allocated memory on slot destruction

From: Izik Eidus <izike@...ranet.com>

kvm_vm_ioctl_set_memory_region() is able to remove memory in addition to
adding it.  Therefore when using kernel swapping support for old userspaces,
we need to munmap the memory if the user request to remove it

Signed-off-by: Izik Eidus <izike@...ranet.com>
Signed-off-by: Avi Kivity <avi@...ranet.com>
---
 drivers/kvm/kvm.h      |    1 +
 drivers/kvm/kvm_main.c |   14 ++++++++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index f7181a4..12de42c 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -353,6 +353,7 @@ struct kvm_memory_slot {
 	unsigned long *rmap;
 	unsigned long *dirty_bitmap;
 	unsigned long userspace_addr;
+	int user_alloc;
 };
 
 struct kvm {
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 005f2d5..0e8f77d 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -713,6 +713,7 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
 
 		memset(new.rmap, 0, npages * sizeof(*new.rmap));
 
+		new.user_alloc = user_alloc;
 		if (user_alloc)
 			new.userspace_addr = mem->userspace_addr;
 		else {
@@ -727,6 +728,19 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
 			if (IS_ERR((void *)new.userspace_addr))
 				goto out_unlock;
 		}
+	} else {
+		if (!old.user_alloc && old.rmap) {
+			int ret;
+
+			down_write(&current->mm->mmap_sem);
+			ret = do_munmap(current->mm, old.userspace_addr,
+					old.npages * PAGE_SIZE);
+			up_write(&current->mm->mmap_sem);
+			if (ret < 0)
+				printk(KERN_WARNING
+				       "kvm_vm_ioctl_set_memory_region: "
+				       "failed to munmap memory\n");
+		}
 	}
 
 	/* Allocate page dirty bitmap if needed */
-- 
1.5.3.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ