ARM: KVM: prevent NULL pointer dereference with KVM ioctl
PATCH 1/1 ARM: KVM: prevent NULL pointer dereference with KVM ioctl
Some ARM KVM VCPU ioctls require the vCPU to be properly initialized with the KVM_ARM_VCPU_INIT ioctl before being used with further requests. KVM_RUN checks whether this initialization has been done, but other ioctls do not.
Namely KVM_GET_REG_LIST will dereference an array with index -1 without initialization and thus leads to a kernel oops. Fix this by adding checks before executing the ioctl handlers.
--- arch/arm/kvm/arm.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/kvm/arm.c +9 -0
@@ -893,6 +893,11 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_SET_ONE_REG :case KVM_GET_ONE_REG : {struct kvm_one_reg reg; + +/* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */ +if (unlikely (vcpu->arch.target <0 )) +return -ENOEXEC ; +if (copy_from_user (®, argp,sizeof (reg)))return -EFAULT ;if (ioctl ==KVM_SET_ONE_REG )
@@ -905,6 +910,10 @@ long kvm_arch_vcpu_ioctl(struct file *filp,struct kvm_reg_list reg_list;unsigned n; +/* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */ +if (unlikely (vcpu->arch.target <0 )) +return -ENOEXEC ; +if (copy_from_user (®_list, user_list,sizeof (reg_list)))return -EFAULT ; n = reg_list.n;
Signature · 1 line
1.7.12.1
PATCH 1/1 ARM: KVM: prevent NULL pointer dereference with KVM ioctl
Quoted 31 lines · Andre Przywara
Some ARM KVM VCPU ioctls require the vCPU to be properly initialized with the
KVM_ARM_VCPU_INITioctl before being used with further requests.KVM_RUNchecks whether this initialization has been done, but other ioctls do not.
NamelyKVM_GET_REG_LISTwill dereference an array with index -1 without initialization and thus leads to a kernel oops. Fix this by adding checks before executing the ioctl handlers.Signed-off-by Andre Przywara <[email protected]>--- arch/arm/kvm/arm.c | 9 +++++++++ 1 file changed, 9 insertions(+)arch/arm/kvm/arm.c +5
-0@@ -893,6 +893,11 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_SET_ONE_REG :case KVM_GET_ONE_REG : {struct kvm_one_reg reg; + +/* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */ +if (unlikely (vcpu->arch.target <0 )) +return -ENOEXEC ; +if (copy_from_user (®, argp,sizeof (reg)))return -EFAULT ;if (ioctl ==KVM_SET_ONE_REG )
arch/arm/kvm/arm.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 919
Quoted 10 lines
arch/arm/kvm/arm.c +4
-0@@ -905,6 +910,10 @@ long kvm_arch_vcpu_ioctl(struct file *filp,struct kvm_reg_list reg_list;unsigned n; +/* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */ +if (unlikely (vcpu->arch.target <0 )) +return -ENOEXEC ; +if (copy_from_user (®_list, user_list,sizeof (reg_list)))return -EFAULT ; n = reg_list.n;
So we also have the same snippet in kvm_arch_vcpu_ioctl_run().
Can you create a static function (kvm_vcpu_initialized?) containing that code and make all three sites use it?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH 1/1 ARM: KVM: prevent NULL pointer dereference with KVM ioctl
Quoted 45 lines · Marc Zyngier
Quoted 31 lines · Andre Przywara
Some ARM KVM VCPU ioctls require the vCPU to be properly initialized with the
KVM_ARM_VCPU_INITioctl before being used with further requests.KVM_RUNchecks whether this initialization has been done, but other ioctls do not.
NamelyKVM_GET_REG_LISTwill dereference an array with index -1 without initialization and thus leads to a kernel oops. Fix this by adding checks before executing the ioctl handlers.Signed-off-by Andre Przywara <[email protected]>--- arch/arm/kvm/arm.c | 9 +++++++++ 1 file changed, 9 insertions(+)arch/arm/kvm/arm.c +5
-0@@ -893,6 +893,11 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_SET_ONE_REG :case KVM_GET_ONE_REG : {struct kvm_one_reg reg; + +/* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */ +if (unlikely (vcpu->arch.target <0 )) +return -ENOEXEC ; +if (copy_from_user (®, argp,sizeof (reg)))return -EFAULT ;if (ioctl ==KVM_SET_ONE_REG )arch/arm/kvm/arm.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 919
Quoted 10 lines
arch/arm/kvm/arm.c +4
-0@@ -905,6 +910,10 @@ long kvm_arch_vcpu_ioctl(struct file *filp,struct kvm_reg_list reg_list;unsigned n; +/* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */ +if (unlikely (vcpu->arch.target <0 )) +return -ENOEXEC ; +if (copy_from_user (®_list, user_list,sizeof (reg_list)))return -EFAULT ; n = reg_list.n;So we also have the same snippet in
kvm_arch_vcpu_ioctl_run().
Quoted 3 lines
Can you create a static function (
kvm_vcpu_initialized?) containing that code and make all three sites use it?
Andre, will you re-spin your patch as per Marc's comments?
Thanks,
-Christoffer
PATCH 1/1 ARM: KVM: prevent NULL pointer dereference with KVM ioctl
Quoted 46 lines · Christoffer Dall
Quoted 45 lines · Marc Zyngier
Quoted 31 lines · Andre Przywara
Some ARM KVM VCPU ioctls require the vCPU to be properly initialized with the
KVM_ARM_VCPU_INITioctl before being used with further requests.KVM_RUNchecks whether this initialization has been done, but other ioctls do not.
NamelyKVM_GET_REG_LISTwill dereference an array with index -1 without initialization and thus leads to a kernel oops. Fix this by adding checks before executing the ioctl handlers.Signed-off-by Andre Przywara <[email protected]>--- arch/arm/kvm/arm.c | 9 +++++++++ 1 file changed, 9 insertions(+)arch/arm/kvm/arm.c +5
-0@@ -893,6 +893,11 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_SET_ONE_REG :case KVM_GET_ONE_REG : {struct kvm_one_reg reg; + +/* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */ +if (unlikely (vcpu->arch.target <0 )) +return -ENOEXEC ; +if (copy_from_user (®, argp,sizeof (reg)))return -EFAULT ;if (ioctl ==KVM_SET_ONE_REG )arch/arm/kvm/arm.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 919
Quoted 10 lines
arch/arm/kvm/arm.c +4
-0@@ -905,6 +910,10 @@ long kvm_arch_vcpu_ioctl(struct file *filp,struct kvm_reg_list reg_list;unsigned n; +/* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */ +if (unlikely (vcpu->arch.target <0 )) +return -ENOEXEC ; +if (copy_from_user (®_list, user_list,sizeof (reg_list)))return -EFAULT ; n = reg_list.n;So we also have the same snippet in
kvm_arch_vcpu_ioctl_run().
Quoted 5 lines
Quoted 3 lines
Can you create a static function (
kvm_vcpu_initialized?) containing that code and make all three sites use it?Andre, will you re-spin your patch as per Marc's comments?
oh, never mind, missed it when I looked over the mails.
-Christoffer