Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9277467pxu; Mon, 28 Dec 2020 11:10:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3VCt0wLo6E7JUHJwYoN4g5hqcp50OG87sFPxxtGBAL9Dfv50xru8kuQiztgUkFNzUCmgm X-Received: by 2002:aa7:dc0d:: with SMTP id b13mr43462664edu.170.1609182621257; Mon, 28 Dec 2020 11:10:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609182621; cv=none; d=google.com; s=arc-20160816; b=EENrjTgZjaexFDl+YgO2upN/0c6A5PF8Vf1+vbm6tlKYXVuHwMm0mXOI3BPGCQUVH5 fzebNyHfNFZHiUrp4wqhTgVUeJFnEhtO+TMjS+ZkV9DtUAL0eVzFO9GbA6jslKnxaMlc QCbscU7YMjTUyOtld6g8C7b7cXfWSBtTgwchtHMRIcjiQVffme0pzvBERwzPKRoU4UnS 9rttMvBab7zfPoM3QIWljQbWB+2Xb+dKXbwefqgOAIYG4gbAvHayyuNDOUiyohvIoggc l7beBXcwlrrr9kCRHqfFRoQ9/7txGMeKeD4xjVmxloTs6RsZT7AFK5OhVwv0PUbs+sVL cMFA== 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=cmObvFm2lrpzMq5E2JDOXRws+LJwW/vFo2Cd3nsfoVI=; b=R4F4+CbdUr3EHJD3H8dV3twWwrnYkuuQN9zyApz30I8NP3V0nNyoTj8tyaAK3lqSZX dIf4Y/KFMsJv7VInO8+QTwBOVF/0gAfeg2OM2OV+Kv3viEERxobES116GPyAaHv/k8cj /dB2INX/icPsTnpXyhovdmkWnKgIRCKWmyNkialIP4nKaa4tTQ4cDLrPeOX1M9LOu8NN 1+p6X0Rath573SA2vBVx3ACym01TWxvYN18ZQ0ypKGdePlZ8i7ec22us/4zcrh4z5jG7 /5NkTQ5bVQeGzQkbmQrNMRfYULj65zIbzpV7iu7nM8QTclaCWI+QikiYjBmU7pbrMOi+ 3W5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kbKxh4s6; 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 b24si20969202eds.235.2020.12.28.11.09.59; Mon, 28 Dec 2020 11:10:21 -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=kbKxh4s6; 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 S2407331AbgL1Nxh (ORCPT + 99 others); Mon, 28 Dec 2020 08:53:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:55360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391551AbgL1Nxd (ORCPT ); Mon, 28 Dec 2020 08:53:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DA484208B3; Mon, 28 Dec 2020 13:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609163572; bh=udMr1+ezdY5xGDueHfvt5TWpLGn73565yyT6LJrU4vU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kbKxh4s6F1fCmuZjekGpARWAXOf8KND6rgxNakXDq/kE9Dz4DLTTqjE92/Epxu8Vh /vio1fo0Y+gotfgaAwPzAq9jJAHmr0pvynylQOl8vvf9Fn74TT5fNsPCt8ZU7k9xbJ 7sTCPi7pYQV86xzBQy7HR42CWHBLN9L+hhBpdGzU= 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.4 305/453] virtio_ring: Fix two use after free bugs Date: Mon, 28 Dec 2020 13:49:01 +0100 Message-Id: <20201228124951.884970888@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124937.240114599@linuxfoundation.org> References: <20201228124937.240114599@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 e3e8cab81abdf..97e8a195e18f5 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