Skip to contentSkip to conversation

KVM: x86: Use ERR_PTR_USR() to return -EFAULT as a __user pointer

PATCH Applied Sean Christopherson 2 participants 2 messages Feb 2, 2022 – Feb 4, 2022

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 KVM: x86: Use ERR_PTR_USR() to return -EFAULT as a __user pointer

Use ERR_PTR_USR() when returning -EFAULT from kvm_get_attr_addr(), sparse complains about implicitly casting the kernel pointer from ERR_PTR() into a __user pointer.

Quoted 1 line
Quoted 1 line

arch/x86/kvm/x86.c:4342:31: sparse: sparse: incorrect type in return expression

(different address spaces) @@ expected void [noderef] __user * @@ got void * @@
arch/x86/kvm/x86.c:4342:31: sparse: expected void [noderef] __user *
arch/x86/kvm/x86.c:4342:31: sparse: got void *

Quoted 1 line
Quoted 1 line

arch/x86/kvm/x86.c:4342:31: sparse: sparse: incorrect type in return expression

(different address spaces) @@ expected void [noderef] __user * @@ got void * @@
arch/x86/kvm/x86.c:4342:31: sparse: expected void [noderef] __user *
arch/x86/kvm/x86.c:4342:31: sparse: got void *

No functional change intended.

Fixes 56f289a8d23a ("KVM: x86: Add a helper to retrieve userspace address from kvm_device_attr")
---
 arch/x86/kvm/x86.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kvm/x86.c +3 -3
index fec3dd4f0718..b533aab98172 100644
@@ -90,6 +90,8 @@
 u64 __read_mostly kvm_mce_cap_supported = MCG_CTL_P | MCG_SER_P;
 EXPORT_SYMBOL_GPL(kvm_mce_cap_supported);
 
+#define  ERR_PTR_USR(e)  ((void __user *)ERR_PTR(e))
+
 #define emul_to_vcpu(ctxt) \
 	((struct kvm_vcpu *)(ctxt)->vcpu)
 
@@ -4340,7 +4342,7 @@ static inline void __user *kvm_get_attr_addr(struct kvm_device_attr *attr)
 	void __user *uaddr = (void __user*)(unsigned long)attr->addr;
 
 	if ((u64)(unsigned long)uaddr != attr->addr)
-		return ERR_PTR(-EFAULT);
+		return ERR_PTR_USR(-EFAULT);
 	return uaddr;
 }
 
@@ -11684,8 +11686,6 @@ void kvm_arch_sync_events(struct kvm *kvm)
 	kvm_free_pit(kvm);
 }
 
-#define  ERR_PTR_USR(e)  ((void __user *)ERR_PTR(e))
-
 /**
  * __x86_set_memory_region: Setup KVM internal memory slot
  *

base-commit: b2d2af7e5df37ee3a9ba6b405bdbb7691a5c2dfc

Signature · 1 line
2.35.0.rc2.247.g8bbb082509-goog
maintainer Applied
#1 lore raw
Quoted 54 lines · Sean Christopherson

Use ERR_PTR_USR() when returning -EFAULT from kvm_get_attr_addr(), sparse complains about implicitly casting the kernel pointer from ERR_PTR() into a __user pointer.

Quoted 1 line
Quoted 1 line

arch/x86/kvm/x86.c:4342:31: sparse: sparse: incorrect type in return expression

    (different address spaces) @@     expected void [noderef] __user * @@     got void * @@
    arch/x86/kvm/x86.c:4342:31: sparse:     expected void [noderef] __user *
    arch/x86/kvm/x86.c:4342:31: sparse:     got void *
Quoted 1 line
Quoted 1 line

arch/x86/kvm/x86.c:4342:31: sparse: sparse: incorrect type in return expression

    (different address spaces) @@     expected void [noderef] __user * @@     got void * @@
    arch/x86/kvm/x86.c:4342:31: sparse:     expected void [noderef] __user *
    arch/x86/kvm/x86.c:4342:31: sparse:     got void *

No functional change intended.

Fixes 56f289a8d23a ("KVM: x86: Add a helper to retrieve userspace address from kvm_device_attr")
---
  arch/x86/kvm/x86.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kvm/x86.c +3 -3
index fec3dd4f0718..b533aab98172 100644
@@ -90,6 +90,8 @@
  u64 __read_mostly kvm_mce_cap_supported = MCG_CTL_P | MCG_SER_P;
  EXPORT_SYMBOL_GPL(kvm_mce_cap_supported);
 
+#define  ERR_PTR_USR(e)  ((void __user *)ERR_PTR(e))
+
  #define emul_to_vcpu(ctxt) \
  	((struct kvm_vcpu *)(ctxt)->vcpu)
 
@@ -4340,7 +4342,7 @@ static inline void __user *kvm_get_attr_addr(struct kvm_device_attr *attr)
  	void __user *uaddr = (void __user*)(unsigned long)attr->addr;
 
  	if ((u64)(unsigned long)uaddr != attr->addr)
-		return ERR_PTR(-EFAULT);
+		return ERR_PTR_USR(-EFAULT);
  	return uaddr;
  }
 
@@ -11684,8 +11686,6 @@ void kvm_arch_sync_events(struct kvm *kvm)
  	kvm_free_pit(kvm);
  }
 
-#define  ERR_PTR_USR(e)  ((void __user *)ERR_PTR(e))
-
  /**
   * __x86_set_memory_region: Setup KVM internal memory slot
   *
Quoted 1 line

base-commit: b2d2af7e5df37ee3a9ba6b405bdbb7691a5c2dfc

Queued, thanks.

Paolo