lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1ce2bee4-64ed-f630-2695-8e8b9b8e27c1@redhat.com>
Date:   Wed, 26 Feb 2020 11:13:57 +0800
From:   Jason Wang <jasowang@...hat.com>
To:     Suman Anna <s-anna@...com>, "Michael S. Tsirkin" <mst@...hat.com>
Cc:     Tiwei Bie <tiwei.bie@...el.com>,
        "David S. Miller" <davem@...emloft.net>,
        virtualization@...ts.linux-foundation.org,
        linux-kernel@...r.kernel.org, linux-remoteproc@...r.kernel.org
Subject: Re: [PATCH] virtio_ring: Fix mem leak with vring_new_virtqueue()


On 2020/2/26 上午12:51, Suman Anna wrote:
> Hi Jason,
>
> On 2/24/20 11:39 PM, Jason Wang wrote:
>> On 2020/2/25 上午5:26, Suman Anna wrote:
>>> The functions vring_new_virtqueue() and __vring_new_virtqueue() are used
>>> with split rings, and any allocations within these functions are managed
>>> outside of the .we_own_ring flag. The commit cbeedb72b97a ("virtio_ring:
>>> allocate desc state for split ring separately") allocates the desc state
>>> within the __vring_new_virtqueue() but frees it only when the
>>> .we_own_ring
>>> flag is set. This leads to a memory leak when freeing such allocated
>>> virtqueues with the vring_del_virtqueue() function.
>>>
>>> Fix this by moving the desc_state free code outside the flag and only
>>> for split rings. Issue was discovered during testing with remoteproc
>>> and virtio_rpmsg.
>>>
>>> Fixes: cbeedb72b97a ("virtio_ring: allocate desc state for split ring
>>> separately")
>>> Signed-off-by: Suman Anna<s-anna@...com>
>>> ---
>>>    drivers/virtio/virtio_ring.c | 4 ++--
>>>    1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
>>> index 867c7ebd3f10..58b96baa8d48 100644
>>> --- a/drivers/virtio/virtio_ring.c
>>> +++ b/drivers/virtio/virtio_ring.c
>>> @@ -2203,10 +2203,10 @@ void vring_del_virtqueue(struct virtqueue *_vq)
>>>                         vq->split.queue_size_in_bytes,
>>>                         vq->split.vring.desc,
>>>                         vq->split.queue_dma_addr);
>>> -
>>> -            kfree(vq->split.desc_state);
>>>            }
>>>        }
>>> +    if (!vq->packed_ring)
>>> +        kfree(vq->split.desc_state);
>> Nitpick, it looks to me it would be more clear if we just free
>> desc_state unconditionally here (and remove the kfree for packed above).
> OK, are you sure you want that to be folded into this patch? It looks to
> me a separate cleanup/consolidation patch, and packed desc_state does
> not suffer this memleak, and need not be backported into stable kernels.
>
> regards
> Suman


Though it's just a small tweak, I'm fine for leaving it for future.

So

Acked-by: Jason Wang <jasowang@...hat.com>

Thanks

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ