Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9090863pxu; Mon, 28 Dec 2020 06:24:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1/obXFmAT9/AZ+4K4QB1Rf7QIcmtcuFgUYsl3hzfyDR6PMC6rgCDXRvFeZxkD4C4Fx7Bt X-Received: by 2002:aa7:c886:: with SMTP id p6mr43340792eds.352.1609165492455; Mon, 28 Dec 2020 06:24:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165492; cv=none; d=google.com; s=arc-20160816; b=wesQkPUkZ8H4LzBTW11nmuXa0bHTcIDt7HbtLioF6JLrPRCAxXEgxzvH2MLfHD3TSZ cJmbGZiPFr+u0TZDmtLJKHsW8E7HsxSwKVUTuwgvMpImzWR1ddF+r2YuHXCv9jbIzntc gJX6qbw8KyG9AooAfDNVxjHFueD6kWwTPVstU2+x6ZPDk0R1D3qmKl6HFTyeNUbZfY7b z2Y9z4nV7MBYA8X+2LqgxXtkwSW+y+bn0VVrPNyRFBUyyxZgYjc1KBFOWyuSmh5f7Wu8 du1yDlTLjw005nIwnxdxcctt1tF8o5A3HIvrIbjedP5VJfuFaSf+lof0Ygd3tjjY+iTX ybxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hUkjQ+FJN2orRYIR+WTAh6zVecZ5ujWYGesG1OGXgNs=; b=SuQzZc+BaXY1RcMD5bgwqkieVhJCGHhgKC00Xyjr6wQr493LT8Se/95twEdiwVGHfO HP006O36/IAupU6aqRK2TbGMosGgAibX1E7Ke8QxTqIElprI6Mhz7J3I9KZaSXzIi6wx pFu+Hx/SLWqcIogXCFG7FBlNGkOLjNd1GWmG0wEWmeq15yphZqD3mryDNbk3MVwBrSL5 k4GDsXsAuvl9OIvokbCymqZvDodkjNfkLyBnY9Us3/6R3qtDgn61xWyxhiS2F187EHzm CQ1KeGf+80iSClgk2eW9oo5z6kIXXwIppQvs3IDRBCMa+nEP95kffgiJ1YnwFqO+Tzgj 7FVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SYY/qPjf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i1si21011607edy.450.2020.12.28.06.24.28; Mon, 28 Dec 2020 06:24:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SYY/qPjf"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502639AbgL1OWW (ORCPT + 99 others); Mon, 28 Dec 2020 09:22:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:56246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2441686AbgL1OWO (ORCPT ); Mon, 28 Dec 2020 09:22:14 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D649520731; Mon, 28 Dec 2020 14:21:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165319; bh=DT+JgyDmWanLqDIAzzZ+1jqPi8DVkBgpjT3FkD4Z/c8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SYY/qPjf5qQYwnPY0Bl1qtHc1ITdrfPUwOeRumrVC2bFxTHUK9C1Oyferm+pWXniW 1Dx7KKVrYUQ2XgxHU1tkuMvAPSKuOj5qO6Y4bZxd+jplb1QnjL/kza0n6cvIkR8eNX +qJhgG0Q0M9poPSK2yL5dwztKDaDoQgddlLCSb+8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Buhren , Felicitas Hetzelt , Dan Carpenter , "Michael S. Tsirkin" , Jason Wang , Sasha Levin Subject: [PATCH 5.10 491/717] virtio_ring: Fix two use after free bugs Date: Mon, 28 Dec 2020 13:48:09 +0100 Message-Id: <20201228125044.489456056@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit e152d8af4220a05c9797591609151d404866beaa ] The "vq" struct is added to the "vdev->vqs" list prematurely. If we encounter an error later in the function then the "vq" is freed, but since it is still on the list that could lead to a use after free bug. Fixes: cbeedb72b97a ("virtio_ring: allocate desc state for split ring separately") Reported-by: Robert Buhren Reported-by: Felicitas Hetzelt Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/X8pGaG/zkI3jk8mk@mwanda Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang Signed-off-by: Sasha Levin --- 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 924b6b85376bd..71e16b53e9c18 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1608,7 +1608,6 @@ static struct virtqueue *vring_create_virtqueue_packed( vq->num_added = 0; vq->packed_ring = true; vq->use_dma_api = vring_use_dma_api(vdev); - list_add_tail(&vq->vq.list, &vdev->vqs); #ifdef DEBUG vq->in_use = false; vq->last_add_time_valid = false; @@ -1669,6 +1668,7 @@ static struct virtqueue *vring_create_virtqueue_packed( cpu_to_le16(vq->packed.event_flags_shadow); } + list_add_tail(&vq->vq.list, &vdev->vqs); return &vq->vq; err_desc_extra: @@ -2085,7 +2085,6 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->last_used_idx = 0; vq->num_added = 0; vq->use_dma_api = vring_use_dma_api(vdev); - list_add_tail(&vq->vq.list, &vdev->vqs); #ifdef DEBUG vq->in_use = false; vq->last_add_time_valid = false; @@ -2127,6 +2126,7 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index, memset(vq->split.desc_state, 0, vring.num * sizeof(struct vring_desc_state_split)); + list_add_tail(&vq->vq.list, &vdev->vqs); return &vq->vq; } EXPORT_SYMBOL_GPL(__vring_new_virtqueue); -- 2.27.0