aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/kvm
diff options
context:
space:
mode:
authorHeiko Carstens <heiko.carstens@de.ibm.com>2013-03-05 07:14:40 -0500
committerMarcelo Tosatti <mtosatti@redhat.com>2013-03-07 14:21:19 -0500
commit744b37fb5a63d45e92e590967bae82d8ac62e950 (patch)
treebbcc033484c4be327a3574965174f841621f2d63 /arch/s390/kvm
parent1a0d74e66405a795bb37a4a23ece50f8d8e5e81e (diff)
s390/kvm,gaccess: fix guest access return code handling
Guest access functions like copy_to/from_guest() call __guestaddr_to_user() which in turn call gmap_fault() in order to translate a guest address to a user space address. In error case __guest_addr_to_user() returns either -EFAULT or -ENOMEM. The copy_to/from_guest functions just pass these return values down to the callers. The -ENOMEM case however is problematic since there are several places which access guest memory like: rc = copy_to_guest(...); if (rc == -EFAULT) error_handling(); So in case of -ENOMEM the code assumes that the guest memory access succeeded even though it failed. This can cause guest data or state corruption. If __guestaddr_to_user() returns -ENOMEM the meaning is that a valid user space mapping exists, but there was not enough memory available when trying to build the guest mapping. In other words an out-of-memory situation occured. For normal user space accesses an out-of-memory situation causes the page fault handler to map -ENOMEM to -EFAULT (see fixup code in do_no_context()). We need to do exactly the same for the kvm gaccess functions. So __guestaddr_to_user() should just map all error codes to -EFAULT. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/s390/kvm')
-rw-r--r--arch/s390/kvm/gaccess.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/arch/s390/kvm/gaccess.h b/arch/s390/kvm/gaccess.h
index 4703f129e95e..84d01dd7a8e4 100644
--- a/arch/s390/kvm/gaccess.h
+++ b/arch/s390/kvm/gaccess.h
@@ -22,13 +22,16 @@ static inline void __user *__guestaddr_to_user(struct kvm_vcpu *vcpu,
22 unsigned long guestaddr) 22 unsigned long guestaddr)
23{ 23{
24 unsigned long prefix = vcpu->arch.sie_block->prefix; 24 unsigned long prefix = vcpu->arch.sie_block->prefix;
25 unsigned long uaddress;
25 26
26 if (guestaddr < 2 * PAGE_SIZE) 27 if (guestaddr < 2 * PAGE_SIZE)
27 guestaddr += prefix; 28 guestaddr += prefix;
28 else if ((guestaddr >= prefix) && (guestaddr < prefix + 2 * PAGE_SIZE)) 29 else if ((guestaddr >= prefix) && (guestaddr < prefix + 2 * PAGE_SIZE))
29 guestaddr -= prefix; 30 guestaddr -= prefix;
30 31 uaddress = gmap_fault(guestaddr, vcpu->arch.gmap);
31 return (void __user *) gmap_fault(guestaddr, vcpu->arch.gmap); 32 if (IS_ERR_VALUE(uaddress))
33 uaddress = -EFAULT;
34 return (void __user *)uaddress;
32} 35}
33 36
34static inline int get_guest_u64(struct kvm_vcpu *vcpu, unsigned long guestaddr, 37static inline int get_guest_u64(struct kvm_vcpu *vcpu, unsigned long guestaddr,