From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967240AbcHBOFH (ORCPT ); Tue, 2 Aug 2016 10:05:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48134 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967211AbcHBOEV (ORCPT ); Tue, 2 Aug 2016 10:04:21 -0400 Date: Tue, 2 Aug 2016 17:04:16 +0300 From: "Michael S. Tsirkin" To: Wei Yongjun Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH -next] virtio: fix possible memory leak in virtqueue_add() Message-ID: <20160802170351-mutt-send-email-mst@kernel.org> References: <1470146345-19531-1-git-send-email-weiyj.lk@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1470146345-19531-1-git-send-email-weiyj.lk@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 02 Aug 2016 14:04:18 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 02, 2016 at 01:59:05PM +0000, Wei Yongjun wrote: > desc may malloced in virtqueue_add() and should be freed before > leaving from the error handling cases, otherwise it will cause > memory leak. > > Signed-off-by: Wei Yongjun > --- > drivers/virtio/virtio_ring.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 114a0c8..bda71ef 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -328,6 +328,7 @@ static inline int virtqueue_add(struct virtqueue *_vq, > if (out_sgs) > vq->notify(&vq->vq); > END_USE(vq); > + kfree(desc); I think only if indirect is true, otherwise you will free vq->vring.desc. > return -ENOSPC; > }