From patchwork Sun May 16 03:03:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 12260137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87DCCC43460 for ; Sun, 16 May 2021 03:07:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3396661264 for ; Sun, 16 May 2021 03:07:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3396661264 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1li77w-0000WX-BG for qemu-devel@archiver.kernel.org; Sat, 15 May 2021 23:07:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1li74o-0000om-Eb for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:22 -0400 Received: from m12-13.163.com ([220.181.12.13]:51847) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1li74i-0002Zj-VH for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=8RKfS 0LKkqB2rg2p/FeSJzPg2FwjNOaF3v/+HsGrsW0=; b=kU/Xo7HCj2Lq5zlnWe72B 7UHwCl9hVxr+f4c7/CXeU5ADfUPCuLrFGqk6vQQPbrzPaG1XYmip6jsUsVrZH5Ir tpI1JQiv9Kak8qIoYoMQ8O3movsb/5d6yzE4zb/LhmJlWiz8X3WJBY42y4vQ/xwI 47qC2LNleh3IZSH5TMmnSk= Received: from ubuntu.localdomain (unknown [115.200.200.157]) by smtp9 (Coremail) with SMTP id DcCowAC3evili6Bg85SBAw--.61303S5; Sun, 16 May 2021 11:04:08 +0800 (CST) From: Li Qiang To: marcandre.lureau@redhat.com, kraxel@redhat.com, philmd@redhat.com, ppandit@redhat.com, mcascell@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 1/8] vhost-user-gpu: fix memory disclosure in virgl_cmd_get_capset_info (CVE-2021-3545) Date: Sat, 15 May 2021 20:03:56 -0700 Message-Id: <20210516030403.107723-2-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516030403.107723-1-liq3ea@163.com> References: <20210516030403.107723-1-liq3ea@163.com> MIME-Version: 1.0 X-CM-TRANSID: DcCowAC3evili6Bg85SBAw--.61303S5 X-Coremail-Antispam: 1Uf129KBjvdXoW7Gry5Kr47JrWUur4DurWxWFg_yoW3urg_ZF yFyrn7AF4DWFW0kr45Z3W5JrWay3yrAFsayFnakrn7ZFyF93W5Xwn3t3s7C34fuw43GF4D AFy0yw4rG3Z09jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8QAw7UUUUU== X-Originating-IP: [115.200.200.157] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbByQiUbV1vkd6VCwAAsb Received-SPF: pass client-ip=220.181.12.13; envelope-from=liq3ea@163.com; helo=m12-13.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Otherwise some of the 'resp' will be leaked to guest. Fixes: CVE-2021-3545 Reported-by: Li Qiang virtio-gpu fix: 42a8dadc74 ("virtio-gpu: fix information leak in getting capset info dispatch") Signed-off-by: Li Qiang --- contrib/vhost-user-gpu/virgl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 9e6660c7ab..6a332d601f 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -128,6 +128,7 @@ virgl_cmd_get_capset_info(VuGpu *g, VUGPU_FILL_CMD(info); + memset(&resp, 0, sizeof(resp)); if (info.capset_index == 0) { resp.capset_id = VIRTIO_GPU_CAPSET_VIRGL; virgl_renderer_get_cap_set(resp.capset_id, From patchwork Sun May 16 03:03:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 12260143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6359C433ED for ; Sun, 16 May 2021 03:09:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 99C8061041 for ; Sun, 16 May 2021 03:09:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99C8061041 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1li79z-00047c-GQ for qemu-devel@archiver.kernel.org; Sat, 15 May 2021 23:09:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1li74q-0000pv-Nl for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:24 -0400 Received: from m12-13.163.com ([220.181.12.13]:52221) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1li74l-0002e7-E0 for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=+cX1B 0xZjC1BtX+cq5VAtM2rkQYVJVOu0vA64CpTbqI=; b=aj5/m/mfAt1Y3OTr52evb +WPWN84TkvjY1JxiTbNsNMlFd3Pcm8/28affbOie+Adf4rY7djTh9PT2Iem18ERg 4tP0sObP8+zrhIUnoddkHV8jTPGsZ/7dOwijb/i45kGF+P63ncti3H043EUB+f41 niSMvo8o6+72P6/v3p50q0= Received: from ubuntu.localdomain (unknown [115.200.200.157]) by smtp9 (Coremail) with SMTP id DcCowAC3evili6Bg85SBAw--.61303S6; Sun, 16 May 2021 11:04:10 +0800 (CST) From: Li Qiang To: marcandre.lureau@redhat.com, kraxel@redhat.com, philmd@redhat.com, ppandit@redhat.com, mcascell@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 2/8] vhost-user-gpu: fix resource leak in 'vg_resource_create_2d' (CVE-2021-3544) Date: Sat, 15 May 2021 20:03:57 -0700 Message-Id: <20210516030403.107723-3-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516030403.107723-1-liq3ea@163.com> References: <20210516030403.107723-1-liq3ea@163.com> MIME-Version: 1.0 X-CM-TRANSID: DcCowAC3evili6Bg85SBAw--.61303S6 X-Coremail-Antispam: 1Uf129KBjvdXoW7GFWDCr1UuryUtw1kur4fuFg_yoWfXFg_Za 18XF4kCFs8WFy09w4DtwsxA3yayFWfJrs7tFy0kF45CFyUtwnIq3s5t3yvyry8Zw4DGF1D ArWUJw48AF12vjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8LXo7UUUUU== X-Originating-IP: [115.200.200.157] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbiKQqUbVXl0i9ZBgAAsI Received-SPF: pass client-ip=220.181.12.13; envelope-from=liq3ea@163.com; helo=m12-13.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, Prasad J Pandit Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Call 'vugbm_buffer_destroy' in error path to avoid resource leak. Fixes: CVE-2021-3544 Reported-by: Li Qiang Reviewed-by: Prasad J Pandit Signed-off-by: Li Qiang --- contrib/vhost-user-gpu/vhost-user-gpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c index f73f292c9f..b5e153d0d6 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -349,6 +349,7 @@ vg_resource_create_2d(VuGpu *g, g_critical("%s: resource creation failed %d %d %d", __func__, c2d.resource_id, c2d.width, c2d.height); g_free(res); + vugbm_buffer_destroy(&res->buffer); cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY; return; } From patchwork Sun May 16 03:03:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 12260141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AD78C433ED for ; Sun, 16 May 2021 03:07:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D9D7461263 for ; Sun, 16 May 2021 03:07:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9D7461263 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1li781-0000YZ-TO for qemu-devel@archiver.kernel.org; Sat, 15 May 2021 23:07:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1li74p-0000pI-Jl for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 Received: from m12-13.163.com ([220.181.12.13]:51970) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1li74k-0002at-L6 for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=C+paA DHADu8m1z5BBlUXuo5S79eASO5woW8DxjrqGN0=; b=PiQKMe2+DnafQYrGLKADR abjg0/J//Vqs6VZZrHtzKvRkdiD5P1qhEyaNRoFQSAokUZ/EEa7DpoayH41TG9PH 7KHOvjPQK6Zc3v5SeCnOpMY7kCSafstlBn9pmYgpOwj4QULuapomkm3yNaopyuy9 qGdNLqDKCLam8avzutDvBs= Received: from ubuntu.localdomain (unknown [115.200.200.157]) by smtp9 (Coremail) with SMTP id DcCowAC3evili6Bg85SBAw--.61303S7; Sun, 16 May 2021 11:04:11 +0800 (CST) From: Li Qiang To: marcandre.lureau@redhat.com, kraxel@redhat.com, philmd@redhat.com, ppandit@redhat.com, mcascell@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 3/8] vhost-user-gpu: fix memory leak in vg_resource_attach_backing (CVE-2021-3544) Date: Sat, 15 May 2021 20:03:58 -0700 Message-Id: <20210516030403.107723-4-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516030403.107723-1-liq3ea@163.com> References: <20210516030403.107723-1-liq3ea@163.com> MIME-Version: 1.0 X-CM-TRANSID: DcCowAC3evili6Bg85SBAw--.61303S7 X-Coremail-Antispam: 1Uf129KBjvdXoWrKFyxCF1xGFWUWr4xJr1DJrb_yoWfAwb_ZF 4rZFs7CrsxWFWq9F4jqw15ZryayFWfJr1fAFyIkr9xGryFqwnIqw1Fkr97Kr18Zw4DGF1D ArWUJr4xGw129jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU0X4SUUUUUU== X-Originating-IP: [115.200.200.157] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbiTwWUbVsGYxK8lgAAs1 Received-SPF: pass client-ip=220.181.12.13; envelope-from=liq3ea@163.com; helo=m12-13.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Check whether the 'res' has already been attach_backing to avoid memory leak. Fixes: CVE-2021-3544 Reported-by: Li Qiang virtio-gpu fix: 204f01b309 ("virtio-gpu: fix memory leak in resource attach backing") Signed-off-by: Li Qiang --- contrib/vhost-user-gpu/vhost-user-gpu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c index b5e153d0d6..0437e52b64 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -489,6 +489,11 @@ vg_resource_attach_backing(VuGpu *g, return; } + if (res->iov) { + cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + ret = vg_create_mapping_iov(g, &ab, cmd, &res->iov); if (ret != 0) { cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC; From patchwork Sun May 16 03:03:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 12260131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10988C433B4 for ; Sun, 16 May 2021 03:05:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 796A361264 for ; Sun, 16 May 2021 03:05:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 796A361264 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1li76L-0003UH-DQ for qemu-devel@archiver.kernel.org; Sat, 15 May 2021 23:05:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1li74p-0000pB-8T for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 Received: from m12-13.163.com ([220.181.12.13]:52412) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1li74n-0002gl-B0 for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=+gT0x OZ1sbHb1v809rvyAUb/xUotLOBP97I035MOv5U=; b=ItI9oMmP1n4V74Oe8YS3R 8taWuqaJ+4lrdQFQYQwG+50YiPkRhD1NUhTO8bbusiEoE7KAi9i1MkAEJHGO9yUc bPmT3dLKjSsv5fn/A5xH/xOU071D8bY957p86stvq/EkAVQJWx9Ck7MfNlPVJcam I3FmWmSraSL8Ck5REHggE4= Received: from ubuntu.localdomain (unknown [115.200.200.157]) by smtp9 (Coremail) with SMTP id DcCowAC3evili6Bg85SBAw--.61303S8; Sun, 16 May 2021 11:04:12 +0800 (CST) From: Li Qiang To: marcandre.lureau@redhat.com, kraxel@redhat.com, philmd@redhat.com, ppandit@redhat.com, mcascell@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 4/8] vhost-user-gpu: fix memory leak while calling 'vg_resource_unref' (CVE-2021-3544) Date: Sat, 15 May 2021 20:03:59 -0700 Message-Id: <20210516030403.107723-5-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516030403.107723-1-liq3ea@163.com> References: <20210516030403.107723-1-liq3ea@163.com> MIME-Version: 1.0 X-CM-TRANSID: DcCowAC3evili6Bg85SBAw--.61303S8 X-Coremail-Antispam: 1Uf129KBjvdXoWrtry3AF1rtw4xZw18Jw1xAFb_yoWDuFb_Za 1rAF4kArsxGFy093yjyw13A3y3ArWfJrn3Cas7KFW5KryrKwnIqw1fX397tryUZw4DuF1D Cry8Jw4rWw1Y9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8Y0P3UUUUU== X-Originating-IP: [115.200.200.157] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbitAqUbVSIlhIIyQACsc Received-SPF: pass client-ip=220.181.12.13; envelope-from=liq3ea@163.com; helo=m12-13.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, Prasad J Pandit Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If the guest trigger following sequences, the attach_backing will be leaked: vg_resource_create_2d vg_resource_attach_backing vg_resource_unref This patch fix this by freeing 'res->iov' in vg_resource_destroy. Fixes: CVE-2021-3544 Reported-by: Li Qiang virtio-gpu fix: 5e8e3c4c75 ("virtio-gpu: fix resource leak in virgl_cmd_resource_unref") Reviewed-by: Prasad J Pandit Signed-off-by: Li Qiang --- contrib/vhost-user-gpu/vhost-user-gpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c index 0437e52b64..770dfad529 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -400,6 +400,7 @@ vg_resource_destroy(VuGpu *g, } vugbm_buffer_destroy(&res->buffer); + g_free(res->iov); pixman_image_unref(res->image); QTAILQ_REMOVE(&g->reslist, res, next); g_free(res); From patchwork Sun May 16 03:04:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 12260135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5632C43460 for ; Sun, 16 May 2021 03:05:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4B54E61264 for ; Sun, 16 May 2021 03:05:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B54E61264 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1li76M-0003Wf-68 for qemu-devel@archiver.kernel.org; Sat, 15 May 2021 23:05:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1li74p-0000pN-Qx for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 Received: from m12-13.163.com ([220.181.12.13]:52132) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1li74k-0002dJ-U8 for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=BzYCD 09ffMe45pwQvIaWImz53+dVi8gD6dIwEE++i/w=; b=jpCYDOB6wxrLE5Q4hv6nQ sGnRnZq0em23rFKL3ZxjWXMUbNdu4UL3XThMGr6PXLw0YZ9O357zTyPAgBKgpC5V w4mt6GzsgUbYz/Y4rHwvFf+JNxHG8yosgEWIJVWoUH8ok9H1ukeAMQbqh9F2pUUQ 1HPs/zh3RMhVNo94aDsOSk= Received: from ubuntu.localdomain (unknown [115.200.200.157]) by smtp9 (Coremail) with SMTP id DcCowAC3evili6Bg85SBAw--.61303S9; Sun, 16 May 2021 11:04:13 +0800 (CST) From: Li Qiang To: marcandre.lureau@redhat.com, kraxel@redhat.com, philmd@redhat.com, ppandit@redhat.com, mcascell@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 5/8] vhost-user-gpu: fix memory leak in 'virgl_cmd_resource_unref' (CVE-2021-3544) Date: Sat, 15 May 2021 20:04:00 -0700 Message-Id: <20210516030403.107723-6-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516030403.107723-1-liq3ea@163.com> References: <20210516030403.107723-1-liq3ea@163.com> MIME-Version: 1.0 X-CM-TRANSID: DcCowAC3evili6Bg85SBAw--.61303S9 X-Coremail-Antispam: 1Uf129KBjvdXoW7Wr1DXF1UGFW3Xw4rWFW3Jrb_yoWkGFg_ZF 4YkF18Ar45GFy093y5Zw1rAayaywna9FyqvFyfKa4Fk34rWr1jqw10q3s7Gry29r4kGF4D JryFyw4rCw4a9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU85CzJUUUUU== X-Originating-IP: [115.200.200.157] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBZgyUbVaD74ALNQABsW Received-SPF: pass client-ip=220.181.12.13; envelope-from=liq3ea@163.com; helo=m12-13.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The 'res->iov' will be leaked if the guest trigger following sequences: virgl_cmd_create_resource_2d virgl_resource_attach_backing virgl_cmd_resource_unref This patch fixes this. Fixes: CVE-2021-3544 Reported-by: Li Qiang virtio-gpu fix: 5e8e3c4c75 ("virtio-gpu: fix resource leak in virgl_cmd_resource_unref" Signed-off-by: Li Qiang --- contrib/vhost-user-gpu/virgl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 6a332d601f..c669d73a1d 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -108,9 +108,16 @@ virgl_cmd_resource_unref(VuGpu *g, struct virtio_gpu_ctrl_command *cmd) { struct virtio_gpu_resource_unref unref; + struct iovec *res_iovs = NULL; + int num_iovs = 0; VUGPU_FILL_CMD(unref); + virgl_renderer_resource_detach_iov(unref.resource_id, + &res_iovs, + &num_iovs); + g_free(res_iovs); + virgl_renderer_resource_unref(unref.resource_id); } From patchwork Sun May 16 03:04:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 12260133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F388C43461 for ; Sun, 16 May 2021 03:05:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D5BB61221 for ; Sun, 16 May 2021 03:05:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D5BB61221 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1li76M-0003XF-4q for qemu-devel@archiver.kernel.org; Sat, 15 May 2021 23:05:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1li74o-0000oo-LQ for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:22 -0400 Received: from m12-13.163.com ([220.181.12.13]:52205) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1li74k-0002db-EF for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=VHEE/ 6PHj6HKMf1kg5MP8/mD9JXRubLwlPgxHpRSgv4=; b=ZlP+46gnHHsRz3rbNNmjr 5qEga2Sn6baQeRgFtbc7ImER9fFz987xPJKlnHXzcddsCqmTezNQnpA+LL2iwUoF jdp7PA9VSKuH/qIHugzouI6Ws/7ZFE+2yGC8lfXBw7e9UUeFmBEwqHvbyqQKfmcu BB7+uBTJ1gUeALWgEQ7CNE= Received: from ubuntu.localdomain (unknown [115.200.200.157]) by smtp9 (Coremail) with SMTP id DcCowAC3evili6Bg85SBAw--.61303S10; Sun, 16 May 2021 11:04:14 +0800 (CST) From: Li Qiang To: marcandre.lureau@redhat.com, kraxel@redhat.com, philmd@redhat.com, ppandit@redhat.com, mcascell@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 6/8] vhost-user-gpu: fix memory leak in 'virgl_resource_attach_backing' (CVE-2021-3544) Date: Sat, 15 May 2021 20:04:01 -0700 Message-Id: <20210516030403.107723-7-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516030403.107723-1-liq3ea@163.com> References: <20210516030403.107723-1-liq3ea@163.com> MIME-Version: 1.0 X-CM-TRANSID: DcCowAC3evili6Bg85SBAw--.61303S10 X-Coremail-Antispam: 1Uf129KBjvdXoWrKFyxCF17Kr4UXFyDCr4xtFb_yoWfCrg_ZF 4Fvrn7Jr4UXFWj9w43Xw18Cayay3yrZF97AFyfKayfCFyFgw15Xw1rt3s7J347Zr4DWFnr Zry0yr4rCa13ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU85l1DUUUUU== X-Originating-IP: [115.200.200.157] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBZg6UbVaD74ALQQAAsh Received-SPF: pass client-ip=220.181.12.13; envelope-from=liq3ea@163.com; helo=m12-13.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If 'virgl_renderer_resource_attach_iov' failed, the 'res_iovs' will be leaked. Fixes: CVE-2021-3544 Reported-by: Li Qiang virtio-gpu fix: 33243031da ("virtio-gpu-3d: fix memory leak in resource attach backing") Signed-off-by: Li Qiang --- contrib/vhost-user-gpu/virgl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index c669d73a1d..a16a311d80 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -287,8 +287,11 @@ virgl_resource_attach_backing(VuGpu *g, return; } - virgl_renderer_resource_attach_iov(att_rb.resource_id, + ret = virgl_renderer_resource_attach_iov(att_rb.resource_id, res_iovs, att_rb.nr_entries); + if (ret != 0) { + g_free(res_iovs); + } } static void From patchwork Sun May 16 03:04:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 12260145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64AC0C433B4 for ; Sun, 16 May 2021 03:09:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27FD361263 for ; Sun, 16 May 2021 03:09:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27FD361263 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1li7A0-0004A7-7h for qemu-devel@archiver.kernel.org; Sat, 15 May 2021 23:09:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1li74s-0000v0-6c for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:26 -0400 Received: from m12-13.163.com ([220.181.12.13]:52565) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1li74q-0002kN-6W for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=HfJ8S VRcOOM7xn8n/ZsrKk1pmtNvBma0xJJbdxFPmHg=; b=jjnX/jMri4ERphxLB29O9 m4SU3AlRLvZF9MTsyYNvLMCV6ui1FupMtdyuQzCNckrPNnNQsXrXen0LkIqqsZOK Nbj70OOgdlJYg4s8KmXVKQGj2A5lAdLtAnwKQfax2sxDtEbX4V4nvZWlqKbOfnfM tisizpGx19mUIp0aWORKp4= Received: from ubuntu.localdomain (unknown [115.200.200.157]) by smtp9 (Coremail) with SMTP id DcCowAC3evili6Bg85SBAw--.61303S11; Sun, 16 May 2021 11:04:15 +0800 (CST) From: Li Qiang To: marcandre.lureau@redhat.com, kraxel@redhat.com, philmd@redhat.com, ppandit@redhat.com, mcascell@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 7/8] vhost-user-gpu: fix OOB write in 'virgl_cmd_get_capset' (CVE-2021-3546) Date: Sat, 15 May 2021 20:04:02 -0700 Message-Id: <20210516030403.107723-8-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516030403.107723-1-liq3ea@163.com> References: <20210516030403.107723-1-liq3ea@163.com> MIME-Version: 1.0 X-CM-TRANSID: DcCowAC3evili6Bg85SBAw--.61303S11 X-Coremail-Antispam: 1Uf129KBjvdXoWrtw4fAr4rWFWrXr1xGry5CFg_yoWDtrc_ZF 1fCr1rZr4DZryj9Fs8Ar1YyrW7ArW8AFn2vFyfKw1fXFy5K3W5X34fG34kCw43Z3ykCF1D Ary8tws5W3ZF9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUbUDG5UUUUU== X-Originating-IP: [115.200.200.157] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBZg+UbVaD74ALRwAAsm Received-SPF: pass client-ip=220.181.12.13; envelope-from=liq3ea@163.com; helo=m12-13.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, Prasad J Pandit Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If 'virgl_cmd_get_capset' set 'max_size' to 0, the 'virgl_renderer_fill_caps' will write the data after the 'resp'. This patch avoid this by checking the returned 'max_size'. virtio-gpu fix: abd7f08b23 ("display: virtio-gpu-3d: check virgl capabilities max_size") Fixes: CVE-2021-3546 Reported-by: Li Qiang Reviewed-by: Prasad J Pandit Signed-off-by: Li Qiang --- contrib/vhost-user-gpu/virgl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index a16a311d80..7172104b19 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -177,6 +177,10 @@ virgl_cmd_get_capset(VuGpu *g, virgl_renderer_get_cap_set(gc.capset_id, &max_ver, &max_size); + if (!max_size) { + cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + return; + } resp = g_malloc0(sizeof(*resp) + max_size); resp->hdr.type = VIRTIO_GPU_RESP_OK_CAPSET; From patchwork Sun May 16 03:04:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 12260139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84E29C433B4 for ; Sun, 16 May 2021 03:07:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3390961041 for ; Sun, 16 May 2021 03:07:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3390961041 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1li77w-0000VW-BT for qemu-devel@archiver.kernel.org; Sat, 15 May 2021 23:07:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1li74p-0000pR-Th for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 Received: from m12-13.163.com ([220.181.12.13]:52352) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1li74n-0002gO-Bn for qemu-devel@nongnu.org; Sat, 15 May 2021 23:04:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=DcDXR blPPvnfD/xYLg4aHe8aReG2NSYKLxSU3hh7qxU=; b=Y5Bgc8mH5zeTUX/Vx9YDV AZMXoLjBFtsWlEDlLjx1Yf9bIu2EURiBVX0qWqd/Ny41gBy0Wmnv4uhlfC/oOzUI h3bECCSy4qIaAtrkXdu6GvDcsZjEAuHmtEfWQEvrbgC5+2OB4ymabr3gYZYkIB4m /ZtfIek8cumCquCKAveJ5g= Received: from ubuntu.localdomain (unknown [115.200.200.157]) by smtp9 (Coremail) with SMTP id DcCowAC3evili6Bg85SBAw--.61303S12; Sun, 16 May 2021 11:04:16 +0800 (CST) From: Li Qiang To: marcandre.lureau@redhat.com, kraxel@redhat.com, philmd@redhat.com, ppandit@redhat.com, mcascell@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 8/8] vhost-user-gpu: abstract vg_cleanup_mapping_iov Date: Sat, 15 May 2021 20:04:03 -0700 Message-Id: <20210516030403.107723-9-liq3ea@163.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516030403.107723-1-liq3ea@163.com> References: <20210516030403.107723-1-liq3ea@163.com> MIME-Version: 1.0 X-CM-TRANSID: DcCowAC3evili6Bg85SBAw--.61303S12 X-Coremail-Antispam: 1Uf129KBjvJXoWxWrW7Gr4DJr47XFWUGw4UJwb_yoWrJFyUpF yxW3W2kF48Zr4fKa97Aw1UZFnav3WrZFWYkr1akan8ursIg3yqq3Z8u3Z8Kr15JFyktF47 tFn8Gw18GrWUAFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UD5rcUUUUU= X-Originating-IP: [115.200.200.157] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbiKRCUbVXl0i9ZPQAAsp Received-SPF: pass client-ip=220.181.12.13; envelope-from=liq3ea@163.com; helo=m12-13.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Currently in vhost-user-gpu, we free resource directly in the cleanup case of resource. If we change the cleanup logic we need to change several places, also abstruct a 'vg_create_mapping_iov' can be symmetry with the 'vg_create_mapping_iov'. This is like what virtio-gpu does, no function changed. Signed-off-by: Li Qiang --- contrib/vhost-user-gpu/vhost-user-gpu.c | 24 ++++++++++++++++++++---- contrib/vhost-user-gpu/virgl.c | 9 +++++---- contrib/vhost-user-gpu/vugpu.h | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c index 770dfad529..6dc6a44f4e 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -49,6 +49,8 @@ static char *opt_render_node; static gboolean opt_virgl; static void vg_handle_ctrl(VuDev *dev, int qidx); +static void vg_cleanup_mapping(VuGpu *g, + struct virtio_gpu_simple_resource *res); static const char * vg_cmd_to_string(int cmd) @@ -400,7 +402,7 @@ vg_resource_destroy(VuGpu *g, } vugbm_buffer_destroy(&res->buffer); - g_free(res->iov); + vg_cleanup_mapping(g, res); pixman_image_unref(res->image); QTAILQ_REMOVE(&g->reslist, res, next); g_free(res); @@ -504,6 +506,22 @@ vg_resource_attach_backing(VuGpu *g, res->iov_cnt = ab.nr_entries; } +/* Though currently only free iov, maybe later will do more work. */ +void vg_cleanup_mapping_iov(VuGpu *g, + struct iovec *iov, uint32_t count) +{ + g_free(iov); +} + +static void +vg_cleanup_mapping(VuGpu *g, + struct virtio_gpu_simple_resource *res) +{ + vg_cleanup_mapping_iov(g, res->iov, res->iov_cnt); + res->iov = NULL; + res->iov_cnt = 0; +} + static void vg_resource_detach_backing(VuGpu *g, struct virtio_gpu_ctrl_command *cmd) @@ -522,9 +540,7 @@ vg_resource_detach_backing(VuGpu *g, return; } - g_free(res->iov); - res->iov = NULL; - res->iov_cnt = 0; + vg_cleanup_mapping(g, res); } static void diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 7172104b19..3e45e1bd33 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -116,8 +116,9 @@ virgl_cmd_resource_unref(VuGpu *g, virgl_renderer_resource_detach_iov(unref.resource_id, &res_iovs, &num_iovs); - g_free(res_iovs); - + if (res_iovs != NULL && num_iovs != 0) { + vg_cleanup_mapping_iov(g, res_iovs, num_iovs); + } virgl_renderer_resource_unref(unref.resource_id); } @@ -294,7 +295,7 @@ virgl_resource_attach_backing(VuGpu *g, ret = virgl_renderer_resource_attach_iov(att_rb.resource_id, res_iovs, att_rb.nr_entries); if (ret != 0) { - g_free(res_iovs); + vg_cleanup_mapping_iov(g, res_iovs, att_rb.nr_entries); } } @@ -314,7 +315,7 @@ virgl_resource_detach_backing(VuGpu *g, if (res_iovs == NULL || num_iovs == 0) { return; } - g_free(res_iovs); + vg_cleanup_mapping_iov(g, res_iovs, num_iovs); } static void diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h index 04d5615812..e2864bba68 100644 --- a/contrib/vhost-user-gpu/vugpu.h +++ b/contrib/vhost-user-gpu/vugpu.h @@ -169,7 +169,7 @@ int vg_create_mapping_iov(VuGpu *g, struct virtio_gpu_resource_attach_backing *ab, struct virtio_gpu_ctrl_command *cmd, struct iovec **iov); - +void vg_cleanup_mapping_iov(VuGpu *g, struct iovec *iov, uint32_t count); void vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd); void vg_wait_ok(VuGpu *g);