From nobody Fri Apr 19 14:30:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652382370; cv=none; d=zohomail.com; s=zohoarc; b=g5PNrnNW5eGGjmrJTv7//vEpZ9qmZEikedaVg8+/rJTWL0MQPlurp4zoVleLN8GxLpMXxwQTWDSen2zH/JeudqY4M/uCbau1m9607MQHIgXeIOYOiYo5loG9tlLiBPD0dXas2XsUB8nQGJ6bPGNYklhpGLBfeA0SquFKZrUjWQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652382370; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iY4ieypF1u3bLIJmHhsw+EpUiurJRhvqodmb1z++LGw=; b=AAmp+cGjVJ5NWr8QGPaeg7Wev8HEHDBBezdl1JKZSXbraVJLJ1eOXe8fIjYFKY/G4ZdT7gRDEiR/eDoQrX9x4wcvAM14EretIuEI4VRYhB9217ZNFFTQNYz9wr+x8S+SZNGCZXbIZBgP/eQDoVKe3IOKS6zbq449kNl7nzLed2Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165238237056395.92965132593895; Thu, 12 May 2022 12:06:10 -0700 (PDT) Received: from localhost ([::1]:57252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npE8W-0001kf-Hf for importer@patchew.org; Thu, 12 May 2022 15:06:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4d-0000NW-CG for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4b-0001hz-OY for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:03 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-154-YzXp2Mo_PkaaKeiX8FMLiA-1; Thu, 12 May 2022 13:57:55 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D05358EFAF5; Thu, 12 May 2022 17:57:53 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0532543E390; Thu, 12 May 2022 17:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652378281; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iY4ieypF1u3bLIJmHhsw+EpUiurJRhvqodmb1z++LGw=; b=GWXbkDnmWZGLD2W2dXaQU3UlItu03eKK4+dAekKUWVKS+wHzG0g4lXFqF6E+JvlFJTSYNF zwnBeDzISgN99u7csxyRl5o9AyShej1Q29xOUeBFeVgZp71AbhW9RoOGRQU9tHYGnVSiVZ AzYkbnyDi+T8sfREqpQXXLCZLgkyPqg= X-MC-Unique: YzXp2Mo_PkaaKeiX8FMLiA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Laurent Vivier , Harpreet Singh Anand , qemu-stable@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Jason Wang , "Gonglei (Arei)" , Cindy Lu Subject: [PATCH 1/6] vhost: Track descriptor chain in private at SVQ Date: Thu, 12 May 2022 19:57:42 +0200 Message-Id: <20220512175747.142058-2-eperezma@redhat.com> In-Reply-To: <20220512175747.142058-1-eperezma@redhat.com> References: <20220512175747.142058-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652382373091100001 The device could have access to modify them, and it definitely have access when we implement packed vq. Harden SVQ maintaining a private copy of the descriptor chain. Other fields like buffer addresses are already maintained sepparatedly. Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.h | 6 ++++++ hw/virtio/vhost-shadow-virtqueue.c | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-vi= rtqueue.h index e5e24c536d..c132c994e9 100644 --- a/hw/virtio/vhost-shadow-virtqueue.h +++ b/hw/virtio/vhost-shadow-virtqueue.h @@ -53,6 +53,12 @@ typedef struct VhostShadowVirtqueue { /* Next VirtQueue element that guest made available */ VirtQueueElement *next_guest_avail_elem; + /* + * Backup next field for each descriptor so we can recover securely, n= ot + * needing to trust the device access. + */ + uint16_t *desc_next; + /* Next head to expose to the device */ uint16_t shadow_avail_idx; diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 1e5cfe2af6..1d6552b0fe 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -138,6 +138,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueu= e *svq, hwaddr *sg, for (n =3D 0; n < num; n++) { if (more_descs || (n + 1 < num)) { descs[i].flags =3D flags | cpu_to_le16(VRING_DESC_F_NEXT); + descs[i].next =3D cpu_to_le16(svq->desc_next[i]); } else { descs[i].flags =3D flags; } @@ -145,10 +146,10 @@ static void vhost_vring_write_descs(VhostShadowVirtqu= eue *svq, hwaddr *sg, descs[i].len =3D cpu_to_le32(iovec[n].iov_len); last =3D i; - i =3D cpu_to_le16(descs[i].next); + i =3D cpu_to_le16(svq->desc_next[i]); } - svq->free_head =3D le16_to_cpu(descs[last].next); + svq->free_head =3D le16_to_cpu(svq->desc_next[last]); } static bool vhost_svq_add_split(VhostShadowVirtqueue *svq, @@ -336,7 +337,6 @@ static void vhost_svq_disable_notification(VhostShadowV= irtqueue *svq) static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *len) { - vring_desc_t *descs =3D svq->vring.desc; const vring_used_t *used =3D svq->vring.used; vring_used_elem_t used_elem; uint16_t last_used; @@ -365,7 +365,7 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowV= irtqueue *svq, return NULL; } - descs[used_elem.id].next =3D svq->free_head; + svq->desc_next[used_elem.id] =3D svq->free_head; svq->free_head =3D used_elem.id; *len =3D used_elem.len; @@ -540,8 +540,9 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIOD= evice *vdev, svq->vring.used =3D qemu_memalign(qemu_real_host_page_size(), device_s= ize); memset(svq->vring.used, 0, device_size); svq->ring_id_maps =3D g_new0(VirtQueueElement *, svq->vring.num); + svq->desc_next =3D g_new0(uint16_t, svq->vring.num); for (unsigned i =3D 0; i < svq->vring.num - 1; i++) { - svq->vring.desc[i].next =3D cpu_to_le16(i + 1); + svq->desc_next[i] =3D cpu_to_le16(i + 1); } } @@ -574,6 +575,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq) virtqueue_detach_element(svq->vq, next_avail_elem, 0); } svq->vq =3D NULL; + g_free(svq->desc_next); g_free(svq->ring_id_maps); qemu_vfree(svq->vring.desc); qemu_vfree(svq->vring.used); -- 2.27.0 From nobody Fri Apr 19 14:30:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652381876; cv=none; d=zohomail.com; s=zohoarc; b=Nl6pzzCdUF6/yj64OINQ8+/4yNdBrZNrI8ynNqt9lUpSIsFGxmCBZ8w2dgGOBA2CinZ9hEivQNoibS7jDEod+FJUZG04ZRaCreaPgXDtYeK0hcsqDPobnhPlcUgQQfHkhp+8HeYyYePvnh300F+BZQO8vIK2t0VugkB06LqlKU8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652381876; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/HqXl0e8d4AvopNhSor6yOCxE50p3KojYSBCMiIVygc=; b=EeNNM8BSgxGL+wI1zqj1YoH5aKBxkyU/Ahrf+8I5Eebd6V7aEYGMsoyUY6DqML4LQXV4zdCRRR/shk2IbKRJmqhM9Hw7/Kw4ouDE6dg55XKCGx6NzSKXZyoshwxzG77hwxm/y1v52oir+DDGSgPDuorWxEdoPTxbL2Rz1rofONk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652381876273879.8832044120295; Thu, 12 May 2022 11:57:56 -0700 (PDT) Received: from localhost ([::1]:48094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npE0Z-0003K7-4F for importer@patchew.org; Thu, 12 May 2022 14:57:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4b-0000KM-Uw for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38157) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4a-0001hZ-Ed for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:01 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-296-uZ9KkI0zNzGSNBs8t5IGDA-1; Thu, 12 May 2022 13:57:56 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7D7E38349C0; Thu, 12 May 2022 17:57:55 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26B4E438EFC; Thu, 12 May 2022 17:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652378279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/HqXl0e8d4AvopNhSor6yOCxE50p3KojYSBCMiIVygc=; b=RhZ7/bZrNIA0W3RL37NosuOVWJs8eyg2uf9mkQBOh023nt8l4+3hREwVPEClavc06DlLFJ g1GzzebRKdAPurqt7v7iysmDflJ+85HldO2Ici+jSEUXR631BMQ2y5+/83kXqbqXc1cTht eiFVkgGU6dwB8RcFdHMPtM7qH6ij1U4= X-MC-Unique: uZ9KkI0zNzGSNBs8t5IGDA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Laurent Vivier , Harpreet Singh Anand , qemu-stable@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Jason Wang , "Gonglei (Arei)" , Cindy Lu Subject: [PATCH 2/6] vhost: Fix device's used descriptor dequeue Date: Thu, 12 May 2022 19:57:43 +0200 Message-Id: <20220512175747.142058-3-eperezma@redhat.com> In-Reply-To: <20220512175747.142058-1-eperezma@redhat.com> References: <20220512175747.142058-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652381877080100001 Only the first one of them were properly enqueued back. Fixes: 100890f7ca ("vhost: Shadow virtqueue buffers forwarding") Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index 1d6552b0fe..a8376ef82b 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -334,12 +334,22 @@ static void vhost_svq_disable_notification(VhostShado= wVirtqueue *svq) svq->vring.avail->flags |=3D cpu_to_le16(VRING_AVAIL_F_NO_INTERRUPT); } =20 +static uint16_t vhost_svq_last_desc_of_chain(const VhostShadowVirtqueue *s= vq, + uint16_t num, uint16_t i) +{ + for (uint16_t j =3D 0; j < (num - 1); ++j) { + i =3D le16_to_cpu(svq->desc_next[i]); + } + + return i; +} + static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq, uint32_t *len) { const vring_used_t *used =3D svq->vring.used; vring_used_elem_t used_elem; - uint16_t last_used; + uint16_t last_used, last_used_chain, num; =20 if (!vhost_svq_more_used(svq)) { return NULL; @@ -365,7 +375,10 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadow= Virtqueue *svq, return NULL; } =20 - svq->desc_next[used_elem.id] =3D svq->free_head; + num =3D svq->ring_id_maps[used_elem.id]->in_num + + svq->ring_id_maps[used_elem.id]->out_num; + last_used_chain =3D vhost_svq_last_desc_of_chain(svq, num, used_elem.i= d); + svq->desc_next[last_used_chain] =3D svq->free_head; svq->free_head =3D used_elem.id; =20 *len =3D used_elem.len; --=20 2.27.0 From nobody Fri Apr 19 14:30:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652380064; cv=none; d=zohomail.com; s=zohoarc; b=J0GC6fMFZvppmzYrt7Qa1l4pae0UMPAlXir6/s6h9NQ7FiligbdUVV2aJ86Ue7BuoufGhQ6KPlOvl0Ol5lgaf0zpfGMbACEOUQEj7jOLR9ND7h+d/hmQesSdFUqtiXxj9ZBOOXML5wV12zZ773ch2iGUP3u6cBYO3g0S8FN7Y9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652380064; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=horrKLSX5UQc3hpFHfe34qtWNP3DxGqYAhUxa1zSGl0=; b=etS5fkXgCWhc8+6O+kOm9R00RlY9ZdPB4D5obQfPQV6wRkYWXlFVFHQiTomcsN613JWufG1LVPNgQqNDl+5fT4ND1oq9Vxkw06zdpgpYcDb/R6+6YnRzHqWqVGPefWd42mOe0j3V7R4/gAZ8Y1aIZEDKo9hNh5xVqJImW0IOQF0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652380064554975.5009098677529; Thu, 12 May 2022 11:27:44 -0700 (PDT) Received: from localhost ([::1]:60886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npDXH-0006CI-6c for importer@patchew.org; Thu, 12 May 2022 14:27:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4e-0000RG-Ra for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36849) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4c-0001iB-LZ for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:04 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-152-TbzKXWBhOD-KqV74lxs3cA-1; Thu, 12 May 2022 13:57:58 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0743D2A5955B; Thu, 12 May 2022 17:57:58 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A3C943E390; Thu, 12 May 2022 17:57:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652378282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=horrKLSX5UQc3hpFHfe34qtWNP3DxGqYAhUxa1zSGl0=; b=DrN9H2zlawNkbFvk2C5bXXZR1sVjg8DzkThFNt+V6ZZrTNC4YZanxLU7l4jk5UH1kZFU2h TCnrltfFGTCx1P4Obig8XcH6nyOycUYmuVY8Fd9NXo1DftvBY50EJs7isZgXe8SLZCZFOH wcgVSQLRW/CzpemRzx8dPhIA3Y5g2CE= X-MC-Unique: TbzKXWBhOD-KqV74lxs3cA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Laurent Vivier , Harpreet Singh Anand , qemu-stable@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Jason Wang , "Gonglei (Arei)" , Cindy Lu Subject: [PATCH 3/6] vdpa: Fix bad index calculus at vhost_vdpa_get_vring_base Date: Thu, 12 May 2022 19:57:44 +0200 Message-Id: <20220512175747.142058-4-eperezma@redhat.com> In-Reply-To: <20220512175747.142058-1-eperezma@redhat.com> References: <20220512175747.142058-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652380065888100003 Fixes: 6d0b222666 ("vdpa: Adapt vhost_vdpa_get_vring_base to SVQ") Acked-by: Jason Wang Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index a30510ed17..493269b0b5 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1172,11 +1172,11 @@ static int vhost_vdpa_get_vring_base(struct vhost_d= ev *dev, struct vhost_vring_state *ring) { struct vhost_vdpa *v =3D dev->opaque; + int vdpa_idx =3D ring->index - dev->vq_index; int ret; =20 if (v->shadow_vqs_enabled) { - VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, - ring->index); + VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, vdp= a_idx); =20 /* * Setting base as last used idx, so destination will see as avail= able --=20 2.27.0 From nobody Fri Apr 19 14:30:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652380853; cv=none; d=zohomail.com; s=zohoarc; b=Q1OYg+Ix2z8arl/UJbbRbAxu9+rD75q+zqS7KACOvVoEeYC9I3urhb3xJX1asjG8r29eiGMVqZhDLuviXUNNXRmQ4ceDbKz2I3tKywhS9O+5I9ofiXG8g6yIkjeFAhBJTNIFbvsXXk1fjE+1GYmjxsNBhrCvWlx/G+Yc08PmGH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652380853; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eyfecB7cDAHlStp0iGvtgqADQTrNlA30aKHmxiznVwA=; b=GY/ojq3wtf+QyMjvI/zDi9/agw2Q9jO6W8YEa9AbyifD/uXbNFYMUQbfv2q/w5Z7oqInNjXx/d0Z/pRfKvYpEtPZnhGQnlRu9Ru8llhjJnTZdaG5P0WiPPOTimxT7HbV1Uaa8HAp9WmtYJD10NhDhjlQ/bOTSrhRmBc7oTID+v8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165238085360759.112823930971444; Thu, 12 May 2022 11:40:53 -0700 (PDT) Received: from localhost ([::1]:52612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npDk4-0003A6-HC for importer@patchew.org; Thu, 12 May 2022 14:40:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4g-0000XH-AU for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4e-0001im-Od for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:06 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-552-mBU0YjqYNjSqB7K283lKGw-1; Thu, 12 May 2022 13:58:00 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25853801E80; Thu, 12 May 2022 17:58:00 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5172243E390; Thu, 12 May 2022 17:57:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652378284; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eyfecB7cDAHlStp0iGvtgqADQTrNlA30aKHmxiznVwA=; b=TgWtsA2my9swrpi/WAMW/dFYSPKh4qBo6mJR6UJPMUdHTuJUUkHG/SXTEQ3AxtmWUVuAr3 GXa7RQEk8aDVWODoOlVCbB/TxEPSLXvjKIKkRYSvNaoX6LXcVRVOP4v5vrNAJuIoPYrBX/ +MD9YjveMTbXy6uWQsmkizxdi/yGJi8= X-MC-Unique: mBU0YjqYNjSqB7K283lKGw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Laurent Vivier , Harpreet Singh Anand , qemu-stable@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Jason Wang , "Gonglei (Arei)" , Cindy Lu Subject: [PATCH 4/6] vdpa: Fix index calculus at vhost_vdpa_svqs_start Date: Thu, 12 May 2022 19:57:45 +0200 Message-Id: <20220512175747.142058-5-eperezma@redhat.com> In-Reply-To: <20220512175747.142058-1-eperezma@redhat.com> References: <20220512175747.142058-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652380855734100001 With the introduction of MQ the index of the vq needs to be calculated with the device model vq_index. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 493269b0b5..ed106bff47 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -1018,7 +1018,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *d= ev) VirtQueue *vq =3D virtio_get_queue(dev->vdev, dev->vq_index + i); VhostShadowVirtqueue *svq =3D g_ptr_array_index(v->shadow_vqs, i); struct vhost_vring_addr addr =3D { - .index =3D i, + .index =3D dev->vq_index + i, }; int r; bool ok =3D vhost_vdpa_svq_setup(dev, svq, i, &err); --=20 2.27.0 From nobody Fri Apr 19 14:30:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652382841; cv=none; d=zohomail.com; s=zohoarc; b=MqAxAFPyCMxV9AxZ5g4r9fE9urC2MZBWqaFdDpRNqwg4Wjxd9LVrPidZQQ9lhcfcec1RJGAMxtHhywrm5sAZWBNrpSxNW0O7CBr2RFjj6ijUikgf0kGbBhGDRN3tCdCR1Nyv8YoeciQWEzb/6QFz2hfjA3O24Y9GqXQ/miWajM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652382841; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4PkJ9AftPi32TpD+kjV0SOKYsI2NXHREerwEsgX8ncQ=; b=AE/PYA0XQ6EJU52SnFoYB1cAxwJhtkvUn9BJyCqXS8f+Y4bB/2AQbGWC65U+NPtbCbDbVHSAG4XOjaocUH8exjBgxFH0STebu3p1vv7jC9BvQgzo+rzv/IpqJC+4NOK1DnGcZWYwIpgGDLjOrBTF6AeC5Qtm6CCm+Wzz27DN+ac= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652382841395764.0335921269609; Thu, 12 May 2022 12:14:01 -0700 (PDT) Received: from localhost ([::1]:40120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npEG8-00031N-6F for importer@patchew.org; Thu, 12 May 2022 15:14:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4l-0000lT-Rw for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:40186) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4i-0001kr-OD for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:11 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-325-lj35mmpdNyuKqmB19TRU7g-1; Thu, 12 May 2022 13:58:02 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 46C4E811E80; Thu, 12 May 2022 17:58:02 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AE1443E390; Thu, 12 May 2022 17:58:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652378287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4PkJ9AftPi32TpD+kjV0SOKYsI2NXHREerwEsgX8ncQ=; b=OFO2I68IBoRc+IsCLVMC7Tq4R7uysTPXoA41pB41KmrCkp0slkmJ8tkdklWd+Kb9tEnUbE yA/VibsQU5cpisMY9XwOt4Gt8lMcWliO0eBWc/Cxa7dwgxLS7VHime5QVa7tAzeoGMS1tv wtQBsfo3cI7Vg0EinQBSIdfAcJaVgrM= X-MC-Unique: lj35mmpdNyuKqmB19TRU7g-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Laurent Vivier , Harpreet Singh Anand , qemu-stable@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Jason Wang , "Gonglei (Arei)" , Cindy Lu Subject: [PATCH 5/6] hw/virtio: Replace g_memdup() by g_memdup2() Date: Thu, 12 May 2022 19:57:46 +0200 Message-Id: <20220512175747.142058-6-eperezma@redhat.com> In-Reply-To: <20220512175747.142058-1-eperezma@redhat.com> References: <20220512175747.142058-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652382841782100001 From: Philippe Mathieu-Daud=C3=A9 Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-memdu= p2-now/5538 The old API took the size of the memory to duplicate as a guint, whereas most memory functions take memory sizes as a gsize. This made it easy to accidentally pass a gsize to g_memdup(). For large values, that would lead to a silent truncation of the size from 64 to 32 bits, and result in a heap area being returned which is significantly smaller than what the caller expects. This can likely be exploited in various modules to cause a heap buffer overflow. Replace g_memdup() by the safer g_memdup2() wrapper. Acked-by: Jason Wang Acked-by: Eugenio P=C3=A9rez Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/net/virtio-net.c | 3 ++- hw/virtio/virtio-crypto.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 1067e72b39..e4748a7e6c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev= , VirtQueue *vq) } =20 iov_cnt =3D elem->out_num; - iov2 =3D iov =3D g_memdup(elem->out_sg, sizeof(struct iovec) * ele= m->out_num); + iov2 =3D iov =3D g_memdup2(elem->out_sg, + sizeof(struct iovec) * elem->out_num); s =3D iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl)); iov_discard_front(&iov, &iov_cnt, sizeof(ctrl)); if (s !=3D sizeof(ctrl)) { diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index dcd80b904d..0e31e3cc04 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -242,7 +242,7 @@ static void virtio_crypto_handle_ctrl(VirtIODevice *vde= v, VirtQueue *vq) } =20 out_num =3D elem->out_num; - out_iov_copy =3D g_memdup(elem->out_sg, sizeof(out_iov[0]) * out_n= um); + out_iov_copy =3D g_memdup2(elem->out_sg, sizeof(out_iov[0]) * out_= num); out_iov =3D out_iov_copy; =20 in_num =3D elem->in_num; @@ -605,11 +605,11 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) } =20 out_num =3D elem->out_num; - out_iov_copy =3D g_memdup(elem->out_sg, sizeof(out_iov[0]) * out_num); + out_iov_copy =3D g_memdup2(elem->out_sg, sizeof(out_iov[0]) * out_num); out_iov =3D out_iov_copy; =20 in_num =3D elem->in_num; - in_iov_copy =3D g_memdup(elem->in_sg, sizeof(in_iov[0]) * in_num); + in_iov_copy =3D g_memdup2(elem->in_sg, sizeof(in_iov[0]) * in_num); in_iov =3D in_iov_copy; =20 if (unlikely(iov_to_buf(out_iov, out_num, 0, &req, sizeof(req)) --=20 2.27.0 From nobody Fri Apr 19 14:30:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1652381235; cv=none; d=zohomail.com; s=zohoarc; b=Q0rY4RydZmKh4yPmMF1TmCFOQoBIxFg0l52OdE09GXlo38IDih2oziTzCqGoPaMBgg57vDcQyoBDEsZjixnYwV8Lr5JR5raHrPXFlSEvHgDBQG7sSpSZvUUn0sn8iUM1pOBFMqXpu9/YK8q8wmAXJjBv7mcR9ukj/xnY8OfYrfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652381235; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Lcr2WOpJYbpUL+DcJ8ruYB6/M8/E0ReWvgqIYFP/sIk=; b=mvw9BTiyGR9GUGwhpdoOI5p+ER42QJOeIueVcwa3X08MfhzUkOEJ6/tGggh28pCsqrcXSzhAekkko7ZxrlLk359tdAvFSuAb7900fAPh1RqrCVCyiukwOJ4pmQMIJajIuCzSWHYXasWKTmHmB7VxhRIHmUbIk3vnczPqz41Yfgo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652381235336948.6652132675887; Thu, 12 May 2022 11:47:15 -0700 (PDT) Received: from localhost ([::1]:33202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npDqE-0000wP-8C for importer@patchew.org; Thu, 12 May 2022 14:47:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4k-0000ik-Bf for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npD4i-0001lA-Md for qemu-devel@nongnu.org; Thu, 12 May 2022 13:58:09 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-179-FjJ5zO1AMA6zzzZNJ2ad0w-1; Thu, 12 May 2022 13:58:04 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61BFF101A52C; Thu, 12 May 2022 17:58:04 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9212A43E392; Thu, 12 May 2022 17:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652378288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lcr2WOpJYbpUL+DcJ8ruYB6/M8/E0ReWvgqIYFP/sIk=; b=GLs9GjsQyBtui2Ellsx9Rm+7HSqaj3x5gMPyeZ2KELh4XdySPb/+zyOUhQ92sxn5XV1qA7 dcqUvk8+M6o+O20HdY8carASSr6sO4ZFy+NFm+Ed4nPvPoxJ6XQkHwGfyBYU3U+Y+PinNx l1czQTGnuXtIGWXFRdmiF2G2IBi9Beg= X-MC-Unique: FjJ5zO1AMA6zzzZNJ2ad0w-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Gautam Dawar , Laurent Vivier , Harpreet Singh Anand , qemu-stable@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Jason Wang , "Gonglei (Arei)" , Cindy Lu Subject: [PATCH 6/6] vhost: Fix element in vhost_svq_add failure Date: Thu, 12 May 2022 19:57:47 +0200 Message-Id: <20220512175747.142058-7-eperezma@redhat.com> In-Reply-To: <20220512175747.142058-1-eperezma@redhat.com> References: <20220512175747.142058-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1652381236381100001 Coverity rightly reports that is not free in that case. Fixes: Coverity CID 1487559 Fixes: 100890f7ca ("vhost: Shadow virtqueue buffers forwarding") Signed-off-by: Eugenio P=C3=A9rez --- hw/virtio/vhost-shadow-virtqueue.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-vi= rtqueue.c index a8376ef82b..56c96ebd13 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -199,11 +199,19 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue = *svq, return true; } =20 +/** + * Add an element to a SVQ. + * + * The caller must check that there is enough slots for the new element. It + * takes ownership of the element: In case of failure, it is free and the = SVQ + * is considered broken. + */ static bool vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *ele= m) { unsigned qemu_head; bool ok =3D vhost_svq_add_split(svq, elem, &qemu_head); if (unlikely(!ok)) { + g_free(elem); return false; } =20 --=20 2.27.0