Re: Virt: Kvm - Fix possible ERR_PTR() dereferencing.

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

 




On 20/09/2016 08:50, Shailendra Verma wrote:
> This is of course wrong to call kfree() if memdup_user() fails,
> no memory was allocated and the error in the error-valued pointer
> should be returned.
> 
> Reviewed-by: Ravikant Sharma <ravikant.s2@xxxxxxxxxxx>
> Signed-off-by: Shailendra Verma <shailendra.v@xxxxxxxxxxx>
> ---
>  virt/kvm/kvm_main.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 484079e..e3a0653 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2398,10 +2398,8 @@ out_free1:
>  
>  		r = -ENOMEM;
>  		kvm_regs = memdup_user(argp, sizeof(*kvm_regs));
> -		if (IS_ERR(kvm_regs)) {
> -			r = PTR_ERR(kvm_regs);
> -			goto out;
> -		}
> +		if (IS_ERR(kvm_regs))
> +			return PTR_ERR(kvm_regs);

This incorrectly skips the vcpu_put at the end.

Paolo

>  		r = kvm_arch_vcpu_ioctl_set_regs(vcpu, kvm_regs);
>  		kfree(kvm_regs);
>  		break;
> @@ -2422,11 +2420,8 @@ out_free1:
>  	}
>  	case KVM_SET_SREGS: {
>  		kvm_sregs = memdup_user(argp, sizeof(*kvm_sregs));
> -		if (IS_ERR(kvm_sregs)) {
> -			r = PTR_ERR(kvm_sregs);
> -			kvm_sregs = NULL;
> -			goto out;
> -		}
> +		if (IS_ERR(kvm_sregs))
> +			return PTR_ERR(kvm_sregs);
>  		r = kvm_arch_vcpu_ioctl_set_sregs(vcpu, kvm_sregs);
>  		break;
>  	}
> @@ -2514,11 +2509,8 @@ out_free1:
>  	}
>  	case KVM_SET_FPU: {
>  		fpu = memdup_user(argp, sizeof(*fpu));
> -		if (IS_ERR(fpu)) {
> -			r = PTR_ERR(fpu);
> -			fpu = NULL;
> -			goto out;
> -		}
> +		if (IS_ERR(fpu))
> +			return PTR_ERR(fpu);
>  		r = kvm_arch_vcpu_ioctl_set_fpu(vcpu, fpu);
>  		break;
>  	}
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux