Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1222591

Re: [PATCH V4 2/4] kvm: fix double free for fast mmio eventfd

From Cornelia Huck <cornelia.huck@de.ibm.com>
Newsgroups linux.kernel
Subject Re: [PATCH V4 2/4] kvm: fix double free for fast mmio eventfd
Date 2015-09-11 09:50 +0200
Message-ID <q7rfQ-3xd-3@gated-at.bofh.it> (permalink)
References <q7n2x-645-3@gated-at.bofh.it> <q7n2x-645-5@gated-at.bofh.it>
Organization IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294

Show all headers | View raw


On Fri, 11 Sep 2015 11:17:35 +0800
Jason Wang <jasowang@redhat.com> wrote:

> We register wildcard mmio eventfd on two buses, one for KVM_MMIO_BUS
> and another is KVM_FAST_MMIO_BUS but with a single iodev
> instance. This will lead an issue: kvm_io_bus_destroy() knows nothing
> about the devices on two buses points to a single dev. Which will lead

s/points/pointing/

> double free[1] during exit. Fixing this by using allocate two

s/using allocate/allocating/

> instances of iodevs then register one on KVM_MMIO_BUS and another on
> KVM_FAST_MMIO_BUS.
> 
(...)

> @@ -929,8 +878,66 @@ kvm_deassign_ioeventfd_idx(struct kvm *kvm, enum kvm_bus bus_idx,
>  static int kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
>  {
>  	enum kvm_bus bus_idx = ioeventfd_bus_from_flags(args->flags);
> +	int ret = kvm_deassign_ioeventfd_idx(kvm, bus_idx, args);
> +
> +	if (!args->len)
> +		kvm_deassign_ioeventfd_idx(kvm, KVM_FAST_MMIO_BUS, args);

I think it would be good to explicitly check for bus_idx ==
KVM_MMIO_BUS here.

> +
> +	return ret;
> +}
> 
> -	return kvm_deassign_ioeventfd_idx(kvm, bus_idx, args);
> +static int
> +kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
> +{
> +	enum kvm_bus              bus_idx;
> +	int ret;
> +
> +	bus_idx = ioeventfd_bus_from_flags(args->flags);
> +	/* must be natural-word sized, or 0 to ignore length */
> +	switch (args->len) {
> +	case 0:
> +	case 1:
> +	case 2:
> +	case 4:
> +	case 8:
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	/* check for range overflow */
> +	if (args->addr + args->len < args->addr)
> +		return -EINVAL;
> +
> +	/* check for extra flags that we don't understand */
> +	if (args->flags & ~KVM_IOEVENTFD_VALID_FLAG_MASK)
> +		return -EINVAL;
> +
> +	/* ioeventfd with no length can't be combined with DATAMATCH */
> +	if (!args->len &&
> +	    args->flags & (KVM_IOEVENTFD_FLAG_PIO |
> +			   KVM_IOEVENTFD_FLAG_DATAMATCH))
> +		return -EINVAL;
> +
> +	ret = kvm_assign_ioeventfd_idx(kvm, bus_idx, args);
> +	if (ret)
> +		goto fail;
> +
> +	/* When length is ignored, MMIO is also put on a separate bus, for
> +	 * faster lookups.
> +	 */
> +	if (!args->len && !(args->flags & KVM_IOEVENTFD_FLAG_PIO)) {

Dito on a positive check for bus_idx == KVM_MMIO_BUS.

> +		ret = kvm_assign_ioeventfd_idx(kvm, KVM_FAST_MMIO_BUS, args);
> +		if (ret < 0)
> +			goto fast_fail;
> +	}
> +
> +	return 0;
> +
> +fast_fail:
> +	kvm_deassign_ioeventfd(kvm, args);

Shouldn't you use kvm_deassign_ioeventfd(kvm, bus_idx, args) here?

> +fail:
> +	return ret;
>  }
> 
>  int

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH V4 2/4] kvm: fix double free for fast mmio eventfd Jason Wang <jasowang@redhat.com> - 2015-09-11 05:20 +0200
  Re: [PATCH V4 2/4] kvm: fix double free for fast mmio eventfd Cornelia Huck <cornelia.huck@de.ibm.com> - 2015-09-11 09:50 +0200
    Re: [PATCH V4 2/4] kvm: fix double free for fast mmio eventfd Jason Wang <jasowang@redhat.com> - 2015-09-11 11:30 +0200
      Re: [PATCH V4 2/4] kvm: fix double free for fast mmio eventfd Cornelia Huck <cornelia.huck@de.ibm.com> - 2015-09-11 12:20 +0200

csiph-web