Re: [PATCH 26/27] Enable 32bit dirty log pointers on 64bit host

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09/29/2009 06:29 PM, Alexander Graf wrote:

How about this one? (broken whitespace!)

From c3864a2c5e1fccff7839e47f12c09d9739ca441e Mon Sep 17 00:00:00 2001
From: Alexander Graf <agraf@xxxxxxx>
Date: Thu, 23 Jul 2009 21:05:57 +0200
Subject: [PATCH] Enable 32bit dirty log pointers on 64bit host

With big endian userspace, passing a pointer from 32-bit userspace to
64-bit kernel space breaks.

This is what happens with dirty logging. To get the pointer interpreted
correctly, we can just check the guest's 32bit flag and treat the pointer
as 32 bits then.

Signed-off-by: Alexander Graf <agraf@xxxxxxx>

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e27b7a9..00f2c59 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -703,6 +703,7 @@ int kvm_get_dirty_log(struct kvm *kvm,
        int r, i;
        int n;
        unsigned long any = 0;
+       void *target_bm;

void __user *target_bm;


        r = -EINVAL;
        if (log->slot >= KVM_MEMORY_SLOTS)
@@ -718,8 +719,15 @@ int kvm_get_dirty_log(struct kvm *kvm,
        for (i = 0; !any && i < n/sizeof(long); ++i)
                any = memslot->dirty_bitmap[i];

+#if defined(__BIG_ENDIAN) && defined(CONFIG_64BIT)
+       /* Need to convert user pointers */
+       if (test_thread_flag(TIF_32BIT))
+               target_bm = (void*)((u64)log->dirty_bitmap >> 32);
+       else
+#endif
+       target_bm = log->dirty_bitmap;
        r = -EFAULT;
-       if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
+       if (copy_to_user(target_bm, memslot->dirty_bitmap, n))
                goto out;

        if (any)

Ah, that's much better. Plus a mental note not to put pointers in user-visible structures in the future. This can serve as a reminder :)

--
error compiling committee.c: too many arguments to function

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM Development]     [KVM ARM]     [KVM ia64]     [Linux Virtualization]     [Linux USB Devel]     [Linux Video]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux